Skip to content

Commit 1dff5a8

Browse files
committed
fix peft state dict parsing
1 parent 36acdd7 commit 1dff5a8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/diffusers/loaders/lora_conversion_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def _convert_sd_scripts_to_ai_toolkit(sds_sd):
519519
remaining_keys = list(sds_sd.keys())
520520
te_state_dict = {}
521521
if remaining_keys:
522-
if not all(k.startswith("lora_te1") for k in remaining_keys):
522+
if not all(k.startswith("lora_te") for k in remaining_keys):
523523
raise ValueError(f"Incompatible keys detected: \n\n {', '.join(remaining_keys)}")
524524
for key in remaining_keys:
525525
if not key.endswith("lora_down.weight"):
@@ -558,6 +558,13 @@ def _convert_sd_scripts_to_ai_toolkit(sds_sd):
558558
new_state_dict = {**ait_sd, **te_state_dict}
559559
return new_state_dict
560560

561+
# This is weird.
562+
# https://huggingface.co/sayakpaul/different-lora-from-civitai/tree/main?show_file_info=sharp_detailed_foot.safetensors
563+
# has both `peft` and non-peft state dict.
564+
has_peft_state_dict = any(k.startswith("transformer.") for k in state_dict)
565+
if has_peft_state_dict:
566+
state_dict = {k: v for k, v in state_dict.items() if k.startswith("transformer.")}
567+
return state_dict
561568
return _convert_sd_scripts_to_ai_toolkit(state_dict)
562569

563570

0 commit comments

Comments
 (0)