set_rng_state

paddle.cuda. set_rng_state ( new_state: core.GeneratorState, device: DeviceLike | None = None ) None [source]

Set the random number generator state of the specified device.

Parameters
  • new_state (core.GeneratorState) – The desired RNG state to set. This should be a state object previously obtained from get_rng_state().

  • device (DeviceLike, optional) – The device to set the RNG state for. If not specified, uses the current default device (as returned by paddle.framework._current_expected_place_()). Can be a device object, integer device ID, or device string.

Returns

None

Examples

>>> import paddle
>>> # Save RNG state
>>> state = paddle.cuda.get_rng_state()
>>> # Do some random operations
>>> x = paddle.randn([2, 3])
>>> # Restore RNG state
>>> paddle.cuda.set_rng_state(state)