zero.random.init

zero.random.init(seed, cudnn_deterministic=True, cudnn_benchmark=False)[source]

Set seeds and settings in random, numpy and torch.

Sets random seed in random, numpy.random, torch, torch.cuda and sets settings in torch.backends.cudnn.

Parameters
  • seed (Optional[int]) – the seed for all mentioned libraries. If None, a high-quality seed is generated and used instead.

  • cudnn_deterministic (bool) – value for torch.backends.cudnn.deterministic

  • cudnn_benchmark (bool) – value for torch.backends.cudnn.benchmark

Returns

if seed is set to None, the generated seed is returned;

otherwise the seed argument 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.random.init(None))

Examples

assert zero.random.init(0) == 0
generated_seed = zero.random.init(None)