(source_state_dict, target_state_dict, split_qkv=False)
| 111 | |
| 112 | |
| 113 | def 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 | |
| 135 | def search_for_files(folder, extensions): |
nothing calls this directly
no test coverage detected