Skip to content

Instantly share code, notes, and snippets.

@gatheluck
Created April 9, 2020 22:21
Show Gist options
  • Save gatheluck/c57e2a40e3122028ceaecc3cb0d152ac to your computer and use it in GitHub Desktop.
Save gatheluck/c57e2a40e3122028ceaecc3cb0d152ac to your computer and use it in GitHub Desktop.
Set seed for python, numpy and pytorch for reproductiveity.
import os
import random
import numpy as np
import torch
def set_all_seeds(seed):
random.seed(seed)
os.environ('PYTHONHASHSEED') = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.backends.cudnn.deterministic = True
@gerardsimons
Copy link

Don't you mean os.environ['PYTHONHASHSEED'] = str(seed) (square brackets) for line 8?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment