Skip to content

Instantly share code, notes, and snippets.

@ihoromi4
Created February 5, 2020 11:49
Show Gist options
  • Save ihoromi4/b681a9088f348942b01711f251e5f964 to your computer and use it in GitHub Desktop.
Save ihoromi4/b681a9088f348942b01711f251e5f964 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)
@dongdk
Copy link

dongdk commented Sep 27, 2024

@peymanrostami does it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment