Saves a checkpoint atomically, avoiding the creation of incomplete checkpoints. This will create a temporary checkpoint with a suffix of ``.part``, then copy it to the final location once saving is finished. Args: checkpoint (object): The object to save.
(self, checkpoint, filepath)
| 720 | # MODEL SAVE CHECKPOINT |
| 721 | # -------------------- |
| 722 | def _atomic_save(self, checkpoint, filepath): |
| 723 | """Saves a checkpoint atomically, avoiding the creation of incomplete checkpoints. |
| 724 | |
| 725 | This will create a temporary checkpoint with a suffix of ``.part``, then copy it to the final location once |
| 726 | saving is finished. |
| 727 | |
| 728 | Args: |
| 729 | checkpoint (object): The object to save. |
| 730 | Built to be used with the ``dump_checkpoint`` method, but can deal with anything which ``torch.save`` |
| 731 | accepts. |
| 732 | filepath (str|pathlib.Path): The path to which the checkpoint will be saved. |
| 733 | This points to the file that the checkpoint will be stored in. |
| 734 | """ |
| 735 | tmp_path = str(filepath) + ".part" |
| 736 | torch.save(checkpoint, tmp_path) |
| 737 | os.replace(tmp_path, filepath) |
| 738 | |
| 739 | def save_checkpoint(self, filepath): |
| 740 | checkpoint = self.dump_checkpoint() |