-
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
Merged
+150
−55
Merged
Changes from all commits
Commits
Show all changes
34 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 52ede6f
Merge branch 'main' into wan22-lightx2v
sayakpaul 386cf1c
Update src/diffusers/loaders/lora_pipeline.py
linoytsaban 64d9b04
Merge branch 'main' into wan22-lightx2v
linoytsaban 2a5b07d
revert change
linoytsaban 3c57672
Merge remote-tracking branch 'origin/wan22-lightx2v' into wan22-lightx2v
linoytsaban f1f1f33
revert change
linoytsaban d83a592
fix copies
c3cb4a6
Merge branch 'main' into wan22-lightx2v
sayakpaul ce5be55
up
sayakpaul 5e21c4d
Merge branch 'main' into wan22-lightx2v
sayakpaul 0559eac
fix
sayakpaul 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
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 |
---|---|---|
|
@@ -5065,7 +5065,7 @@ class WanLoraLoaderMixin(LoraBaseMixin): | |
Load LoRA layers into [`WanTransformer3DModel`]. Specific to [`WanPipeline`] and `[WanImageToVideoPipeline`]. | ||
""" | ||
|
||
_lora_loadable_modules = ["transformer"] | ||
_lora_loadable_modules = ["transformer", "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. Just to note that this loader is shared amongst Wan 2.1 and 2.2 as the pipelines are also one and the same. For Wan 2.1, we won't have any |
||
transformer_name = TRANSFORMER_NAME | ||
|
||
@classmethod | ||
|
@@ -5270,15 +5270,35 @@ 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: | ||
linoytsaban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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." | ||
) | ||
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 +5688,35 @@ 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." | ||
linoytsaban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
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 | ||
|
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.