Handles the case where the LightningModule wrapper (FullPintsTransformer) prepends 'model.' to all keys in the state dict. Removes the prefix in-place.
(state_dict: Dict[str, torch.Tensor])
| 538 | |
| 539 | |
| 540 | def remove_model_prefix(state_dict: Dict[str, torch.Tensor]) -> None: |
| 541 | """ |
| 542 | Handles the case where the LightningModule wrapper (FullPintsTransformer) prepends 'model.' |
| 543 | to all keys in the state dict. Removes the prefix in-place. |
| 544 | """ |
| 545 | keys = list(state_dict.keys()) |
| 546 | for key in keys: |
| 547 | new_key = key.removeprefix('model.') |
| 548 | if new_key != key: |
| 549 | state_dict[new_key] = state_dict.pop(key) |
| 550 | |
| 551 | |
| 552 | def add_model_prefix(state_dict: Dict[str, torch.Tensor]) -> None: |