(key: str, substrings: list[str])
| 1021 | |
| 1022 | |
| 1023 | def _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 | |
| 1043 | def _convert_bfl_flux_control_lora_to_diffusers(original_state_dict): |
no test coverage detected
searching dependent graphs…