Skip to content

Commit 76356ea

Browse files
committed
version-guard.
1 parent 388a539 commit 76356ea

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

src/diffusers/utils/peft_utils.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,25 @@ def get_peft_kwargs(
187187
# for now we know that the "bias" keys are only associated with `lora_B`.
188188
lora_bias = any("lora_B" in k and k.endswith(".bias") for k in peft_state_dict)
189189

190-
# Example: load FusionX LoRA into Wan VACE
191-
exclude_modules = _derive_exclude_modules(model_state_dict, peft_state_dict, adapter_name)
192-
if not exclude_modules:
193-
exclude_modules = None
194-
195190
lora_config_kwargs = {
196191
"r": r,
197192
"lora_alpha": lora_alpha,
198193
"rank_pattern": rank_pattern,
199194
"alpha_pattern": alpha_pattern,
200195
"target_modules": target_modules,
201-
"exclude_modules": exclude_modules,
202196
"use_dora": use_dora,
203197
"lora_bias": lora_bias,
204198
}
199+
200+
# Example: try load FusionX LoRA into Wan VACE
201+
exclude_modules = _derive_exclude_modules(model_state_dict, peft_state_dict, adapter_name)
202+
if exclude_modules:
203+
if not is_peft_version(">=", "0.14.0"):
204+
msg = "It seems like there are certain modules that need to be excluded when initializing `LoraConfig`. Your current `peft` version doesn't support passing an `exclude_modules` to `LoraConfig`. Please update it by running `pip install -U peft`."
205+
logger.warning(msg)
206+
else:
207+
lora_config_kwargs.update({"exclude_modules": exclude_modules})
208+
205209
return lora_config_kwargs
206210

207211

@@ -382,6 +386,11 @@ def _maybe_warn_for_unhandled_keys(incompatible_keys, adapter_name):
382386

383387

384388
def _derive_exclude_modules(model_state_dict, peft_state_dict, adapter_name=None):
389+
"""
390+
Derives the modules to exclude while initializing `LoraConfig` through `exclude_modules`. It works by comparing the
391+
`model_state_dict` and `peft_state_dict` and adds a module from `model_state_dict` to the exclusion set if it
392+
doesn't exist in `peft_state_dict`.
393+
"""
385394
all_modules = set()
386395
string_to_replace = f"{adapter_name}." if adapter_name else ""
387396

0 commit comments

Comments
 (0)