MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / _atomic_save

Method _atomic_save

utils/pl_utils.py:722–737  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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()

Callers 1

save_checkpointMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected