Seeded generation reproducibility boundaries
Control request-owned random streams and complete generation manifests without promising identical pixels across arbitrary numerical environments.
On this page
The question for today
What you’ll understand
- Distinguish an initial seed from a generator’s current state and draw assignment.
- Preserve request streams across batching, retries, and cancellation.
- Define bitwise, numerical, perceptual, and distributional reproducibility claims separately.
A seed is one input to a generation computation, not a complete description of its output. Models, schedules, guidance, random draw ordering, precision, kernels, batching, and decoding also matter. A serving system should preserve enough state to reproduce the promised level of behavior and state that level clearly. Cross-hardware identical pixels are a much stronger claim than using the same initial integer seed.
A random stream has state and an assignment policy
Initial latent generation and stochastic sampler steps can consume random values. Reusing a generator object after one request starts from its advanced state unless it is explicitly reset or reconstructed. Diffusers v0.35.1 recommends passing generator state and explains this consumption behavior. A deterministic ODE-style sampler may use no new stochastic draws after initialization, but its output still depends on the initial latent. A stochastic sampler can require an entire per-step noise stream in addition to that initial state.
A global generator shared across requests can assign different draws when batch order, step count, cancellation, or retries change. Give each request an explicit stream policy, with stable logical identifiers and a declared retry rule. Separate per-request generators or a supported counter-based mapping can reduce scheduling coupling, but neither is implemented merely by attaching a request ID to a log. If a model uses multiple random sources, include every relevant source and the transformation from random state to tensors. Preserve actual initial latents or noise tensors when that is the needed comparison boundary.
Numerical execution is another part of the manifest
Record model and autoencoder revisions, tokenizer and conditioning artifacts, adapters, scheduler configuration, realized grid, guidance policy, prediction type, precision, initial latent or generator state, and relevant software/hardware settings. Floating-point reduction order, kernel selection, nondeterministic operations, and batch shape can change results even with the same random draws. CPU-generated initialization can help align one source of randomness across devices but does not force the subsequent denoiser and decoder arithmetic to match bitwise.
PyTorch and the pinned Diffusers reproducibility documentation explicitly limit guarantees across releases and platforms. Deterministic-algorithm settings can improve repeatability in a supported fixed environment while changing performance or rejecting unsupported operations. Define the oracle: exact latent or pixel equality, bounded numerical error, perceptual similarity, or a distributional test. Passing a tolerance for one generated image is not proof that two samplers have the same output law, and bitwise equality on one machine is not a universal portability guarantee.
Test scheduling independence and restoration explicitly
Replay a fixed request alone, in different compatible batch orders, after another request consumes random values, and after a neighboring request is canceled. Verify the intended stream assignment and compare outputs using the declared oracle. Test retries separately: the service may promise the same candidate again or intentionally create a new sample, but that policy should not depend on accidental process-global RNG progress. For resumable generation, preserve the latent, solver history, coordinate, and random state at one consistent boundary rather than only the original seed.
The modular instrument is a transparent sequence-position analogy, not a random generator. Reset, set both m=16 and a=5, predict residue fifteen after three additions, then Step three times. Separately Reset, set both m=16 and a=3, predict residue nine after three additions, then Step three times. Both sequence rule and position affect subsequent values. This short exact periodic orbit has no Gaussian sampling, statistical randomness, device kernels, or model outputs. It helps distinguish a fully specified stream position from the fact that two processes once started at zero.
Work it through
Shared consumption changes which request gets a draw
Use the deterministic toy sequence formed by repeatedly adding five modulo sixteen from zero. The first four values are 5, 10, 15, and 4. Two requests A and B each need two values; compare sequential and interleaved assignment.
With A consuming two values first, A receives (5,10) and B receives (15,4). The shared sequence itself is fully determined by its starting state and rule.
With interleaving A,B,A,B, A receives (5,15) and B receives (10,4). A’s second value changes from ten to fifteen although the global sequence and initial state are unchanged.
This is not a statistical PRNG example. It demonstrates why a common initial seed does not define per-request draw assignment when scheduling changes. Actual generation needs an implemented request-stream policy plus a scoped numerical reproducibility contract.
Control both stream state and ownership. Identical global initialization is weaker than reproducible request-level random inputs, which is itself weaker than universal bitwise output identity.
The living notebook
Explore the model
Interactive lab · modular
The sequence rule and position determine the next value
Reset, set both m=16 and a=5, predict residue fifteen after three additions, then Step three times. Separately Reset, set both m=16 and a=3, predict residue nine, then Step three times. This deterministic additive orbit is not a PRNG, Gaussian source, statistical independence test, or cross-device generation comparison.
- 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 forRecord request stream assignment and numerical conditions in addition to the seed.
Pause & reason
Check your understanding
Your turn
Try it yourself
A hypothetical sampler draws one four-element initial noise tensor and two later four-element stochastic noise tensors. Count the abstract generated variates, and explain why this does not necessarily equal the number of underlying uniform RNG operations.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Count tensor elements first, then distinguish a requested distribution from its implementation.
Compare with the solution
The sampler requests 4+2×4=12 abstract noise variates. A backend can generate normal values using vectorized methods, cached intermediates, or other transformations, so twelve variates do not specify twelve uniform draws or a portable raw generator-state offset. Preserve the actual supported state or assigned tensors rather than inventing that equivalence.
Keep the idea
Take it with you
- Treat seeds, current generator states, and request draw assignments separately.
- Preserve the complete sampler and numerical manifest for the promised oracle.
- Do not equate fixed randomness with universal cross-hardware or distributional exactness.
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.