zero.improve_reproducibility¶
- zero.improve_reproducibility(seed)[source]¶
Set seeds in
random
,numpy
andtorch
and make some cuDNN operations deterministic.Do everything possible to improve reproducibility for code that relies on global random number generators from the aforementioned modules. See also the note below.
Sets:
seeds in
random
,numpy.random
,torch
,torch.cuda
- Parameters
seed (Optional[int]) – the seed for all mentioned libraries. Must be a non-negative number less than
2 ** 32 - 1
. IfNone
, a high-quality seed is generated instead.- Returns
if
seed
is set toNone
, the generated seed is returned; otherwise,seed
is returned as is- Return type
seed
Note
If you don’t want to set the seed by hand, but still want to have a chance to reproduce things, you can use the following pattern:
print('Seed:', zero.improve_reproducibility(None))
Note
100% reproducibility is not always possible in PyTorch. See this page for details.
Examples
assert zero.improve_reproducibility(0) == 0 seed = zero.improve_reproducibility(None)