"docs/vscode:/vscode.git/clone" did not exist on "4db08045baa250148b1e176e9ac1d5797affcd75"
Unverified Commit a8f5134c authored by Sayak Paul's avatar Sayak Paul Committed by GitHub
Browse files

[LoRA] support more SDXL loras. (#11292)



* support more SDXL loras.

* update

---------
Co-authored-by: default avatarhlky <hlky@hlky.ac>
parent c7f2d239
...@@ -33,6 +33,24 @@ def _maybe_map_sgm_blocks_to_diffusers(state_dict, unet_config, delimiter="_", b ...@@ -33,6 +33,24 @@ def _maybe_map_sgm_blocks_to_diffusers(state_dict, unet_config, delimiter="_", b
# 1. get all state_dict_keys # 1. get all state_dict_keys
all_keys = list(state_dict.keys()) all_keys = list(state_dict.keys())
sgm_patterns = ["input_blocks", "middle_block", "output_blocks"] sgm_patterns = ["input_blocks", "middle_block", "output_blocks"]
not_sgm_patterns = ["down_blocks", "mid_block", "up_blocks"]
# check if state_dict contains both patterns
contains_sgm_patterns = False
contains_not_sgm_patterns = False
for key in all_keys:
if any(p in key for p in sgm_patterns):
contains_sgm_patterns = True
elif any(p in key for p in not_sgm_patterns):
contains_not_sgm_patterns = True
# if state_dict contains both patterns, remove sgm
# we can then return state_dict immediately
if contains_sgm_patterns and contains_not_sgm_patterns:
for key in all_keys:
if any(p in key for p in sgm_patterns):
state_dict.pop(key)
return state_dict
# 2. check if needs remapping, if not return original dict # 2. check if needs remapping, if not return original dict
is_in_sgm_format = False is_in_sgm_format = False
...@@ -126,7 +144,7 @@ def _maybe_map_sgm_blocks_to_diffusers(state_dict, unet_config, delimiter="_", b ...@@ -126,7 +144,7 @@ def _maybe_map_sgm_blocks_to_diffusers(state_dict, unet_config, delimiter="_", b
) )
new_state_dict[new_key] = state_dict.pop(key) new_state_dict[new_key] = state_dict.pop(key)
if len(state_dict) > 0: if state_dict:
raise ValueError("At this point all state dict entries have to be converted.") raise ValueError("At this point all state dict entries have to be converted.")
return new_state_dict return new_state_dict
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment