Download src/utils/seed.py from yashb18/deepreads: direct link, hf CLI and curl.
- Browser
- Download file 694 Bytes
-
https://huggingface.co/spaces/yashb18/deepreads/resolve/main/src/utils/seed.py
- Command line
-
hf download hf://spaces/yashb18/deepreads/src/utils/seed.py
-
curl -L -o seed.py https://huggingface.co/spaces/yashb18/deepreads/resolve/main/src/utils/seed.py
694 Bytes
| """ | |
| Reproducibility utilities — set all random seeds in one call. | |
| """ | |
| from __future__ import annotations | |
| import os | |
| import random | |
| import numpy as np | |
| def set_seed(seed: int = 42) -> None: | |
| """ | |
| Set random seeds for Python, NumPy, and PyTorch (if available). | |
| Args: | |
| seed: Integer seed value. | |
| """ | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| os.environ["PYTHONHASHSEED"] = str(seed) | |
| try: | |
| import torch | |
| torch.manual_seed(seed) | |
| if torch.cuda.is_available(): | |
| torch.cuda.manual_seed_all(seed) | |
| torch.backends.cudnn.deterministic = True | |
| torch.backends.cudnn.benchmark = False | |
| except ImportError: | |
| pass | |