zero.random.set_randomness¶
-
zero.random.set_randomness(seed, cudnn_deterministic=True, cudnn_benchmark=False)[source]¶ Set seeds and settings in
random,numpyandtorch.Sets random seed in
random,numpy.random,torch,torch.cudaand sets settings intorch.backends.cudnn.- Parameters
- Returns
- if
seedis set toNone, the generated seed is returned; otherwise the
seedargument 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!'