-
Notifications
You must be signed in to change notification settings - Fork 6.2k
[Wan 2.2 LoRA] add support for 2nd transformer lora loading + wan 2.2 lightx2v lora #12074
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
Open
linoytsaban
wants to merge
23
commits into
huggingface:main
Choose a base branch
from
linoytsaban:wan22-lightx2v
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−53
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
96864fb
add alpha
linoytsaban 0847255
load into 2nd transformer
linoytsaban dcce164
Merge branch 'main' into wan22-lightx2v
linoytsaban d083f86
Merge branch 'main' into wan22-lightx2v
linoytsaban 5284a9c
Update src/diffusers/loaders/lora_conversion_utils.py
linoytsaban 0a7be77
Update src/diffusers/loaders/lora_conversion_utils.py
linoytsaban b7e24d9
pr comments
linoytsaban bcb0924
pr comments
linoytsaban cabcf3d
pr comments
linoytsaban eda4d4b
Merge branch 'main' into wan22-lightx2v
linoytsaban 4fdf400
fix
linoytsaban 0ed988c
Merge remote-tracking branch 'origin/wan22-lightx2v' into wan22-lightx2v
linoytsaban f3afbf1
Merge branch 'main' into wan22-lightx2v
linoytsaban 724b9a2
fix
linoytsaban daaa598
Merge remote-tracking branch 'origin/wan22-lightx2v' into wan22-lightx2v
linoytsaban 6e8d333
Merge branch 'main' into wan22-lightx2v
linoytsaban b09fc48
Apply style fixes
github-actions[bot] af03f73
Merge branch 'main' into wan22-lightx2v
linoytsaban 729252e
Merge branch 'main' into wan22-lightx2v
linoytsaban ea451d1
fix copies
18382f4
fix
linoytsaban 4c425e2
fix copies
a57aa54
Merge branch 'main' into wan22-lightx2v
linoytsaban 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
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 |
---|---|---|
|
@@ -5270,15 +5270,37 @@ def load_lora_weights( | |
if not is_correct_format: | ||
raise ValueError("Invalid LoRA checkpoint.") | ||
|
||
self.load_lora_into_transformer( | ||
state_dict, | ||
transformer=getattr(self, self.transformer_name) if not hasattr(self, "transformer") else self.transformer, | ||
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=self, | ||
low_cpu_mem_usage=low_cpu_mem_usage, | ||
hotswap=hotswap, | ||
) | ||
load_into_transformer_2 = kwargs.pop("load_into_transformer_2", False) | ||
if load_into_transformer_2: | ||
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. Should raise in case |
||
if not hasattr(self, "transformer_2"): | ||
raise AttributeError( | ||
f"'{type(self).__name__}' object has no attribute transformer_2" | ||
"Note that Wan2.1 models do not have a transformer_2 component." | ||
"Ensure the model has a transformer_2 component before setting load_into_transformer_2=True." | ||
) | ||
if "transformer_2" not in self._lora_loadable_modules: | ||
self._lora_loadable_modules.append("transformer_2") | ||
self.load_lora_into_transformer( | ||
state_dict, | ||
transformer=self.transformer_2, | ||
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=self, | ||
low_cpu_mem_usage=low_cpu_mem_usage, | ||
hotswap=hotswap, | ||
) | ||
else: | ||
self.load_lora_into_transformer( | ||
state_dict, | ||
transformer=getattr(self, self.transformer_name) | ||
if not hasattr(self, "transformer") | ||
else self.transformer, | ||
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=self, | ||
low_cpu_mem_usage=low_cpu_mem_usage, | ||
hotswap=hotswap, | ||
) | ||
|
||
@classmethod | ||
# Copied from diffusers.loaders.lora_pipeline.SD3LoraLoaderMixin.load_lora_into_transformer with SD3Transformer2DModel->WanTransformer3DModel | ||
|
@@ -5668,15 +5690,37 @@ def load_lora_weights( | |
if not is_correct_format: | ||
raise ValueError("Invalid LoRA checkpoint.") | ||
|
||
self.load_lora_into_transformer( | ||
state_dict, | ||
transformer=getattr(self, self.transformer_name) if not hasattr(self, "transformer") else self.transformer, | ||
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=self, | ||
low_cpu_mem_usage=low_cpu_mem_usage, | ||
hotswap=hotswap, | ||
) | ||
load_into_transformer_2 = kwargs.pop("load_into_transformer_2", False) | ||
if load_into_transformer_2: | ||
if not hasattr(self, "transformer_2"): | ||
raise AttributeError( | ||
f"'{type(self).__name__}' object has no attribute transformer_2" | ||
"Note that Wan2.1 models do not have a transformer_2 component." | ||
"Ensure the model has a transformer_2 component before setting load_into_transformer_2=True." | ||
) | ||
if "transformer_2" not in self._lora_loadable_modules: | ||
self._lora_loadable_modules.append("transformer_2") | ||
self.load_lora_into_transformer( | ||
state_dict, | ||
transformer=self.transformer_2, | ||
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=self, | ||
low_cpu_mem_usage=low_cpu_mem_usage, | ||
hotswap=hotswap, | ||
) | ||
else: | ||
self.load_lora_into_transformer( | ||
state_dict, | ||
transformer=getattr(self, self.transformer_name) | ||
if not hasattr(self, "transformer") | ||
else self.transformer, | ||
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=self, | ||
low_cpu_mem_usage=low_cpu_mem_usage, | ||
hotswap=hotswap, | ||
) | ||
|
||
@classmethod | ||
# Copied from diffusers.loaders.lora_pipeline.SD3LoraLoaderMixin.load_lora_into_transformer with SD3Transformer2DModel->SkyReelsV2Transformer3DModel | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.