Skip to content

Commit

Permalink
Avoid race condition in creating checkpoint directories (#530)
Browse files Browse the repository at this point in the history
* Avoid race condition in creating checkpoint directories

In multi-GPU training, several processes run the code that creates checkpoint dirs. This fix avoids a probably rare situation (but it happened to me) where another process created a dir between the `exists` check and the `makedirs` call.

* Remove the now unneeded check for dir existence
  • Loading branch information
alumae authored and williamFalcon committed Nov 21, 2019
1 parent c1ecca4 commit 539d7bc
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions pytorch_lightning/callbacks/pt_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def __init__(self, filepath, monitor='val_loss', verbose=0,
self.monitor = monitor
self.verbose = verbose
self.filepath = filepath
if not os.path.exists(filepath):
os.makedirs(filepath)
os.makedirs(filepath, exist_ok=True)
self.save_top_k = save_top_k
self.save_weights_only = save_weights_only
self.period = period
Expand Down

0 comments on commit 539d7bc

Please sign in to comment.