noether.core.utils.seed¶
Attributes¶
Functions¶
|
Set the seed for random number generation for Python random, numpy, |
|
DataLoader |
Module Contents¶
- noether.core.utils.seed.logger¶
- noether.core.utils.seed.set_seed(seed)¶
Set the seed for random number generation for Python random, numpy, torch and torch.cuda, if available.
- Parameters:
seed (int) – Seed value.
- Return type:
None
- noether.core.utils.seed.seed_worker(worker_id)¶
DataLoader
worker_init_fnthat re-seeds Pythonrandomandnumpyinside each worker.PyTorch already derives a per-worker torch seed from the
DataLoader’sgenerator(orbase_seed) combined withworker_id, sotorch.randperm,torch.randn, etc. inside workers are deterministic as long as theDataLoaderreceives a seededgenerator. However,randomandnumpy.randomare forked from the main process unseeded per-worker, which makes any code using them in a worker non-deterministic across runs. This function pulls the torch worker seed and uses it to reseedrandomandnumpyso the whole worker is deterministic.- Parameters:
worker_id (int) – Worker id passed by the DataLoader. Unused; kept to match the
worker_init_fnsignature.- Return type:
None