Created
May 30, 2023 03:18
-
-
Save elcolie/5488e296b0b4c976353d7d1ba2e4424b to your computer and use it in GitHub Desktop.
Set all seed for python
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 torch | |
import numpy as np | |
def seed_everything(seed: int): | |
random.seed(seed) | |
os.environ['PYTHONHASHSEED'] = str(seed) | |
np.random.seed(seed) | |
torch.manual_seed(seed) | |
if torch.cuda.is_available(): | |
torch.cuda.manual_seed(seed) | |
torch.backends.cudnn.deterministic = True | |
torch.backends.cudnn.benchmark = True | |
elif torch.backends.mps.is_available(): | |
torch.mps.manual_seed(seed) | |
else: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment