Skip to content

Commit

Permalink
Remove checkpoints only on main process (#1974)
Browse files Browse the repository at this point in the history
* Remove checkpoints only on main process

shutil.rmtree might throw errors if called on multiply processes. Make a call only on main process

* Apply style
  • Loading branch information
Kepnu4 authored Sep 14, 2023
1 parent ce53708 commit bbcdbba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/accelerate/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2720,8 +2720,10 @@ def save_state(self, output_dir: str = None, **save_model_func_kwargs):
os.makedirs(output_dir, exist_ok=True)
if self.project_configuration.automatic_checkpoint_naming:
folders = [os.path.join(output_dir, folder) for folder in os.listdir(output_dir)]
if self.project_configuration.total_limit is not None and (
len(folders) + 1 > self.project_configuration.total_limit
if (
self.project_configuration.total_limit is not None
and (len(folders) + 1 > self.project_configuration.total_limit)
and self.is_main_process
):

def _inner(folder):
Expand Down

0 comments on commit bbcdbba

Please sign in to comment.