Skip to content

Instantly share code, notes, and snippets.

@mickypaganini
Created February 27, 2020 03:31
Show Gist options
  • Save mickypaganini/13578fccb28f1c13f48862ce21f97d9d to your computer and use it in GitHub Desktop.
Save mickypaganini/13578fccb28f1c13f48862ce21f97d9d to your computer and use it in GitHub Desktop.
def set_reproducible_seed(seed):
import torch
import numpy as np
import random
import os
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed)
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment