Seeds control streams, not every source of nondeterminism
Inventory random generators, logical actor identity, execution order, and evaluation variability without promising cross-platform bitwise replay.
On this page
The question for today
What you’ll understand
- Scope Gymnasium reset and action-space seeding correctly.
- Distinguish restoring RNG state from repeating an initial seed.
- Quantify variation across independent runs without counting correlated steps as replicates.
A root seed is a useful experiment input, not a complete reproducibility artifact. An RL run includes environment randomization, policy sampling, preprocessing, minibatch shuffling, replay sampling, initialization, and distributed execution order. Gymnasium 1.1.1 defines its reset RNG behavior and separate action-space seeding; PyTorch 2.9 explicitly limits reproducibility guarantees across releases and platforms. State the desired scope: replaying one fixture on one pinned stack, statistically reproducing a result across independent runs, and bitwise identity are different goals.
Assign and record random streams deliberately
Inventory every random generator and the code path that consumes it. Seeding the environment does not necessarily seed sampled actions from its action space, the policy framework, NumPy Generator instances, or another library. In the pinned Gymnasium contract, an integer passed to reset initializes or resets its RNG, while reset with seed None preserves an already initialized stream. Reusing the same seed at every episode can repeatedly revisit the same initial random sequence rather than provide independent episode randomization. Match the procedure to the intended experiment.
Derive streams from stable logical identities and purposes, such as training replicate, actor identity, environment instance, episode, and sampler role, using a documented mapping and supported seed range. A physical rank can change on restart, so it is not always the right logical identity. Check collisions or truncation in any finite seed mapping and avoid assuming distinct integers prove statistically independent streams. Record the generator algorithm and version. A schedule that changes how many random draws are consumed can alter future behavior even when the initial seeds remain identical.
Execution and restart state matter beyond initialization
GPU kernels, floating-point reduction order, library algorithms, asynchronous actor arrival, and environment simulation can introduce variation unrelated to the root seed. Deterministic-operation settings can constrain supported operations on a pinned stack, sometimes with a performance cost, but are not a universal cross-device or cross-release promise. Record hardware, framework, simulator, wrapper, and numerical settings. A fixed seed can still produce a different replay insertion order when actors race, which then changes later minibatches and updates even if each local random stream is individually repeatable.
A restart needs the relevant generator states and consumption positions, not merely the original seed. It may also need environment state, recurrent state, replay contents, sampler state, normalizers, and pending-fragment policy. If the environment cannot serialize a mid-episode state, define recovery at a reproducible episode boundary or acknowledge a changed continuation. Do not claim exact uninterrupted equivalence from loading weights and calling reset with the old root seed. Test the claimed restart scope explicitly with tagged transitions and a short deterministic fixture.
Report variability as evidence rather than seed magic
Separate variability from training seeds from variability of evaluation episodes for one trained checkpoint. Many evaluation episodes reduce uncertainty about that checkpoint’s performance, but they do not replace independent training replicates when claiming an algorithm is reliable. Preserve all scheduled runs, including failures, and specify whether hyperparameters or checkpoint selection used the evaluation data. A single lucky seed can be exactly reproducible and still be unrepresentative. Publish the protocol and distributional evidence alongside the artifact needed to rerun individual cases.
The modular lab illustrates a finite mapping collision, not a random generator. Reset, explicitly set modulus eight and additive step two, predict the orbit period, then Play or Step. Compare a fresh Reset with modulus eight and step one explicitly set. Periods are four and eight; a deterministic stride can revisit a residue before covering all slots. This toy supplies no seed algorithm, independence test, environment dynamics, or framework determinism. It only makes the need to inspect a finite identity-to-stream mapping concrete.
Work it through
Independent run variation is not removed by fixing one seed
Four independent training-replicate returns in a hypothetical fixed protocol are [1,3,3,5]. Treat them as comparable draws with finite variance. Calculate their mean, sample variance, and estimated standard error, without claiming a confidence interval.
The mean is twelve divided by four, or three return units. Deviations are [−2,0,0,2], whose squared sum is eight.
The sample variance is 8/(4−1)=8/3 squared return units. The sample standard deviation is about 1.633 return units.
The estimated standard error is sqrt(8/3)/sqrt(4)=sqrt(2/3), about 0.8165 return units. Four runs provide limited evidence; these calculations do not justify treating thousands of correlated steps as thousands of independent training replicates.
The mean is three with estimated standard error about 0.8165 under the stated assumptions. Reproducing one chosen seed does not remove the variation across runs.
The living notebook
Explore the model
Interactive lab · modular
A finite deterministic mapping can revisit identities early
Use independent Reset → explicitly set BOTH modulus and step → predict → Play/Step runs for (8,2) and (8,1). Their residue periods are four and eight. This is additive modular arithmetic, not a PRNG, seed derivation recommendation, independence test, or RL reproducibility simulator.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forInspect stream identity and generator state rather than assume a root seed defines every execution detail.
Pause & reason
Check your understanding
Your turn
Try it yourself
Four independent comparable replicate returns are [2,2,4,4]. Compute mean, sample variance, and estimated standard error. Would evaluating one checkpoint on 1,000 episodes necessarily establish training-seed reliability?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use the replicate count four for the training-run calculation, then distinguish training and evaluation sources of variation.
Compare with the solution
The mean is three. Squared deviations sum to four, so sample variance is 4/3 and estimated standard error is sqrt((4/3)/4)=sqrt(1/3), about 0.5774. These are not automatically a confidence interval. One thousand evaluation episodes can characterize one checkpoint under the stated episode protocol, but they do not replace independent training replicates or expose seed-sensitive training failures. Record both sources of variability and avoid treating correlated within-run samples as independent algorithm-level evidence.
Keep the idea
Take it with you
- Inventory and identify all random streams and their consumption state.
- Pin execution assumptions and test the precise replay scope claimed.
- Distinguish reproducible individual runs from reliable results across independent runs.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.