delu.improve_reproducibility#
- delu.improve_reproducibility(base_seed, one_cuda_seed=False)[source]#
[DEPRECATED | Instead, use
delu.random.seedand manually set flags mentioned in the PyTorch docs on reproducibility] Set seeds and turn off non-deterministic algorithms.Do everything possible to improve reproducibility for code that relies on global random number generators. See also the note below.
Sets:
seeds in
random,numpy.random,torch,torch.cudatorch.backends.cudnn.benchmarktoFalsetorch.backends.cudnn.deterministictoTrue
- Parameters:
base_seed (int | None) – 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_seedis set toNone, the generated base seed is returned; otherwise,
base_seedis 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)