Skip to content

Commit

Permalink
add clean checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
seiriosPlus committed May 23, 2018
1 parent 192f9a5 commit cf3fb24
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/paddle/fluid/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,19 @@ def load_checkpoint(executor, checkpoint_dir=None, main_program=None):
filename=None)


def clean_checkpoint(checkpoint_dir, delete_dir=False):
"""
clean the checkpoint dir, when the train exits normally, the trainer will call clean_checkpoint to delete checkpoint directory saved before.
delete_dir only works when the directory is empty, otherwise, OSError is raised.
"""
if checkpoint_dir is None:
checkpoint_dir = os.getcwd()
_lru_delete(checkpoint_dir, max_num_checkpoints=0)

if delete_dir and not os.listdir(checkpoint_dir):
os.rmdir(checkpoint_dir)


def _get_serial_dir(serial, checkpoint_dir):
serial_folder = CHECKPOINT_PREFIX + CHECKPOINT_SEPARATOR + str(serial)
return os.path.join(checkpoint_dir, serial_folder)
Expand Down

0 comments on commit cf3fb24

Please sign in to comment.