Skip to content

Instantly share code, notes, and snippets.

@elcolie
Created May 30, 2023 03:18
Show Gist options
  • Save elcolie/5488e296b0b4c976353d7d1ba2e4424b to your computer and use it in GitHub Desktop.
Save elcolie/5488e296b0b4c976353d7d1ba2e4424b to your computer and use it in GitHub Desktop.
Set all seed for python
import random
import torch
import numpy as np
def seed_everything(seed: int):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = True
elif torch.backends.mps.is_available():
torch.mps.manual_seed(seed)
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment