Created
December 3, 2024 09:22
-
-
Save fengjing/ef77ad0fc298918d3b57d5f9c70eb649 to your computer and use it in GitHub Desktop.
seed everything
This file contains hidden or 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 os | |
| import numpy as np | |
| def seed_everything(seed=42): | |
| os.environ["PYTHONHASHSEED"] = str(seed) | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| torch.cuda.manual_seed(seed) | |
| torch.cuda.manual_seed_all(seed) | |
| torch.backends.cudnn.deterministic = True | |
| torch.backends.cudnn.benchmark = False | |
| seed_everything() | |
| # Do training etc after running seed_everything |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment