Skip to content

Instantly share code, notes, and snippets.

@gurucharanmk
Created April 2, 2020 12:39
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 gurucharanmk/e84490502e5d064e8c36d6c242cb64c9 to your computer and use it in GitHub Desktop.
Save gurucharanmk/e84490502e5d064e8c36d6c242cb64c9 to your computer and use it in GitHub Desktop.
Utility function to get deterministic results for PyToch executions
import random
import os
import torch
import numpy as np
def set_seed(seed):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment