-
Notifications
You must be signed in to change notification settings - Fork 92
fix: prevent silent double-application of LoRA weights #473
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 all commits
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 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,11 @@ def load_lora_weights( | |||||||||||||||||||||||||||||||
| def translate_fn(nnx_path_str): | ||||||||||||||||||||||||||||||||
| return lora_conversion_utils.translate_wan_nnx_path_to_diffusers_lora(nnx_path_str, scan_layers=scan_layers) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| lora_key = (lora_model_path, transformer_weight_name) | ||||||||||||||||||||||||||||||||
| if self._check_and_record_lora(lora_key): | ||||||||||||||||||||||||||||||||
| max_logging.log(f"WARNING: LoRA '{lora_model_path}' already merged — skipping to avoid double-application.") | ||||||||||||||||||||||||||||||||
| return pipeline | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if hasattr(pipeline, "transformer") and transformer_weight_name: | ||||||||||||||||||||||||||||||||
| max_logging.log(f"Merging LoRA into transformer with rank={rank}") | ||||||||||||||||||||||||||||||||
| h_state_dict, _ = lora_loader.lora_state_dict(lora_model_path, weight_name=transformer_weight_name, **kwargs) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+53
to
60
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. Checking and recording the LoRA key before verifying if
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
@@ -91,7 +96,10 @@ def translate_fn(nnx_path_str: str): | |||||||||||||||||||||||||||||||
| return lora_conversion_utils.translate_wan_nnx_path_to_diffusers_lora(nnx_path_str, scan_layers=scan_layers) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Handle high noise model | ||||||||||||||||||||||||||||||||
| if hasattr(pipeline, "high_noise_transformer") and high_noise_weight_name: | ||||||||||||||||||||||||||||||||
| high_key = (lora_model_path, high_noise_weight_name, "high_noise") | ||||||||||||||||||||||||||||||||
| if self._check_and_record_lora(high_key): | ||||||||||||||||||||||||||||||||
| max_logging.log(f"WARNING: LoRA '{lora_model_path}' already merged into high_noise_transformer — skipping.") | ||||||||||||||||||||||||||||||||
| elif hasattr(pipeline, "high_noise_transformer") and high_noise_weight_name: | ||||||||||||||||||||||||||||||||
| max_logging.log(f"Merging LoRA into high_noise_transformer with rank={rank}") | ||||||||||||||||||||||||||||||||
| h_state_dict, _ = lora_loader.lora_state_dict(lora_model_path, weight_name=high_noise_weight_name, **kwargs) | ||||||||||||||||||||||||||||||||
| h_state_dict = lora_conversion_utils.preprocess_wan_lora_dict(h_state_dict) | ||||||||||||||||||||||||||||||||
|
|
@@ -100,7 +108,10 @@ def translate_fn(nnx_path_str: str): | |||||||||||||||||||||||||||||||
| max_logging.log("high_noise_transformer not found or no weight name provided for LoRA.") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Handle low noise model | ||||||||||||||||||||||||||||||||
| if hasattr(pipeline, "low_noise_transformer") and low_noise_weight_name: | ||||||||||||||||||||||||||||||||
| low_key = (lora_model_path, low_noise_weight_name, "low_noise") | ||||||||||||||||||||||||||||||||
| if self._check_and_record_lora(low_key): | ||||||||||||||||||||||||||||||||
| max_logging.log(f"WARNING: LoRA '{lora_model_path}' already merged into low_noise_transformer — skipping.") | ||||||||||||||||||||||||||||||||
| elif hasattr(pipeline, "low_noise_transformer") and low_noise_weight_name: | ||||||||||||||||||||||||||||||||
| max_logging.log(f"Merging LoRA into low_noise_transformer with rank={rank}") | ||||||||||||||||||||||||||||||||
| l_state_dict, _ = lora_loader.lora_state_dict(lora_model_path, weight_name=low_noise_weight_name, **kwargs) | ||||||||||||||||||||||||||||||||
| l_state_dict = lora_conversion_utils.preprocess_wan_lora_dict(l_state_dict) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
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.
Defining
__init__in a mixin class likeLoRABaseMixincan easily lead toAttributeErrorat runtime if subclasses or multiple inheritance hierarchies do not properly callsuper().__init__().\n\nA much safer and more idiomatic approach for Python mixins is to use lazy initialization inside the helper method (e.g., checkinghasattr(self, '_fused_lora_keys')). This completely avoids the need for__init__in the mixin.