MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / build_rename_dict

Function build_rename_dict

diffsynth/models/utils.py:113–132  ·  view source on GitHub ↗
(source_state_dict, target_state_dict, split_qkv=False)

Source from the content-addressed store, hash-verified

111
112
113def build_rename_dict(source_state_dict, target_state_dict, split_qkv=False):
114 matched_keys = set()
115 with torch.no_grad():
116 for name in source_state_dict:
117 rename = search_parameter(source_state_dict[name], target_state_dict)
118 if rename is not None:
119 print(f'"{name}": "{rename}",')
120 matched_keys.add(rename)
121 elif split_qkv and len(source_state_dict[name].shape)>=1 and source_state_dict[name].shape[0]%3==0:
122 length = source_state_dict[name].shape[0] // 3
123 rename = []
124 for i in range(3):
125 rename.append(search_parameter(source_state_dict[name][i*length: i*length+length], target_state_dict))
126 if None not in rename:
127 print(f'"{name}": {rename},')
128 for rename_ in rename:
129 matched_keys.add(rename_)
130 for name in target_state_dict:
131 if name not in matched_keys:
132 print("Cannot find", name, target_state_dict[name].shape)
133
134
135def search_for_files(folder, extensions):

Callers

nothing calls this directly

Calls 1

search_parameterFunction · 0.85

Tested by

no test coverage detected