Skip to content

Instantly share code, notes, and snippets.

@dayyass
Created December 20, 2020 10:16
Show Gist options
  • Save dayyass/3f20982404f678ad26ffc70244c506e0 to your computer and use it in GitHub Desktop.
Save dayyass/3f20982404f678ad26ffc70244c506e0 to your computer and use it in GitHub Desktop.
Set global seed for reproducibility.
import torch
import random
import numpy as np
def set_global_seed(seed: int):
"""
Set global seed for reproducibility.
"""
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True
set_global_seed(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment