From 582d104b93b2028b332e8128d5e51aebe5d2eb2d Mon Sep 17 00:00:00 2001 From: Zach Mueller Date: Tue, 23 Jan 2024 14:30:36 +0100 Subject: [PATCH] Fix windows err with checkpoint race conditions (#28637) Fix windows err --- src/transformers/trainer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/transformers/trainer.py b/src/transformers/trainer.py index f7a15a7fbff1fa..3416bcd72ce378 100755 --- a/src/transformers/trainer.py +++ b/src/transformers/trainer.py @@ -2415,9 +2415,11 @@ 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 - fd = os.open(output_dir, os.O_RDONLY) - os.fsync(fd) - os.close(fd) + # And can only happen on non-windows based systems + if os.name != "nt": + fd = os.open(output_dir, os.O_RDONLY) + os.fsync(fd) + os.close(fd) # Maybe delete some older checkpoints. if self.args.should_save: