Skip to content

Instantly share code, notes, and snippets.

@philip-bl
Created April 27, 2019 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philip-bl/7b32a9ddf5de0fea6727defcbf055393 to your computer and use it in GitHub Desktop.
Save philip-bl/7b32a9ddf5de0fea6727defcbf055393 to your computer and use it in GitHub Desktop.
def set_random_seeds(seed_value=555, device='cuda:0'):
'''source https://forums.fast.ai/t/solved-reproducibility-where-is-the-randomness-coming-in/31628/5.'''
np.random.seed(seed_value)
torch.manual_seed(seed_value)
random.seed(seed_value)
if device != 'cpu':
torch.cuda.manual_seed(seed_value)
torch.cuda.manual_seed_all(seed_value)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment