Skip to content

Instantly share code, notes, and snippets.

@ai2ys
Created April 15, 2023 11:43
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 ai2ys/ad675713f0d56af7a04fe7224c86de74 to your computer and use it in GitHub Desktop.
Save ai2ys/ad675713f0d56af7a04fe7224c86de74 to your computer and use it in GitHub Desktop.
Making PyTorch training reproducible

Reproducible Training Runs in PyTorch

For details check out: https://pytorch.org/docs/stable/notes/randomness.html

Seed points should be set at the beginning of an application.

import torch
import random 
import numpy as np

seed = 0
torch.manual_seed(seed)
# The PyTorch docs state that the command above is sufficient for both CPU and CUDA
# torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment