10000 [LoRA] support non-diffusers hidream loras (#11532) · huggingface/diffusers@0c47c95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c47c95

Browse files
authored
[LoRA] support non-diffusers hidream loras (#11532)
* support non-diffusers hidream loras * make fix-copies
1 parent 7acf834 commit 0c47c95

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed< 8000 /span>

src/diffusers/loaders/lora_conversion_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,3 +1704,11 @@ def get_alpha_scales(down_weight, key):
17041704
converted_state_dict[f"transformer.{key}"] = converted_state_dict.pop(key)
17051705

17061706
return converted_state_dict
1707+
1708+
1709+
def _convert_non_diffusers_hidream_lora_to_diffusers(state_dict, non_diffusers_prefix="diffusion_model"):
1710+
if not all(k.startswith(non_diffusers_prefix) for k in state_dict):
1711+
raise ValueError("Invalid LoRA state dict for HiDream.")
1712+
converted_state_dict = {k.removeprefix(f"{non_diffusers_prefix}."): v for k, v in state_dict.items()}
1713+
converted_state_dict = {f"transformer.{k}": v for k, v in converted_state_dict.items()}
1714+
return converted_state_dict

src/diffusers/loaders/lora_pipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
_convert_hunyuan_video_lora_to_diffusers,
4444
_convert_kohya_flux_lora_to_diffusers,
4545
_convert_musubi_wan_lora_to_diffusers,
46+
_convert_non_diffusers_hidream_lora_to_diffusers,
4647
_convert_non_diffusers_lora_to_diffusers,
4748
_convert_non_diffusers_lumina2_lora_to_diffusers,
4849
_convert_non_diffusers_wan_lora_to_diffusers,
@@ -5371,7 +5372,6 @@ class HiDreamImageLoraLoaderMixin(LoraBaseMixin):
53715372

53725373
@classmethod
53735374
@validate_hf_hub_args
5374-
# Copied from diffusers.loaders.lora_pipeline.CogVideoXLoraLoaderMixin.lora_state_dict
53755375
def lora_state_dict(
53765376
cls,
53775377
pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]],
@@ -5465,6 +5465,10 @@ def lora_state_dict(
54655465
logger.warning(warn_msg)
54665466
state_dict = {k: v for k, v in state_dict.items() if "dora_scale" not in k}
54675467

5468+
is_non_diffusers_format = any("diffusion_model" in k for k in state_dict)
56B9 5469+
if is_non_diffusers_format:
5470+
state_dict = _convert_non_diffusers_hidream_lora_to_diffusers(state_dict)
5471+
54685472
return state_dict
54695473

54705474
# Copied from diffusers.loaders.lora_pipeline.CogVideoXLoraLoaderMixin.load_lora_weights

0 commit comments

Comments
 (0)
0