Updates paths inside attentions to the new naming scheme (local renaming)
(old_list, n_shave_prefix_segments=0)
| 184 | |
| 185 | |
| 186 | def renew_attention_paths(old_list, n_shave_prefix_segments=0): |
| 187 | """ |
| 188 | Updates paths inside attentions to the new naming scheme (local renaming) |
| 189 | """ |
| 190 | mapping = [] |
| 191 | for old_item in old_list: |
| 192 | new_item = old_item |
| 193 | |
| 194 | # new_item = new_item.replace('norm.weight', 'group_norm.weight') |
| 195 | # new_item = new_item.replace('norm.bias', 'group_norm.bias') |
| 196 | |
| 197 | # new_item = new_item.replace('proj_out.weight', 'proj_attn.weight') |
| 198 | # new_item = new_item.replace('proj_out.bias', 'proj_attn.bias') |
| 199 | |
| 200 | # new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments) |
| 201 | new_item = new_item.replace("time_stack", "temporal_transformer_blocks") |
| 202 | |
| 203 | new_item = new_item.replace("time_pos_embed.0.bias", "time_pos_embed.linear_1.bias") |
| 204 | new_item = new_item.replace("time_pos_embed.0.weight", "time_pos_embed.linear_1.weight") |
| 205 | new_item = new_item.replace("time_pos_embed.2.bias", "time_pos_embed.linear_2.bias") |
| 206 | new_item = new_item.replace("time_pos_embed.2.weight", "time_pos_embed.linear_2.weight") |
| 207 | |
| 208 | mapping.append({"old": old_item, "new": new_item}) |
| 209 | |
| 210 | return mapping |
| 211 | |
| 212 | |
| 213 | def shave_segments(path, n_shave_prefix_segments=1): |
no outgoing calls
no test coverage detected