Last active
January 20, 2020 14:44
-
-
Save yang-zhang/3b24106938d140dc8675ba26db22fcc5 to your computer and use it in GitHub Desktop.
set_seed function to lock pytorch randomness 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
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.backends.cudnn.deterministic = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment