Skip to content
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] Handle DoRA better #9547

Merged
merged 14 commits into from
Oct 8, 2024
Merged

[LoRA] Handle DoRA better #9547

merged 14 commits into from
Oct 8, 2024

Conversation

sayakpaul
Copy link
Member

What does this PR do?

Our support for loading community DoRA checkpoints is currently broken. See KohakuBlueleaf/LyCORIS#216.

So, this PR:

  1. Detects if a state dict has dora_scale present. Upon detection, it logs a warning about the incompatibility and filters the state dict so that it doesn't have the dora_scale keys.
  2. Adjust the tests accordingly.

Once Ben gives a go ahead I will request for a review from Yiyi.

@HuggingFaceDocBuilderDev

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.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree it's better not to load these DoRA weights, as we now pretty much agree with Kohaku that their DoRA implementation is using the other axis.

Just a nit, the unit test could check for the new warning message.

@sayakpaul
Copy link
Member Author

@BenjaminBossan thanks. Does a8fdc76 work for you?

@yiyixuxu could you give this a look too?

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM.

@@ -1125,7 +1136,13 @@ def load_lora_weights(
# First, ensure that the checkpoint is a compatible one and can be successfully loaded.
state_dict = self.lora_state_dict(pretrained_model_name_or_path_or_dict, **kwargs)

is_correct_format = all("lora" in key or "dora_scale" in key for key in state_dict.keys())
is_dora_scale_present = any("dora_scale" in k for k in state_dict)
if is_dora_scale_present:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we sometimes add this code to lora_state_dict() and sometimes on load_lora_weights. Is there any reason we do this differently?

Copy link
Member Author

@sayakpaul sayakpaul Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I see what you mean. Will update accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In e08cf74, I have tried to make this more consistent by moving all the "dora_scale" check related code to lora_state_dict().

LMK if that works for you, @yiyixuxu.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@sayakpaul
Copy link
Member Author

Failing test is unrelated.

@sayakpaul sayakpaul merged commit 02eeb8e into main Oct 8, 2024
17 of 18 checks passed
@sayakpaul sayakpaul deleted the handle-dora branch October 8, 2024 16:17
charchit7 pushed a commit to charchit7/diffusers that referenced this pull request Oct 8, 2024
* handle dora.

* print test

* debug

* fix

* fix-copies

* update logits

* add warning in the test.

* make is_dora check consistent.

* fix-copies
leisuzz pushed a commit to leisuzz/diffusers that referenced this pull request Oct 11, 2024
* handle dora.

* print test

* debug

* fix

* fix-copies

* update logits

* add warning in the test.

* make is_dora check consistent.

* fix-copies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants