Skip to content

Commit

Permalink
Removed "with open" due to not working with directory. os.open seems …
Browse files Browse the repository at this point in the history
…to work for directories.
  • Loading branch information
tblattner committed Jan 9, 2024
1 parent df9f6e9 commit eb58698
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2390,9 +2390,9 @@ def _save_checkpoint(self, model, trial, metrics=None):
os.rename(staging_output_dir, output_dir)

# Ensure rename completed in cases where os.rename is not atomic
with open(output_dir, "r") as f:
f.flush()
os.fsync(f.fileno())
fd = os.open(output_dir, os.O_RDONLY)
os.fsync(fd)
os.close(fd)

# Maybe delete some older checkpoints.
if self.args.should_save:
Expand Down

0 comments on commit eb58698

Please sign in to comment.