BLOG / REPRODUCIBILITY
Determinism belongs in the inference stack
Greedy outputs can change when batch composition changes. Trace the first divergence, then define the reproducibility guarantee your service needs.
A regression disappears when you replay the failing request alone. The prompt and greedy decoding settings are unchanged. Put the request back into a busy serving batch and the output changes again.
This is a hypothetical debugging case, but it exposes a precise question: does a request's numerical result depend on the other requests sharing its execution? A reproducibility test that checks only isolated repetition cannot answer it. The serving configuration belongs in the reproduction recipe.
Find the first different token
Greedy decoding chooses the highest computed logit. It removes random sampling from that choice; it does not require every numerical execution path to produce identical logits.
Consider two constructed executions:
| Candidate | Execution A | Execution B |
|---|---|---|
| Token A | 2.000001 | 2.000003 |
| Token B | 2.000002 | 2.000002 |
| Greedy choice | Token B | Token A |
The tiny change matters because it crosses the decision boundary. With a wider margin, different logits could still select the same token. After the first different token, the two executions condition on different prefixes; comparing later logits no longer isolates the original discrepancy.
Start diagnostics at that first divergence. Preserve the common input prefix and compare the candidate ranking there. Similar-looking final paragraphs, or dramatically different ones, tell you little about the initial cause.
A deterministic kernel can still be batch-dependent
Floating-point arithmetic rounds intermediate values. Changing how values are grouped in a reduction can change the result. Tensor shapes can influence kernel and reduction choices, so the same request in a different batch shape can take a different numerical path.
Thinking Machines' analysis of batch invariance explains the important distinction: repeating each fixed shape deterministically does not guarantee that different shapes produce identical results for the shared request.
This gives two separate tests. Fixed-configuration repetition checks whether an execution repeats. Batch-composition variation checks whether serving neighbors can affect the request. Passing the first does not establish the second.
Neither test justifies attributing every inconsistent response to arithmetic. Changed tokenization, model routing, adapters, or application state can alter the effective input before the forward pass begins.
Preserve inputs before blaming execution
Save the actual token IDs, not only the visible prompt. Chat templates, tool schemas, special-token handling, and tokenizer revisions can change those IDs while leaving the user's text untouched.
Record model and adapter revisions, precision, runtime, attention backend, device configuration, and decoding settings. For sampled decoding, preserve the random-state policy as well. A seed governs random draws within an implementation; it does not specify every arithmetic operation across environments.
PyTorch's reproducibility guidance describes why release and platform boundaries matter. A useful guarantee names the boundary within which it is tested.
Then vary one boundary at a time:
- Repeat identical token inputs in isolation with the execution configuration pinned.
- Keep those inputs fixed while varying neighboring requests, lengths, and arrival timing.
- Locate the first token divergence and compare logits on the same preceding token prefix, where instrumentation permits.
If isolation already fails, batch composition cannot be the sole explanation. If only mixed batches fail, investigate shape-dependent execution and shared serving state. The observation narrows the search; it does not prove one numerical cause.
Choose the guarantee your workflow needs
Different workflows need different observable guarantees:
| Workflow | Useful guarantee to specify |
|---|---|
| Replay a production failure | Same token sequence under a recorded serving configuration |
| Compare numerical implementations | Logits or intermediate tensors within an explicit tolerance |
| Serve log probabilities | Stability of the returned scores, not just the chosen tokens |
| Compare model quality | Task outcomes with uncertainty from repeated evaluation |
Token equality can conceal numerical differences. Numerical differences can coexist with stable task quality. Treating those outcomes as one pass/fail property makes both debugging and evaluation less informative.
A model-quality claim also needs protection from ordinary run variability. If the same configuration produces different evaluation scores on repetition, estimate that variation before interpreting a small difference between configurations as an improvement. A perfectly repeatable result can still be consistently wrong; reproducibility and quality need separate tests.
Make upgrades reopen the contract
A stricter numerical path may constrain kernel choices or reduce shape-specific optimization. Measure its cost on the workload that needs the guarantee. Debugging and evaluation can justify a stricter mode than a latency-sensitive endpoint, but the environments must be labeled clearly when comparing results.
Keep a replay corpus with both isolated and mixed-batch cases. Include varied context lengths and prompts that previously diverged, rather than relying on one stable example. Rerun it when the model, runtime, compiler, driver, or execution policy changes.
The operational commitment is concrete: name what repeats, preserve the conditions, and test the boundary whenever those conditions move.
What to remember
- Debug the first differing token while the preceding token prefix is still identical.
- Fixed-shape repeatability and batch invariance require different tests.
- Preserve effective inputs and serving configuration before diagnosing numerical variability.
- Promise the reproducibility your workflow needs, and revalidate it on upgrades.