Skip to content

Instantly share code, notes, and snippets.

@yang-zhang
Last active January 20, 2020 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yang-zhang/3b24106938d140dc8675ba26db22fcc5 to your computer and use it in GitHub Desktop.
Save yang-zhang/3b24106938d140dc8675ba26db22fcc5 to your computer and use it in GitHub Desktop.
set_seed function to lock pytorch randomness for reproducibility.
def set_seed(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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment