Adds the 'model.' prefix in-place, if it does not already exist.
(state_dict: Dict[str, torch.Tensor])
| 550 | |
| 551 | |
| 552 | def add_model_prefix(state_dict: Dict[str, torch.Tensor]) -> None: |
| 553 | """ |
| 554 | Adds the 'model.' prefix in-place, if it does not already exist. |
| 555 | """ |
| 556 | keys = list(state_dict.keys()) |
| 557 | for key in keys: |
| 558 | if not key.startswith('model.'): |
| 559 | new_key = 'model.' + key |
| 560 | state_dict[new_key] = state_dict.pop(key) |
| 561 | |
| 562 | |
| 563 | def load_weights( |