-
-
Save ricgu8086/ae7241b24ae0b0d7410c3a08ba846d4a to your computer and use it in GitHub Desktop.
pytorch - set seed everything
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 seed_everything(seed: int): | |
import random, os | |
import numpy as np | |
import torch | |
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 | |
torch.backends.cudnn.benchmark = True | |
seed_everything(42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment