Created
December 20, 2020 10:16
-
-
Save dayyass/3f20982404f678ad26ffc70244c506e0 to your computer and use it in GitHub Desktop.
Set global seed for reproducibility.
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 torch | |
import random | |
import numpy as np | |
def set_global_seed(seed: int): | |
""" | |
Set global seed for reproducibility. | |
""" | |
random.seed(seed) | |
np.random.seed(seed) | |
torch.manual_seed(seed) | |
torch.cuda.manual_seed_all(seed) | |
torch.backends.cudnn.benchmark = False | |
torch.backends.cudnn.deterministic = True | |
set_global_seed(42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment