| """Deterministic seeding for torch / numpy / random / CUDA.""" | |
| from __future__ import annotations | |
| import os | |
| import random | |
| import numpy as np | |
| import torch | |
| def set_seed(seed: int) -> None: | |
| """Seed all RNGs and enable deterministic CUDA ops where cheap.""" | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| torch.cuda.manual_seed_all(seed) | |
| os.environ["PYTHONHASHSEED"] = str(seed) | |
| # cuBLAS deterministic workspace; some ops still nondeterministic without | |
| # warn_only=True (e.g. scatter_add). | |
| os.environ.setdefault("CUBLAS_WORKSPACE_CONFIG", ":4096:8") | |
| torch.backends.cudnn.deterministic = True | |
| torch.backends.cudnn.benchmark = False | |
| try: | |
| torch.use_deterministic_algorithms(True, warn_only=True) | |
| except Exception: | |
| pass | |
Xet Storage Details
- Size:
- 802 Bytes
- Xet hash:
- 19c51e43fd559494b7ba87c9112919fdd3c22f19c903c95b552155d9ee6615fb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.