Last active
June 15, 2025 10:14
-
-
Save jiywww/eaca729d17c5597d43f47184b6a922a0 to your computer and use it in GitHub Desktop.
Set the seed for reproducibility.
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
def set_seed(seed: int) -> np.random.Generator: | |
"""Set the seed for reproducibility. | |
Parameters | |
---------- | |
seed: int | |
The seed to set for reproducibility. | |
Returns | |
------- | |
np.random.Generator | |
The random number generator for numpy. | |
""" | |
torch.manual_seed(seed) | |
torch.cuda.manual_seed_all(seed) | |
random.seed(seed) | |
torch.backends.cudnn.benchmark = False | |
torch.backends.cudnn.deterministic = True | |
os.environ["PYTHONHASHSEED"] = str(seed) | |
return np.random.default_rng(seed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment