Greedy decoding still varies: float32 sums depend on reduction order, and batch size changes the order. A synthetic experiment, vLLM batch invariance and eval rules.
The surprise in a temperature 0 eval
A team runs its help-desk evaluation twice at temperature 0 against the same self-hosted model and gets different answers on a handful of cases. The usual reaction is to suspect a bug in the harness or a hidden sampling parameter. Usually neither is the cause. Greedy decoding picks the token with the largest logit, and the logits themselves are not guaranteed to be bit-identical from one run to the next.
The clearest public account of why is "Defeating Nondeterminism in LLM Inference" by Horace He and colleagues at Thinking Machines Lab, published on 10 September 2025. They sampled 1,000 completions at temperature 0 for one prompt from Qwen3-235B-A22B-Instruct-2507 and got 80 unique completions; the most common appeared 78 times, and the completions were identical for the first 102 tokens. Their diagnosis is not that parallel threads race. Individual kernels are typically run-to-run deterministic. The cause is that the forward pass is not batch invariant: the numbers a request gets depend on how many other requests share its batch, because kernels choose different reduction strategies for different batch sizes.
This guide explains the arithmetic underneath, reproduces the effect with a small synthetic experiment you can run on a laptop, and turns it into rules for evaluation and testing.
Floating-point addition depends on order
In float32, (1e8 + -1e8) + 1 is 1, and 1e8 + (-1e8 + 1) is 0, because -1e8 + 1 rounds back to -1e8. Addition is commutative but not associative. A logit is a dot product of a hidden vector and a row of the output matrix: thousands of products summed. A GPU kernel does not add them one by one. It splits the sum across threads or blocks, adds partial sums, and then combines them. A kernel that splits the reduction into eight parts for one batch size and into one part for another produces two different roundings of the same mathematical value.
The companion example reduction_order_greedy_flips does exactly this on the CPU with numpy 2.4.4. It takes one synthetic 4,096-dimensional dot product and sums the float32 products as 1, 2, 4, 8, 16, 32 and 64 sequential partial sums:
| Partial sums | float32 result |
|---|---|
| 1 | -0.48284379 |
| 8 | -0.48284495 |
| 64 | -0.48284519 |
| float64 reference | -0.48284523 |
All seven orders give seven different float32 values. The spread between the largest and smallest is 1.46e-6. None of them is wrong. They are different roundings.
When a tiny difference changes the answer
A difference of 1e-6 in one logit only matters when two candidate tokens are nearly tied. The example builds 2,000 synthetic pairs of candidate rows whose true margin is controlled by a scale parameter. For each pair it asks whether the larger logit is the same under a sequential sum and under an eight-way split.
| Margin scale | Median true margin | Pairs whose winner changed (of 2,000) |
|---|---|---|
| 1e-8 | 4.3e-7 | 634 |
| 1e-7 | 4.4e-6 | 111 |
| 1e-6 | 4.4e-5 | 10 |
| 1e-5 | 4.4e-4 | 0 |
These are constructed near-ties, not tokens from a language model, so the counts say nothing about how often a real model flips. What they show is the mechanism. Flips happen only when the margin is comparable to the reduction error, and the largest margin that flipped in the whole run was about 6.4e-6. With a 50,000-token vocabulary and hundreds of generated tokens, a near-tie somewhere in a long completion is not rare. One flip early in a completion changes every token after it, which matches the identical-then-divergent completions in the Thinking Machines measurement.
What this means for serving
On an inference server the batch a request joins depends on what else arrived at the same moment. Under load the batch size varies, so the reduction strategy can vary, and the same prompt can produce different text. The Thinking Machines post describes batch-invariant implementations of RMSNorm, matrix multiplication and attention that fix the reduction strategy regardless of batch size, at some throughput cost.
vLLM now ships this as an option. Its batch invariance documentation, read on 29 November 2026, describes setting VLLM_BATCH_INVARIANT=1 so that output is independent of batch size and request order. It lists supported hardware: NVIDIA GPUs of compute capability 8.0 or higher, some AMD Instinct GPUs, and Intel XPUs with Triton. The feature is marked beta, so check the page for your version before relying on it.
VLLM_BATCH_INVARIANT=1 vllm serve meta-llama/Llama-3.1-8B-InstructHosted APIs are a different case: you do not control batching. The OpenAI Chat Completions seed parameter, for example, is documented as a beta feature that makes "a best effort to sample deterministically", with no guarantee, and points to the system_fingerprint response field to monitor backend changes. Treat a hosted model at temperature 0 as nondeterministic unless its provider documents otherwise.
Rules for evaluation
- Do not interpret a single temperature 0 run as the model's answer. Run each case several times and report the distribution: how many runs passed, and whether the outputs differed.
- Separate harness flakiness from model variation. Record the full output text and a hash of it for every run. Identical hashes with different verdicts point at the grader; different hashes point at decoding.
- Compare candidates on the same footing. If you can make your own server batch invariant for evaluation, do it for both the baseline and the candidate. If you cannot, compare pass rates over repeated runs, not single outputs.
- Find the fragile cases. When the same prompt yields different completions, look for the first divergent token and log the top two logits there if the server exposes log probabilities. A small margin at that position confirms a near-tie, not a harness bug.
- Make assertions semantic. A test that checks an exact string fails on harmless divergence. Check the structured fields the product depends on: the refund amount, the case status, the tool called.
Rules for tests in CI
For a unit test of an agent harness, do not call a model at all. Record model responses as fixtures and replay them, so the harness test is deterministic by construction. Keep a separate, smaller suite of live model tests that run several trials per case and pass on a threshold, with the trial outputs attached to the report. Pin model, server version and the batch-invariance setting in that suite's configuration, because any of the three can change the outputs.
Limits of the experiment
The example reproduces only the reduction-order part of the story, on a CPU, with synthetic vectors. Real kernels also differ in accumulation precision, often bfloat16 inputs with float32 accumulators, in tiling, and in split-K strategies. Attention adds its own reductions over the sequence. The numbers in the table are exact and reproducible for numpy 2.4.4 on one machine; the flip counts are a property of the constructed margins, not of any model.
How to verify on your own stack
Send the same prompt 50 times in parallel with unrelated traffic, at temperature 0, and count unique completions. Then send it 50 times alone. If the parallel run varies and the solo run does not, batch composition is the cause. Repeat with batch invariance enabled if your server supports it, and measure the throughput cost before turning it on in production.