import torch
from spotoptim.utils.seed import seed_everything
seed_everything(42)
a = torch.rand(3)
seed_everything(42)
b = torch.rand(3)
print(torch.equal(a, b))True
utils.seed
Global seeding for fully reproducible torch experiments.
Ported from the seed_everything helper of the schu25a compressor-map study (src/rnn/utils.py): seeds Python, NumPy, and torch (CPU, CUDA, and MPS) and switches cuDNN to deterministic mode, so that repeated runs on the same device produce bit-identical results.
Requires the torch optional extra (pip install 'spotoptim[torch]').
| Name | Description |
|---|---|
| seed_everything | Seed every random number generator relevant to a torch experiment. |
Seed every random number generator relevant to a torch experiment.
Seeds Python’s random, PYTHONHASHSEED, NumPy, and torch (CPU and CUDA unconditionally, MPS when available), and sets torch.backends.cudnn.deterministic = True and torch.backends.cudnn.benchmark = False.
| Name | Type | Description | Default |
|---|---|---|---|
| seed | int | The seed value. | required |