(checkpoint, model, strict=False)
| 1002 | |
| 1003 | |
| 1004 | def load_checkpoint_to_model(checkpoint, model, strict=False): |
| 1005 | with tempfile.NamedTemporaryFile() as file: |
| 1006 | torch.save(checkpoint, file.name) |
| 1007 | del checkpoint |
| 1008 | if strict: |
| 1009 | model.load_state_dict(torch.load(file.name), strict=True) |
| 1010 | else: |
| 1011 | load_checkpoint_and_dispatch(model, file.name, device_map="auto") |
| 1012 | |
| 1013 | |
| 1014 | if __name__ == "__main__": |
no test coverage detected