Created
April 2, 2020 12:39
-
-
Save gurucharanmk/e84490502e5d064e8c36d6c242cb64c9 to your computer and use it in GitHub Desktop.
Utility function to get deterministic results for PyToch executions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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