-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fix Wan AccVideo/CausVid fuse_lora #11856
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f5cf33
fix
a-r-r-o-w 0e0467c
actually, better fix
a-r-r-o-w b175359
Merge branch 'main' into lora/fix-wan
a-r-r-o-w 0aa92e8
empty commit; trigger tests again
a-r-r-o-w 763fd3b
mark wanvace test as flaky
a-r-r-o-w 0371cee
Merge branch 'main' into lora/fix-wan
a-r-r-o-w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1825,24 +1825,22 @@ def _convert_non_diffusers_wan_lora_to_diffusers(state_dict): | |
is_i2v_lora = any("k_img" in k for k in original_state_dict) and any("v_img" in k for k in original_state_dict) | ||
lora_down_key = "lora_A" if any("lora_A" in k for k in original_state_dict) else "lora_down" | ||
lora_up_key = "lora_B" if any("lora_B" in k for k in original_state_dict) else "lora_up" | ||
has_time_projection_weight = any( | ||
k.startswith("time_projection") and k.endswith(".weight") for k in original_state_dict | ||
) | ||
|
||
diff_keys = [k for k in original_state_dict if k.endswith((".diff_b", ".diff"))] | ||
if diff_keys: | ||
for diff_k in diff_keys: | ||
param = original_state_dict[diff_k] | ||
# The magnitudes of the .diff-ending weights are very low (most are below 1e-4, some are upto 1e-3, | ||
# and 2 of them are about 1.6e-2 [the case with AccVideo lora]). The low magnitudes mostly correspond | ||
# to norm layers. Ignoring them is the best option at the moment until a better solution is found. It | ||
# is okay to ignore because they do not affect the model output in a significant manner. | ||
threshold = 1.6e-2 | ||
absdiff = param.abs().max() - param.abs().min() | ||
all_zero = torch.all(param == 0).item() | ||
all_absdiff_lower_than_threshold = absdiff < threshold | ||
if all_zero or all_absdiff_lower_than_threshold: | ||
logger.debug( | ||
f"Removed {diff_k} key from the state dict as it's all zeros, or values lower than hardcoded threshold." | ||
) | ||
original_state_dict.pop(diff_k) | ||
for key in list(original_state_dict.keys()): | ||
if key.endswith((".diff", ".diff_b")) and "norm" in key: | ||
# NOTE: we don't support this because norm layer diff keys are just zeroed values. We can support it | ||
# in future if needed and they are not zeroed. | ||
original_state_dict.pop(key) | ||
logger.debug(f"Removing {key} key from the state dict as it is a norm diff key. This is unsupported.") | ||
|
||
if "time_projection" in key and not has_time_projection_weight: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧠 |
||
# AccVideo lora has diff bias keys but not the weight keys. This causes a weird problem where | ||
# our lora config adds the time proj lora layers, but we don't have the weights for them. | ||
# CausVid lora has the weight keys and the bias keys. | ||
original_state_dict.pop(key) | ||
|
||
# For the `diff_b` keys, we treat them as lora_bias. | ||
# https://huggingface.co/docs/peft/main/en/package_reference/lora#peft.LoraConfig.lora_bias | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not a blocker but might just quickly zero if it's all zeros:
diffusers/src/diffusers/loaders/lora_conversion_utils.py
Line 835 in 8c938fb
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.
From the original codebases where this comes from, I don't think these keys can be anything but zero and yesterday's investigation revealed the same. Probably best to not do anything else here IMO