I often dump everything I download in the lora folder. Turns out the LyCORIS models are supposed to go in a different folder.
I wrote this python script to find all the LyCORIS that were placed in the wrong folder.
e.g.
> python.exe find_lyco.py D:\\stable-diffusion-webui\\models\\lora
----------------------------------
| Looking for .safetensors files |
----------------------------------
D:\stable-diffusion-webui\models\lora\a.safetensors
D:\stable-diffusion-webui\models\lora\subdir\b.safetensors
D:\stable-diffusion-webui\models\lora\c.safetensors
----------------------------------
| Found the following LORA files |
----------------------------------
D:\stable-diffusion-webui\models\lora\a.safetensors
D:\stable-diffusion-webui\models\lora\subdir\b.safetensors
-------------------------------------
| Found the following LyCORIS files |
-------------------------------------
D:\stable-diffusion-webui\models\lora\c.safetensorsDescription
Fixed bug where some lora were misidentified as lycoris
FAQ
Comments (48)
You are amazing. What ever change happened a month or two ago made Lyco a freaking massive pain in the butt compared to how they used to be. Prior to that, you could easily run both from the same folder. Now I have to use sym links and they are all over the place, ahhhh
I intentionally put mine in the same folder since they seem to work fine... did something change in a1111 to prevent that?
That's what I'm wondering lol. I'm using it right now just fine, latest updates for everything relevant.
some work fine but some others seem to not give the desired results unless they go into the lyco folder. It's weird.
If you have the locon extension you put the lycoris in the lora folder. Else you need different folders.
I just have everything in the lyco folder. everything seems to work fine.
When you click on them in the extended hypernetworks showcase and they are in the lora folder they get added to the prompt as <lora:xxx:1> which will not work. If they are in the correct folder they get added with <lyco:xxx:1> and work normally. If you edit the prompt manually and remember which is which, it works regardless I think.
@OneViolentGentleman Maybe it's because of my extensions, but they work fine when run with the '<lora:' prefix for me
@calvin are you sure, the lyco has any effect though? Because you still get an image and only when checking the console it spews out something like: "... AssertionError: Bad Lora layer name: lora_te_text_model_encoder_layers_0_mlp_fc1.hada_w1_a - must end in lora_up.weight, lora_down.weight or alpha"
edit: this is what happens, when I put it in the wrong folder: https://civitai.com/posts/378445 🤣
@OneViolentGentleman Using extensions here too and don't have this problem
@OneViolentGentleman This is exactly what happens to me as well. If they are not in the Lyco folder even while using the Lyco extension, they will give the bad layer error. Mine started doing this a month or two ago, but up to that point it worked fine in the lora folder.
I've got everything up to date, so it's weird some people don't have the issue
@PettankoPaizuri as if the app is playing favorites or something, lol.
@OneViolentGentleman I am definitely sure the lyco has an effect.
Not the hero we deserve, but the one we needed right now. Only one little problem. It finds them, but it doesn't automatically relocate them. dude, I've got hundreds. A list alone isn't really much help, the task remains tedious.
I didn't want to move them since there are preview images and directory structures I don't want to mess up.
It's a small enough edit to the script if you want it to move the files. Make sure you keep the correct indentation when editing the file.
for path in lyco_files:
lyco_dir = "D:\\stable-diffusion-webui\\models\\LyCORIS"
os.rename(path, os.path.join(lyco_dir, os.path.basename(path)))
print(path)
Okay, a few things wrong with this and it kinda fucked me because I have the brain capacity of a rock.
If you use this with civitai helper, it won't carry over the previews and setting files with it, meaning you'll have to go over the list by yourself to carry the other two files over, that could have been easily fixed with some 'if' checks on the uploaders part to see if there were files with .json and .preview.png with the same filename but I digress.
You will also need to move the files manually so for you with 2k+ files, and hundreds of lyco in various folders, good luck.
I will leave you with a python script that will let you move them, just save the list you got in a lyco.txt file in your lora folder and add the destination path you wish:
1) run cmd in the folder where you have saved your 'lyco.txt' where you pasted the list of files:
2) change the 'B:/AI/resource/LORA/lyco' to whatever destination you want to move the files to, make sure the destination folder already exists.
3) Paste this in the cmd window you just opened and make sure the destination is set properly:
python -c "import shutil; [shutil.move(_.strip(), 'B:/AI/resources/LORA/lyco') for _ in open('lyco.txt').readlines()];"
again, don't forget, if you use civit helper, you will only carry over the model files, not their settings or previews.
I'll go cry now for all the lycos that civit doesn't have any more and I have to manually scour for their settings and previews once more.
Thanks m99
The script doesn't move any files. It just prints out file paths. I decided against moving peoples files in case there were folder structures they wanted preserved, preview images, info files, or files at the target with the same name.
I didn't want to be responsible for messing up peoples files so this script only prints out stuff without changing anything. A response I left on another comment details how you could change the script to move your files as well.
@m99 I get it but still, could of saved us a lot of trouble, especially for people that have 2000 loras in a categorized manner. Also, you never answered another user's question that seems pretty important. The script sends some files that are 'supposedly' LoRAs to the Lyco folder, what's up with that? Are they actually LoCon and the uploader made an error naming them LoRA?
Noob question, how to use this script?
Assuming you're on windows
Extract the zip in a directory
In the directory where the extracted file is, shift right click in an empty space and click "Open powershell here"
type "python.exe find_lyco.py " (without the quotes)
drag and drop your lora directory into the prompt
push enter
It will print out the file names of all the LyCORIS. It won't move any files. If it finds LyCORIS files yoy'll want to move them to the LyCORIS folder (along with their previews if you have preview images)
@m99 It doesn't seem to work for me, I'm on Windows 11 and I installed SD in my F drive
After following the instruction nothing happened after I pressed enter
the line I've typed looks like this "python.exe find_lyco.py F:\\StableDiffusion\\webui\\models\\Lora"
What did I do wrong?
@RadStorm04 It should always output an error if something goes wrong. The command should not be wrapped in quotes or it will just echo what you typed without running anything. Running "python.exe --version" should print out the version number of python. If that doesn't work, you'll need to lookup how to install python.
@RadStorm04 Look at your address, there shouldn't be double slashes, should look like this F:/StableDiffusion/webui/models/...etc
Ok, turns out Windows redirected the command to Windows Store by default for some reason, the script works fine after disabling it in App Execution Aliases
Thank you very much bro, this week I ask for this in r/stablediffusion, nobody could help me, thanks!
Doesn't work for me, unfortunately. I have my files on the G: drive with symbolic links in the installation on the C: drive. Tried the path to C and to G, but in both cases I only get shown the usage.
It shows usage if there isn't exactly one arg. The most likely cause is spaces in your file path . You can try wrapping the path in quotes or drag and drop the directory into the command line as that will automaticaly escape the path.
Ugh, spaces ofc "facepalm". Gonna try that right now.
edit: that worked ofc! sorry for being a noob. Wanna put it in the description here or in the python warning itself, or something? Just to not get the same from other noobs like me. Just an idea. ^^
I also wrote a snippet for this (bash, requiring jq), run from stable diffusion folder:
Another issue: Some of the files it claimed to be lycos were actually loras. Some of the falsely identified files are for example:
https://civitai.com/models/82836
https://civitai.com/models/91120
https://civitai.com/models/33725
https://civitai.com/models/80848
https://civitai.com/models/41422
https://civitai.com/models/99865
https://civitai.com/models/27294
https://civitai.com/models/87494
https://civitai.com/models/20640?modelVersionId=51465
https://civitai.com/models/20640?modelVersionId=64350
all versions of:
https://civitai.com/models/79653
I need a second check in the safetensors files to verify manually, because som of them are Lora.
Maybe you must exclude some "Lora" terms in the search. I don't know how to program in Python so, I hope it can be fixed because this program is very usefull, and I thank you for that work.
The script doesn't move files, it just prints out which files are lora and which are lycoris. It's up to you to move the files. This script sorts files based on info in the file header. Another user has left a comment to a script that gets the model type from civitai using the model hash.
@m99 This is not the problem that's I pointed.
The problem is that some files pointed as LyCORIS by you program are not all LyCORIS, some of them are LORAs.
@Xtroat Try deleteing the following lines of code and try again. It will run slower but it will only analyse the model structure and ignore the ss_network_module metadata tag that it uses to speed things up.
metadata = header.get("__metadata__")
if metadata != None:
ss_network_module = metadata.get("ss_network_module")
if ss_network_module != None:
return ss_network_module != "networks.lora"
@m99 tried it. still identifies the same loras as lycos. edit: just had it run over the lycoris folder, and it also misidentifies lycoris files as lora, for example all the files I have of this guy got labeled as loras: https://civitai.com/user/Kappa_Neuro/models
@OneViolentGentleman I just looked at https://civitai.com/models/105984/makoto-shinkai-style-lycoris and it appears to be a lora as far as I can tell. It contains the key "networks.lora" and doesn't have any unet blocks that a lora doesn't. Also looked at https://civitai.com/models/33725/chun-li-street-fighter-lora and it contained "sd_scripts.networks.lora" which it misidentified. I'm updating the script now.
While not 100% (due to the lora extraction of Koyha D method making weird Lora/Lyco hybrids) this is super helpful none the less. thanks!
Ohhh, so this is causing the whole shenanigans?
@OneViolentGentleman Yeah, I found some cases of those extractions not being able to be mixed with other lora as the code says they are lycoris... when they aren't. And then trying to merge as lycoris, it says they are lora. lol
Not sure what causes it, as only some of the extractions in this method have this error, but it's a pain.
What's different in v2?
"Fixed bug where some lora were misidentified as lycoris"
Looks like there is a bug on line 22 of v2. It should be:
except json.JSONDecodeError as e:oops
yea.... I wasn't paying attention, and just assumed they had like a .loco extension or something... turns out I REALLY didn't pay attention, and didn't misplace 3 of them... but 30 xD
I ran this to check a few files where LoRAs and LyCos were in the same post. It seems to have found a ton of LoRAs in my LyCO folder, mostly from Tauron, which were definitely listed as LyCO on Civitai, such as these:
S:\Diffusion Models\Lycoris\Tau's Claire Redfield Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Jill Valentine Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Kaine Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Lady Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Lara Croft Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Lilith Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Lucy Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Quiet (MGS5) Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Reika Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Sarah Kerrigan Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Tifa Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Trish (DMC5) Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Triss Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Yennefer Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Yuna (FFX) Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Zero (Drakengard 3) Cosplay.safetensors S:\Diffusion Models\Lycoris\Tau's Zero Two (Bodysuit Only) Cosplay.safetensors Filenames were renamed to match the civitai page titles so I can find them easily againIs this a bug in the script, or were these posted wrong on Civitai?
Looks like they are lycoris but are mis-labeled as lora in the safetensor metadata.
