Skip to content

Instantly share code, notes, and snippets.

@back2yes
Forked from ihoromi4/seed_everything.py
Created February 13, 2022 13:43
Show Gist options
  • Save back2yes/8322f72ede818c848f4cda2e1ee720db to your computer and use it in GitHub Desktop.
Save back2yes/8322f72ede818c848f4cda2e1ee720db to your computer and use it in GitHub Desktop.
pytorch - set seed everything
def seed_everything(seed: int):
import random, os
import numpy as np
import torch
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 = True
seed_everything(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment