Created
February 27, 2020 03:31
-
-
Save mickypaganini/13578fccb28f1c13f48862ce21f97d9d to your computer and use it in GitHub Desktop.
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
def set_reproducible_seed(seed): | |
import torch | |
import numpy as np | |
import random | |
import os | |
torch.manual_seed(seed) | |
if torch.cuda.is_available(): | |
torch.cuda.manual_seed(seed) | |
torch.cuda.manual_seed_all(seed) | |
torch.backends.cudnn.deterministic = True | |
torch.backends.cudnn.benchmark = False | |
np.random.seed(seed) | |
random.seed(seed) | |
os.environ['PYTHONHASHSEED'] = str(seed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment