zero.random.set_randomness¶
-
zero.random.
set_randomness
(seed=None, cudnn_deterministic=True, cudnn_benchmark=False, callback=<function _default_callback>)[source]¶ Set seeds and settings in
random
,numpy
andtorch
.Sets random seed for
random
,numpy.random
,torch
,torch.cuda
, sets settings fortorch.backends.cudnn
and builds a NumPy random number generator.- Parameters
seed (Optional[int]) – the seed for all mentioned libraries. If omitted, a high-quality seed is generated (an integer that does not fit in int64). In any case,
seed % (2 ** 32 - 1)
will be used for everything except for buildingnumpy.random.Generator
.cudnn_deterministic (bool) – value for
torch.backends.cudnn.deterministic
cudnn_benchmark (bool) – value for
torch.backends.cudnn.benchmark
callback (Optional[Callable[int, Any]]) – a function that takes the seed as the only argument. The default callback simply prints the seed via
print
which is convenient whenseed
is set toNone
.
- Returns
A new style numpy random number generator constructed via
numpy.random.default_rng
(it should be used instead of functions fromnp.random
, see the document).- Return type
Examples
rng = set_randomness() # seed will be generated rng = set_randomness(0)
Seed: ... (see zero.random.set_randomness) Seed: 0 (see zero.random.set_randomness)