diff --git a/diffsynth/utils/lora/general.py b/diffsynth/utils/lora/general.py index 624549d..85ada77 100644 --- a/diffsynth/utils/lora/general.py +++ b/diffsynth/utils/lora/general.py @@ -1,4 +1,4 @@ -import torch +import torch, warnings class GeneralLoRALoader: @@ -26,7 +26,11 @@ class GeneralLoRALoader: keys.pop(0) keys.pop(-1) target_name = ".".join(keys) - lora_name_dict[target_name] = (key, key.replace(lora_B_key, lora_A_key)) + # Alpha: Deprecated but retained for compatibility. + key_alpha = key.replace(lora_B_key + ".weight", "alpha").replace(lora_B_key + ".default.weight", "alpha") + if key_alpha == key or key_alpha not in lora_state_dict: + key_alpha = None + lora_name_dict[target_name] = (key, key.replace(lora_B_key, lora_A_key), key_alpha) return lora_name_dict @@ -36,6 +40,10 @@ class GeneralLoRALoader: for name in name_dict: weight_up = state_dict[name_dict[name][0]] weight_down = state_dict[name_dict[name][1]] + if name_dict[name][2] is not None: + warnings.warn("Alpha detected in the LoRA file. This may be a LoRA model not trained by DiffSynth-Studio. To ensure compatibility, the LoRA weights will be converted to weight * alpha / rank.") + alpha = state_dict[name_dict[name][2]] / weight_down.shape[0] + weight_down = weight_down * alpha state_dict_[name + f".lora_B{suffix}"] = weight_up state_dict_[name + f".lora_A{suffix}"] = weight_down return state_dict_ diff --git a/examples/qwen_image/model_inference/Qwen-Image-Edit-2511-Lightning.py b/examples/qwen_image/model_inference/Qwen-Image-Edit-2511-Lightning.py index 098a77c..c30ccba 100644 --- a/examples/qwen_image/model_inference/Qwen-Image-Edit-2511-Lightning.py +++ b/examples/qwen_image/model_inference/Qwen-Image-Edit-2511-Lightning.py @@ -18,7 +18,7 @@ lora = ModelConfig( model_id="lightx2v/Qwen-Image-Edit-2511-Lightning", origin_file_pattern="Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors" ) -pipe.load_lora(pipe.dit, lora, alpha=8/64) +pipe.load_lora(pipe.dit, lora, alpha=1) pipe.scheduler = FlowMatchScheduler("Qwen-Image-Lightning") diff --git a/examples/qwen_image/model_inference_low_vram/Qwen-Image-Edit-2511-Lightning.py b/examples/qwen_image/model_inference_low_vram/Qwen-Image-Edit-2511-Lightning.py index cbe43a2..cd5b4f3 100644 --- a/examples/qwen_image/model_inference_low_vram/Qwen-Image-Edit-2511-Lightning.py +++ b/examples/qwen_image/model_inference_low_vram/Qwen-Image-Edit-2511-Lightning.py @@ -28,7 +28,7 @@ lora = ModelConfig( model_id="lightx2v/Qwen-Image-Edit-2511-Lightning", origin_file_pattern="Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors" ) -pipe.load_lora(pipe.dit, lora, alpha=8/64) +pipe.load_lora(pipe.dit, lora, alpha=1) pipe.scheduler = FlowMatchScheduler("Qwen-Image-Lightning") diff --git a/pyproject.toml b/pyproject.toml index 9a5075b..c6ba767 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "diffsynth" -version = "2.0.4" +version = "2.0.5" description = "Enjoy the magic of Diffusion models!" authors = [{name = "ModelScope Team"}] license = {text = "Apache-2.0"}