Restore the default random generator to a previously captured state.
Rewinds (or fast-forwards) the Philox generator to the exact
(seed, counter) pair encoded in state, so that the next
sample call produces exactly the same value as it did immediately
after the get_rng_state call that created state.
Formally, after set_rng_state(state) the generator satisfies:
and the next draw returns .
Parameters
stateTensorLength-2
int64 tensor [seed, counter] as returned by
get_rng_state. Passing a tensor of any other shape or dtype
raises ValueError.Raises
ValueErrorIf
state does not have exactly 2 elements.Notes
set_rng_state + get_rng_state together provide a lightweight
fork–join pattern for reproducible stochastic computation:
Both branches then draw from the same sub-stream, enabling controlled ablations where only the model changes, not the data augmentation noise.
Examples
>>> import lucid
>>> lucid.manual_seed(99)
>>> state = lucid.get_rng_state()
>>> x = lucid.randn(4)
>>> lucid.set_rng_state(state)
>>> y = lucid.randn(4)
>>> (x - y).abs().max().item()
0.0