Skip to content

Instantly share code, notes, and snippets.

@brodzik
Last active October 8, 2021 19:26
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 brodzik/f811f5d329d33f17da9e096b7084d638 to your computer and use it in GitHub Desktop.
Save brodzik/f811f5d329d33f17da9e096b7084d638 to your computer and use it in GitHub Desktop.
seed_everything i.e. initialize pseudo-random number generators
import os
import random
import numpy as np
import torch
def seed_everything(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
torch.backends.cudnn.benchmark = False
seed_everything(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment