-
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
96864fb
0847255
dcce164
d083f86
5284a9c
0a7be77
b7e24d9
bcb0924
cabcf3d
eda4d4b
4fdf400
0ed988c
f3afbf1
724b9a2
daaa598
6e8d333
b09fc48
af03f73
729252e
ea451d1
18382f4
4c425e2
a57aa54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5064,7 +5064,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 | ||
|
@@ -5269,15 +5269,33 @@ 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 geattr(self, "transformer_2", None) is None: | ||
linoytsaban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValueError( | ||
"Cannot load LoRA into transformer_2: transformer_2 is not available for this model" | ||
"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, | ||
) | ||
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. Why put it under 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. my thought process was that, as opposed to LoRAs with weights for the transformer and text encoder for example, that we load in one 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. Yeah. So, in case users want to load both transformers, won't it just load one if 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. yep it would, they would need to load separately to each 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. Can you show some pseudo-code expected from the users? This is another way of loading another adapter into 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. here: #12074 (comment) 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. I don't feel strongly about it staying that exact way, but i do think it should remain possible to load different lora weights into the transformers and in different scales 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. Makes sense. Let's go with this but with a note in the docstrings saying it's experimental in nature. |
||
|
||
@classmethod | ||
# Copied from diffusers.loaders.lora_pipeline.SD3LoraLoaderMixin.load_lora_into_transformer with SD3Transformer2DModel->WanTransformer3DModel | ||
|
Uh oh!
There was an error while loading. Please reload this page.