Skip to content

Instantly share code, notes, and snippets.

@SJCaldwell
Created May 20, 2025 16:15
Show Gist options
  • Save SJCaldwell/584dc66a8777ab5dfe644c6f4a5c5a33 to your computer and use it in GitHub Desktop.
Save SJCaldwell/584dc66a8777ab5dfe644c6f4a5c5a33 to your computer and use it in GitHub Desktop.
Striving for reproducibility in pytorch (many seeds)
import random
import numpy as np
def set_seeds(seed=42):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed) # for multi-GPU
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment