Skip to content

Instantly share code, notes, and snippets.

@ground0state
Created September 3, 2020 13:00
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 ground0state/c56b20be516df1a117896daaca29609a to your computer and use it in GitHub Desktop.
Save ground0state/c56b20be516df1a117896daaca29609a to your computer and use it in GitHub Desktop.
import os
import random
import numpy as np
import torch
def set_seed(seed: int = 42):
random.seed(seed)
np.random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment