(new_state_dict, new_k, v)
| 236 | |
| 237 | |
| 238 | def transform_conv_attns(new_state_dict, new_k, v): |
| 239 | if len(new_k) == 1: |
| 240 | if len(v.shape) == 3: |
| 241 | # weight |
| 242 | new_state_dict[new_k[0]] = v[:, :, 0] |
| 243 | else: |
| 244 | # bias |
| 245 | new_state_dict[new_k[0]] = v |
| 246 | else: |
| 247 | # qkv matrices |
| 248 | trippled_shape = v.shape[0] |
| 249 | single_shape = trippled_shape // 3 |
| 250 | for i in range(3): |
| 251 | if len(v.shape) == 3: |
| 252 | new_state_dict[new_k[i]] = v[i * single_shape : (i + 1) * single_shape, :, 0] |
| 253 | else: |
| 254 | new_state_dict[new_k[i]] = v[i * single_shape : (i + 1) * single_shape] |
| 255 | return new_state_dict |
| 256 | |
| 257 | |
| 258 | def main(args): |
no outgoing calls
no test coverage detected