Skip to content

Commit

Permalink
speed-reproducibility fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jun 5, 2020
1 parent 55ca5c7 commit 22d6088
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def train(hyp):
weights = opt.weights # initial training weights

# Configure
init_seeds()
init_seeds(1)
with open(opt.data) as f:
data_dict = yaml.load(f, Loader=yaml.FullLoader) # model dict
train_path = data_dict['train']
Expand Down
7 changes: 5 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
def init_seeds(seed=0):
torch.manual_seed(seed)

# Reduce randomness (may be slower on Tesla GPUs) # https://pytorch.org/docs/stable/notes/randomness.html
if seed == 0:
# Speed-reproducibility tradeoff https://pytorch.org/docs/stable/notes/randomness.html
if seed == 0: # slower, more reproducible
cudnn.deterministic = True
cudnn.benchmark = False
else: # faster, less reproducible
cudnn.deterministic = False
cudnn.benchmark = True

Expand Down

0 comments on commit 22d6088

Please sign in to comment.