delu.improve_reproducibility¶
- delu.improve_reproducibility(base_seed, one_cuda_seed=False)[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
base_seed (Optional[int]) – the argument for
delu.random.seed
. IfNone
, a high-quality base seed is generated instead.one_cuda_seed (bool) – the argument for
delu.random.seed
.
- Returns
- if
base_seed
is set toNone
, the generated base seed is returned; otherwise,
base_seed
is returned as is
- if
- Return type
base_seed
Note
If you don’t want to choose the base seed, but still want to have a chance to reproduce things, you can use the following pattern:
print('Seed:', delu.improve_reproducibility(None))
Note
100% reproducibility is not always possible in PyTorch. See this page for details.
Examples
assert delu.improve_reproducibility(0) == 0 seed = delu.improve_reproducibility(None)