MCPcopy Index your code
hub / github.com/huggingface/diffusers / _custom_replace

Function _custom_replace

src/diffusers/loaders/lora_conversion_utils.py:1023–1040  ·  view source on GitHub ↗
(key: str, substrings: list[str])

Source from the content-addressed store, hash-verified

1021
1022
1023def _custom_replace(key: str, substrings: list[str]) -> str:
1024 # Replaces the "."s with "_"s upto the `substrings`.
1025 # Example:
1026 # lora_unet.foo.bar.lora_A.weight -> lora_unet_foo_bar.lora_A.weight
1027 pattern = "(" + "|".join(re.escape(sub) for sub in substrings) + ")"
1028
1029 match = re.search(pattern, key)
1030 if match:
1031 start_sub = match.start()
1032 if start_sub > 0 and key[start_sub - 1] == ".":
1033 boundary = start_sub - 1
1034 else:
1035 boundary = start_sub
1036 left = key[:boundary].replace(".", "_")
1037 right = key[boundary:]
1038 return left + right
1039 else:
1040 return key.replace(".", "_")
1041
1042
1043def _convert_bfl_flux_control_lora_to_diffusers(original_state_dict):

Callers 1

Calls 1

startMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…