Spaces:
Configuration error
Configuration error
Download src/utils/seeding.py from chenwang/physctrl: direct link, hf CLI and curl.
- Browser
- Download file 456 Bytes
-
https://huggingface.co/spaces/chenwang/physctrl/resolve/main/src/utils/seeding.py
- Command line
-
hf download hf://spaces/chenwang/physctrl/src/utils/seeding.py
-
curl -L -o seeding.py https://huggingface.co/spaces/chenwang/physctrl/resolve/main/src/utils/seeding.py
456 Bytes
| import random | |
| import numpy as np | |
| import torch | |
| import hashlib | |
| def seed_everything(seed): | |
| """Set random seeds for Python, NumPy, and PyTorch based on a string.""" | |
| # Convert string to an integer hash | |
| if isinstance(seed, str): | |
| seed = int(hashlib.md5(seed.encode()).hexdigest(), 16) % (2**32) # 32-bit seed | |
| # Set seeds | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| torch.cuda.manual_seed_all(seed) |