torchnlp.random package¶
The torchnlp.random
package introduces modules for finer grain control of random state.
-
class
torchnlp.random.
RandomGeneratorState
(random, torch, numpy, torch_cuda)[source]¶ -
numpy
¶ Alias for field number 2
-
random
¶ Alias for field number 0
-
torch
¶ Alias for field number 1
-
torch_cuda
¶ Alias for field number 3
-
-
torchnlp.random.
fork_rng
(seed=None, cuda=False)[source]¶ Forks the torch, numpy and random random generators, so that when you return, the random generators are reset to the state that they were previously in.
Parameters:
-
torchnlp.random.
get_random_generator_state
(cuda: bool = False) → torchnlp.random.RandomGeneratorState[source]¶ Get the torch, numpy and random random generator state.
Parameters: cuda (bool, optional) – If True saves the cuda seed also. Note that getting and setting the random generator state for CUDA can be quite slow if you have a lot of GPUs. Returns: RandomGeneratorState
-
torchnlp.random.
set_random_generator_state
(state: torchnlp.random.RandomGeneratorState)[source]¶ Set the torch, numpy and random random generator state.
Parameters: state (RandomGeneratorState) –