-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LoRA] log a warning when there are missing keys in the LoRA loading. #9622
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
About
Does that work as expected? I thought that we'll always get missing keys that stem from the base model, which is why in PEFT we filter out only the keys with the prefix (in this case it would be Regarding the testing, we would probably have to take a valid LoRA adapter (or create one), edit the state dict to delete an entry, and then try to load that adapter. There is a test along these lines in PEFT here: |
If we try to do: from diffusers import DiffusionPipeline
import torch
dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"
base_model = "black-forest-labs/FLUX.1-dev"
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype).to(device)
pipe.load_lora_weights("XLabs-AI/flux-RealismLora")
image = pipe("a mecha robot", generator=torch.manual_seed(1)).images[0]
image.save("xlabs.png") It correctly gives: WarningLoading adapter weights from state_dict led to missing keys in the model: ['single_transformer_blocks.0.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.0.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.0.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.0.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.0.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.0.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.1.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.1.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.1.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.1.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.1.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.1.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.2.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.2.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.2.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.2.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.2.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.2.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.3.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.3.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.3.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.3.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.3.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.3.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.4.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.4.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.4.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.4.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.4.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.4.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.5.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.5.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.5.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.5.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.5.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.5.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.6.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.6.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.6.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.6.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.6.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.6.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.7.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.7.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.7.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.7.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.7.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.7.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.8.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.8.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.8.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.8.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.8.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.8.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.9.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.9.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.9.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.9.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.9.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.9.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.10.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.10.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.10.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.10.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.10.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.10.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.11.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.11.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.11.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.11.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.11.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.11.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.12.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.12.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.12.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.12.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.12.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.12.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.13.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.13.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.13.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.13.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.13.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.13.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.14.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.14.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.14.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.14.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.14.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.14.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.15.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.15.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.15.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.15.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.15.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.15.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.16.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.16.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.16.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.16.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.16.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.16.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.17.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.17.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.17.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.17.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.17.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.17.attn.to_v.lora_B.default_0.weight', 'single_transformer_blocks.18.attn.to_q.lora_A.default_0.weight', 'single_transformer_blocks.18.attn.to_q.lora_B.default_0.weight', 'single_transformer_blocks.18.attn.to_k.lora_A.default_0.weight', 'single_transformer_blocks.18.attn.to_k.lora_B.default_0.weight', 'single_transformer_blocks.18.attn.to_v.lora_A.default_0.weight', 'single_transformer_blocks.18.attn.to_v.lora_B.default_0.weight']. |
Indeed the warning looks correct although I'm not sure why it works. When I jump into the debugger (here), I see 1274 missing keys though, when it really should be 114 missing keys. When I copy your fix, my warning contains 1274 keys. |
Your hunch was correct all along. 58da14b has addressed this. Does this work for you? |
Yes, that change should do it. In PEFT, we check for |
@BenjaminBossan ready for your review |
@BenjaminBossan some interesting findings here. When I ran the following with this PR from diffusers import DiffusionPipeline
import torch
dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"
base_model = "black-forest-labs/FLUX.1-dev"
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype).to(device)
pipe.load_lora_weights("XLabs-AI/flux-RealismLora")
image = pipe("a mecha robot", generator=torch.manual_seed(1)).images[0]
image.save("xlabs.png") I get: Loading adapter weights from state_dict led to missing keys in the model:
single_transformer_blocks.0.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.0.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.0.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.0.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.0.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.0.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.1.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.1.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.1.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.1.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.1.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.1.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.2.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.2.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.2.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.2.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.2.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.2.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.3.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.3.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.3.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.3.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.3.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.3.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.4.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.4.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.4.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.4.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.4.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.4.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.5.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.5.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.5.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.5.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.5.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.5.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.6.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.6.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.6.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.6.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.6.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.6.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.7.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.7.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.7.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.7.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.7.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.7.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.8.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.8.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.8.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.8.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.8.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.8.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.9.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.9.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.9.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.9.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.9.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.9.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.10.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.10.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.10.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.10.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.10.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.10.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.11.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.11.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.11.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.11.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.11.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.11.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.12.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.12.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.12.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.12.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.12.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.12.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.13.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.13.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.13.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.13.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.13.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.13.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.14.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.14.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.14.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.14.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.14.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.14.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.15.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.15.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.15.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.15.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.15.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.15.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.16.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.16.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.16.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.16.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.16.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.16.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.17.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.17.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.17.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.17.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.17.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.17.attn.to_v.lora_B.default_0.weight, single_transformer_blocks.18.attn.to_q.lora_A.default_0.weight, single_transformer_blocks.18.attn.to_q.lora_B.default_0.weight, single_transformer_blocks.18.attn.to_k.lora_A.default_0.weight, single_transformer_blocks.18.attn.to_k.lora_B.default_0.weight, single_transformer_blocks.18.attn.to_v.lora_A.default_0.weight, single_transformer_blocks.18.attn.to_v.lora_B.default_0.weight But, diffusers/src/diffusers/utils/peft_utils.py Line 181 in 1ba04a4
doesn't actually contain ANY @apolinario internally reported https://huggingface.co/dataautogpt3/FLUX-SyntheticAnime to be causing something similar to this. But when I did: from diffusers import DiffusionPipeline
import torch
dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"
base_model = "black-forest-labs/FLUX.1-dev"
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype).to(device)
pipe.load_lora_weights("dataautogpt3/FLUX-SyntheticAnime")
image = pipe("1980s anime screengrab, VHS quality, a woman with her face glitching and disorted, a halo above her head", generator=torch.manual_seed(1)).images[0]
image.save("syn_anime.png") I didn't get any warnings on unexpected keys or missing keys either. |
Well, the keys are missing, right? Therefore, you can't find them in the
So there is a part of the model called "single_transformer_blocks" that has LoRA layers. But should it have LoRA layers? I checked the
This looks very suspicious to me. Keys like "10.attn.to_q" do match "single_transformer_blocks" and explain why it has LoRA layers but is the key right in the first place? I checked if it could be due to huggingface/peft#2045 and indeed, if I remove this optimization, the error goes away because "single_transformer_blocks" is no longer targeted. So what this means is that the optimization leads to the wrong Targeting these missing LoRA layers before we had I'll investigate why we get those incorrect target modules but more and more I get the impression that this PEFT optimization was a bad idea. Edit: Bugfix here: huggingface/peft#2144. Still wondering if this whole feature should be rolled back though. |
Solves the following bug: huggingface/diffusers#9622 (comment) The cause for the bug is as follows: When we have, say, a module called "bar.0.query" that we want to target and another module called "foo_bar.0.query" that we don't want to target, there was potential for an error. This is not caused by _find_minimal_target_modules directly, but rather the bug was inside of BaseTuner.inject_adapter and how the names_no_target were chosen. Those used to be chosen based on suffix. In our example, however, "bar.0.query" is a suffix of "foo_bar.0.query", therefore "foo_bar.0.query" was *not* added to names_no_target when it should have. As a consequence, during the optimization, it looks like "query" is safe to use as target_modules because we don't see that it wrongly matches "foo_bar.0.query".
When loading a LoRA adapter, so far, there was only a warning when there were unexpected keys in the checkpoint. Now, there is also a warning when there are missing keys. This change is consistent with huggingface/peft#2118 in PEFT and the planned PR huggingface/diffusers#9622 in diffusers. Apart from this change, the error message for unexpected keys was slightly altered for consistency (it should be more readable now). Also, besides adding a test for the missing keys warning, a test for unexpected keys warning was also added, as it was missing so far.
You mean the
I guess you meant
|
Solves the following bug: huggingface/diffusers#9622 (comment) The cause for the bug is as follows: When we have, say, a module called "bar.0.query" that we want to target and another module called "foo_bar.0.query" that we don't want to target, there was potential for an error. This is not caused by _find_minimal_target_modules directly, but rather the bug was inside of BaseTuner.inject_adapter and how the names_no_target were chosen. Those used to be chosen based on suffix. In our example, however, "bar.0.query" is a suffix of "foo_bar.0.query", therefore "foo_bar.0.query" was *not* added to names_no_target when it should have. As a consequence, during the optimization, it looks like "query" is safe to use as target_modules because we don't see that it wrongly matches "foo_bar.0.query".
The
What I meant: When we have |
Okay thanks for explaining, @BenjaminBossan! I guess this PR should be in a good state to review now.
|
@apolinario can you run some tests, ensuring you're on |
Depending on the urgency, I can look into making a patch release.
At least, it should be easier to catch possible errors with the new warning. I wonder if we can check a bunch of external LoRAs to see if there are more warnings? |
Will trigger the integration tests from https://github.com/huggingface/diffusers/blob/main/tests/lora/ tomorrow and see. |
With this combination of versions I can confirm that:
I think huggingface/peft#2144 fixed the broken LoRAs issues I was experiencing, which imo could merit a patch @BenjaminBossan as it will fix a few LoRAs for quite a few people where it's currently failing silently; great work folks! |
Solves the following bug: huggingface/diffusers#9622 (comment) The cause for the bug is as follows: When we have, say, a module called "bar.0.query" that we want to target and another module called "foo_bar.0.query" that we don't want to target, there was potential for an error. This is not caused by _find_minimal_target_modules directly, but rather the bug was inside of BaseTuner.inject_adapter and how the names_no_target were chosen. Those used to be chosen based on suffix. In our example, however, "bar.0.query" is a suffix of "foo_bar.0.query", therefore "foo_bar.0.query" was *not* added to names_no_target when it should have. As a consequence, during the optimization, it looks like "query" is safe to use as target_modules because we don't see that it wrongly matches "foo_bar.0.query".
Done: https://github.com/huggingface/peft/releases/tag/v0.13.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM.
* Added diff diff support for kolors img2img * Fized relative imports * Fized relative imports * Added diff diff support for Kolors * Fized import issues * Added map * Fized import issues * Fixed naming issues * Added diffdiff support for Kolors img2img pipeline * Removed example docstrings * Added map input * Updated latents Co-authored-by: Álvaro Somoza <[email protected]> * Updated `original_with_noise` Co-authored-by: Álvaro Somoza <[email protected]> * Improved code quality --------- Co-authored-by: Álvaro Somoza <[email protected]>
@yiyixuxu could you give this a look too? I have run the integration tests for SD and SDXL LoRAs and they are already passing. Will run the Flux LoRA integration tests separately on a 24GB card. |
@@ -208,9 +209,11 @@ def test_flux_the_last_ben(self): | |||
generator=torch.manual_seed(self.seed), | |||
).images | |||
out_slice = out[0, -3:, -3:, -1].flatten() | |||
expected_slice = np.array([0.1719, 0.1719, 0.1699, 0.1719, 0.1719, 0.1738, 0.1641, 0.1621, 0.2090]) | |||
expected_slice = np.array([0.1855, 0.1855, 0.1836, 0.1855, 0.1836, 0.1875, 0.1777, 0.1758, 0.2246]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the recent fixes in peft
. The tests would pass with peft==0.12.0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Solves the following bug: huggingface/diffusers#9622 (comment) The cause for the bug is as follows: When we have, say, a module called "bar.0.query" that we want to target and another module called "foo_bar.0.query" that we don't want to target, there was potential for an error. This is not caused by _find_minimal_target_modules directly, but rather the bug was inside of BaseTuner.inject_adapter and how the names_no_target were chosen. Those used to be chosen based on suffix. In our example, however, "bar.0.query" is a suffix of "foo_bar.0.query", therefore "foo_bar.0.query" was *not* added to names_no_target when it should have. As a consequence, during the optimization, it looks like "query" is safe to use as target_modules because we don't see that it wrongly matches "foo_bar.0.query".
When loading a LoRA adapter, so far, there was only a warning when there were unexpected keys in the checkpoint. Now, there is also a warning when there are missing keys. This change is consistent with huggingface/peft#2118 in PEFT and the planned PR huggingface/diffusers#9622 in diffusers. Apart from this change, the error message for unexpected keys was slightly altered for consistency (it should be more readable now). Also, besides adding a test for the missing keys warning, a test for unexpected keys warning was also added, as it was missing so far.
What does this PR do?
This came up during an investigation of the Xlabs LoRAs (internal link). It turns out that a couple of keys are missing after the
set_peft_model_state_dict()
call. This affects the results.This PR adds a warning for missing keys and unexpected keys similar to https://github.com/huggingface/peft/pull/2084/files#diff-95787fcc5356568929e383449ade2c1bac5da43deccab17318652b62ed171ae7R1181-R1199. Thanks to @BenjaminBossan for the idea. I have added the necessary tests for this, too.
Turns out that this PR and the PEFT PRs referenced by @BenjaminBossan below solve a couple of issues: #9622 (comment).
Once I have an approval from Ben, will request for Yiyi's reviews.