torch.get_rng_state
function get_rng_state(): Uint8ArrayReturns the current random number generator state.
The RNG state is a snapshot of the internal state of the random number generator. This can be saved and restored later to reproduce the same sequence of random numbers. Useful for reproducibility in machine learning experiments.
Use
set_rng_state to restore a saved state. Always save the state BEFORE generating random numbers if you want to reproduce them.Returns
Uint8Array– A Uint8Array containing the RNG state (implementation-dependent format)Examples
// Save the RNG state for reproducibility
const state = torch.get_rng_state();
const x = torch.randn(3, 4);
// Later, restore the state and generate again
torch.set_rng_state(state);
const y = torch.randn(3, 4);
// x and y have the same valuesSee Also
- PyTorch torch.get_rng_state()
- set_rng_state - Restore a saved RNG state
- manual_seed - Set seed for reproducibility
- randn - Generate random tensors