zero.random.set_randomness¶
-
zero.random.
set_randomness
(seed, cudnn_deterministic=True, cudnn_benchmark=False)[source]¶ Set seeds and settings in
random
,numpy
andtorch
.Sets random seed in
random
,numpy.random
,torch
,torch.cuda
and sets settings intorch.backends.cudnn
.- Parameters
- Returns
- if
seed
is set toNone
, the generated seed is returned; otherwise the
seed
argument is returned as is
- if
- 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:', set_randomness(None))
Examples
assert set_randomness(0) == 0 assert set_randomness(), '0 was generated as the seed, which is almost impossible!'