cd /news/large-language-models/what-is-deterministic-inference-real… · home › topics › large-language-models › article
[ARTICLE · art-182700] src=kraghavan.ca ↗ pub= topic=large-language-models verified=true sentiment=· neutral

What Is Deterministic Inference, Really?

Setting an LLM's temperature to zero does not make its output reproducible, because greedy decoding only fixes token selection while the underlying logits can shift between identical runs due to non-associative floating-point addition on GPUs. The author documents sending the same prompt twice at temperature=0 and receiving two different completions, then traces the cause to rounding in floating-point arithmetic, where a logit for one token moving from 4.0000 to 4.00012 is enough to flip a near-tied argmax and send the sequence down a different path. The post argues that removing intentional randomness and achieving bit-for-bit determinism are separate problems, and that determinism also breaks when the GPU, driver, or inference engine version changes.

recommendation

Don't rely on temperature=0 for reproducibility: near-tied logits can flip from floating-point rounding, so pin the GPU, driver and engine version and verify bit-for-bit output if determinism matters.

more in playbook: Inference and self-hosting
by read17 min views2 publishedDec 5, 2026
What Is Deterministic Inference, Really?
Image: Kraghavan (auto-discovered)

Let me be honest with you.

The first time someone asked me why our LLM gave two different answers to the same prompt, I said “temperature.” They’d set it above zero, I explained, so there’s randomness baked in. Set it to zero and you’ll get the same thing every time.

That answer is wrong. Not “incomplete” — wrong. I set temperature to zero myself, sent the identical prompt twice, and got two different completions. I had confidently explained a thing I did not understand.

This post is the explanation I wish I’d had. We’re going to find out why temperature=0 doesn’t buy you reproducibility, trace the cause all the way down to how a GPU adds numbers together, and then turn the problem off and measure what it costs. No hand-waving at “floating point is weird.” We go all the way down.

Strap in.

1. “Deterministic” is not the same as “not random” #

Two words get tangled together here, so let’s separate them up front.

  • Deterministic : for a fixed model, software stack, and hardware, the same input always produces the exact same output. Bit-for-bit. Run it a thousand times on that same stack, get one answer. (Change the GPU, the driver, or the engine version, and all bets are off again — more on that in section 12.)
  • Random : the output is drawn from a distribution. Run it a thousand times, get a spread.

People assume these are opposites — that if you remove the randomness, you’re left with determinism. You aren’t. You can build a system with zero intentional randomness that is still not deterministic, because the determinism is being broken somewhere you weren’t looking.

That “somewhere” is the whole story. But first we have to kill the obvious suspect.

The takeaway: removing randomness (temperature) and getting reproducibility (determinism) are two different jobs. temperature=0 does the first and not the second.

2. What temperature=0 actually does #

When an LLM generates a token, the model first produces a logit (a raw score) for every token in its vocabulary. Those logits get turned into probabilities, and then a token is sampled.

Temperature controls the shape of that sampling step. High temperature flattens the distribution so unlikely tokens get a real chance; low temperature sharpens it. At temperature=0 the sampling collapses into a single rule: pick the token with the highest logit. This is called greedy decoding — no dice are rolled, you just take the argmax.

So the sampling is now deterministic. Given a fixed set of logits, greedy decoding returns the same token every time. Case closed, right?

No. We made the selection deterministic. We did nothing about the logits themselves. And it turns out the logits are where the instability lives.

3. The puzzle, made concrete #

Here’s our running example for the rest of the post. Say the prompt is:

The deploy finished and the service came back

and the model is choosing its next token. Two candidates are almost tied:

token logit
up 4.0001
online 4.0000

Greedy decoding picks up. Deterministically. Every time — if the logits are exactly those numbers.

But what if, on the next run, the logit for onlinecomes out as4.00012instead of 4.0000? Nothing "random" happened. No seed changed. Yet now online wins, the sentence continues down a different path, and 60 tokens later you have a completely different paragraph. One token’s worth of rounding, early in the sequence, is all it takes.

So the question sharpens to this: why would a logit come out as a slightly different number on an identical run?

4. Suspect #1: floating point can’t add straight #

Computers don’t store real numbers. They store floating point approximations — a fixed number of bits, so only so many digits of precision, with every operation rounded to fit.

One consequence is that floating-point addition is not associative. In exact math, (a + b) + c == a + (b + c). In floating point, not necessarily. Here’s that run on my machine (numpy 2.5.3, this is real output, not a hypothetical):

(0.1 + 1e20) - 1e20 = 0.0
0.1 + (1e20 - 1e20) = 0.1

Same three numbers. Different grouping. One answer loses the 0.1 entirely, because 0.1 is too small to survive being added to 1e20 in the available precision — it rounds away. Regroup the operation and it survives.

Now scale that up. A single logit is the result of summing thousands of products (that’s what a matrix multiply is). The order you add those thousands of numbers in changes the rounding. Here’s a 10,000-element float32 array summed three different valid ways, plus a high-precision reference:

sequential  (float32): 2.8884206e+09
reversed    (float32): 2.8884196e+09
pairwise    (float32): 2.8884198e+09
fsum        (float64): 2888419939.74...
max spread among float32 orders: 1024.0

Three legitimate orderings of the same numbers, and they disagree by over a thousand. That’s a relative wobble of a few parts in ten million on a sum near 2.9 billion — not a number you can port straight over to a logit, which usually lives in the single digits. But the mechanism scales with whatever sum it’s operating on: reduction order introduces rounding noise sized to the computation, not to some fixed constant. Remember our two candidate tokens were 0.0001 apart — the point isn’t that this exact demo produces that exact gap, it’s that a real logit gap can be smaller than the rounding noise its own sum produces.

The takeaway: the order of summation changes the result, and the gap between the top two tokens is often far smaller than that change.

5. But that’s not the real reason (the plot twist) #

Here’s where the popular explanation goes wrong, and where the Thinking Machines Lab post by Horace He (September 2025) earns its keep.

The folk wisdom is the “concurrency + floating point” hypothesis: GPUs run thousands of threads in parallel, threads finish in an unpredictable order, floating-point addition is non-associative, therefore results wobble run to run. It sounds airtight. It’s mostly wrong.

The catch is that this specific failure mode requires threads to add into the same accumulator in a racing order — an atomic add. That’s a prerequisite for the concurrency story, not for numerical nondeterminism in general (other mechanisms, different reduction strategies, different kernel choices, different communication paths, can also change the bits, which is exactly what’s coming next). And as He points out, in a typical LLM forward pass there usually isn’t a single atomic add present. The big operations — matrix multiplies, attention — are written to reduce in a fixed internal order. Run the same matmul twice on the same GPU with the same inputs and you get a bitwise identical result. The individual kernels are already run-to-run deterministic.

So if the kernels are deterministic, why isn’t the server?

The takeaway: your GPU is not flaky. The nondeterminism is coming from somewhere more interesting.

6. Suspect #2, the real one: batch invariance #

Here’s the actual culprit. Your request does not run alone.

An inference server is a throughput machine. To keep the GPU busy it batches: it grabs every request that’s in flight at that instant and runs them together in one forward pass. The number of requests in that batch — and how long each one is — depends entirely on how much traffic the server is handling at that millisecond.

And here’s the part that breaks everything: a GPU kernel’s choice of how to split up its work can depend on the shape of the batch. When that choice changes, so does the reduction order, the rounding, and potentially the logits — different tiling, different reduction strategy, different summation order, different rounding, slightly different logits. Not every batch-size change flips the kernel’s strategy, and the strategies don’t move in lockstep with batch size either (our own measured results in section 10 land on the same outcome at some batch sizes that differ at others) — but when it does flip, this is the chain that follows.

A kernel is batch-invariant if it returns the same result for your request regardless of what else is in the batch. Most production kernels are not batch-invariant. They’re tuned to go fast for whatever shape they’re handed, and “go fast” means “reduce in whatever order is most efficient for this batch.”

Put the pieces together and you get the real mechanism:

  1. You send a prompt at temperature=0 .
  2. At that instant the server happens to be handling 7 other requests, so your prompt is in a batch of 8.
  3. The kernels pick a reduction order suited to a batch of 8.
  4. Your logits come out carrying the rounding that order produces.
  5. A moment later you send the same prompt, but now the server is quiet — batch of 1.
  6. Different reduction order, different rounding, a near-tied token flips, and your “deterministic” greedy decode produces a different sentence.

The nondeterminism isn’t randomness. It’s a dependency on who else was hitting the server at the same time as you — which is invisible to you and changes constantly. This is also why it isn’t a GPU-only problem: He notes that CPU- and TPU-served endpoints have the same batch-dependence.

7. The three operations that matter #

You don’t have to make the entire stack batch-invariant. The Thinking Machines analysis narrows it to three operations in the forward pass that need fixed, batch-independent reductions:

operation what it does why batch size changes it
Matrix multiply the bulk of every layer; projects and mixes activations tiling/split-K strategy is chosen per batch shape, changing accumulation order
RMSNorm (normalization) rescales activations within each token the reduction across the feature dimension can be parallelized differently per batch
Attention mixes information across tokens reduces over the sequence and interacts with how the KV cache is chunked, which shifts with batch and sequence length

Make these three reduce the same way no matter the batch, and you’ve covered the main reduction-heavy operations in a (simplified) forward pass. That’s the conceptual core of the fix — real implementations have more edge cases around it (custom all-reduce paths, LoRA, and other optimizations that can reintroduce nondeterminism if left alone — more in section 9).

8. Watch a token flip, for real #

I can’t put a live busy-vs-quiet server in a blog post, but I can show you the core event — a reduction-order change flipping which token wins — with a self-contained script you can run on a laptop. No GPU required. This is real output (numpy 2.5.3, default_rng(seed=0)):

forward-order sum:  logit_A = -66869.74   logit_B = -66869.766  -> winner A
reversed-order sum: logit_A = -66869.65   logit_B = -66869.64   -> winner B
Same inputs. Only the summation order changed. The chosen token changed.

Two tokens whose true scores are essentially tied. Sum each token’s ~1000 contributions left-to-right and token A wins. Sum the exact same contributions right-to-left and token B wins. Nothing changed but the order of addition — which, on a real server, is exactly what the batch size changes for you, without asking.

The full script (determinism_demo.py) is three short functions: non-associativity, reduction-order spread, and this argmax flip.

Measured, not claimed: everything in sections 4 and 8 is output from that script on a CPU. The server-scale numbers in the next sections are a mix of vendor documentation and an experiment I ran — and I’ll mark which is which.

9. The fix in production: batch-invariant kernels in vLLM #

As of late 2026 you can flip this on in vLLM with a single environment variable. From the vLLM batch-invariance docs:

VLLM_BATCH_INVARIANT=1 vllm serve meta-llama/Llama-3.1-8B-Instruct

or offline:

import os
os.environ["VLLM_BATCH_INVARIANT"] = "1"
from vllm import LLM, SamplingParams

When enabled, vLLM swaps in deterministic kernel implementations for attention and the other sensitive ops, and disables a few optimizations that would otherwise reintroduce nondeterminism (for example custom all-reduce paths in the distributed case).

A few things worth knowing before you reach for it:

  • It’s beta. Tracked in vLLM issue #27433; expect rough edges and an evolving model-support list.
  • Hardware floor. The current stable docs require NVIDIA GPUs of compute capability8.0 or higher (Ampere and up — A100, A40, RTX 3090/4090, L4/L40, H100). AMD Instinct (gfx90a/942/950) and Intel XPU with the Triton attention backend are also listed.
  • It’s an availability knob, not magic. It makesyour kernels batch-invariant onone fixed software/hardware stack. Change the GPU model, driver, or vLLM version and the exact bits can move again (more in section 12).

10. The experiment: does it actually hold, and what does it cost? #

This is the part you should run yourself before trusting any number. Here’s the design; I’ve kept it inside a hobby budget (a compute-capability-8.0+ GPU on a by-the-hour host — an RTX 4090 or A40 at well under a dollar an hour is plenty, and a 1-2B model keeps each run to seconds).

Setup

  • Model: Qwen/Qwen3-1.7B (small, open, on vLLM’s validated list).
  • One target prompt whose next-token distribution has a near-tie (a couple of candidates worth checking first).
  • Decoding: temperature=0 , fixedmax_tokens (200 for the stability test, 128 for the throughput test),seed=0 .

Procedure

  1. Generate the target prompt alone (batch of 1). Record the output token IDs.
  2. Generate the target prompt bundled with filler prompts (eight varied short technical questions, repeated/truncated to fill each batch) in a single.generate() call, so it rides in a larger batch. Record the target’s output token IDs again.
  3. Repeat across batch sizes 1, 2, 4, 8, 16, 32.
  4. Do all of the above twice : once withVLLM_BATCH_INVARIANT unset, once with it set to1 — the exact commands are:
python gpu_experiment.py                        # default kernels
VLLM_BATCH_INVARIANT=1 python gpu_experiment.py  # batch-invariant kernels
  1. Separately, measure throughput (tokens/sec on a fixed 64-prompt workload) with the flag off vs on. Same two commands — the script runs both the stability and throughput tests in one pass.

What this does and doesn’t test: this is static, offline batching — one process submits a list of prompts in one call, not a live server fielding independent requests from independent clients under fluctuating traffic. It isolates “does batch size change this kernel’s output” cleanly, which is the mechanism this post is about, but it isn’t the same experiment as hammering a running vllm serve endpoint with concurrent requests and watching one of them flip. That’s a believable next step, not something this run claims to have shown.

Prediction (what I expect — to be confirmed by your run, not asserted):

  • Flag off: the target’s output stays identical up to some batch size, then diverges — the first differing token appears, and everything after it is different. The larger or more varied the batch, the more likely the divergence.
  • Flag on: the target’s output isidentical across every batch size , bit-for-bit.
  • Cost: throughput with the flag on islower — batch-invariant kernels give up the per-batch tuning that makes the default path fast. I won’t guess a percentage; measure it.

Results (measured):

batch size identical to batch-1? (flag OFF) first-diff token index (flag OFF) identical? (flag ON)
1 True — True
2 False 13 True
4 False 90 True
8 False 90 True
16 False 13 True
32 False 13 True
configuration throughput (tok/s) relative
flag OFF 5079.7 1.00×
flag ON 3077.6 0.61×

Notice the first-diff index doesn’t move monotonically with batch size (13, then 90, then back to 13) — that’s the “not every batch-size change flips the kernel’s strategy” point from section 6, measured instead of just claimed.

The honest limits of this run: every cell above is a single trial, not an average — no repeated runs, so I can’t report variance or “what fraction of runs diverge.” The table also only has the first-diff token position, not the size of the logit gap that caused it at each batch size — the script logs token IDs for the stability test, not logprobs, so I can’t show you “how close” each flip was beyond the one baseline check back in section 3. Same limits apply to throughput: one run per configuration, on the one fixed 64-prompt workload in gpu_experiment.py — vLLM’s own warmup (CUDA graph capture, kernel JIT) happens before the clock starts, but there’s no separate discard-the-first-measurement step beyond that. And this is one target prompt, picked for a close top-2 race — it tells you the phenomenon is real and roughly what it costs, not how often it bites across a real prompt distribution. Treat the shape of the result (diverges vs. doesn’t, a real throughput cost vs. none) as solid; treat 39.4% as “the cost was substantial on this workload,” not a number that generalizes to yours. To turn this from a demo into a sizing decision: run 50-100 prompts, multiple trials per batch size, against a live vllm serve endpoint instead of one process and a prompt list.

11. Why you should care (even if you never touch kernels) #

This isn’t trivia. Batch-dependence quietly breaks four things engineers rely on every day:

you’re doing this and nondeterminism does this
Debugging you can’t reproduce the bad output, so you can’t bisect it. The baseline moves under you.
Testing assert output == expected is impossible against a server whose output depends on ambient traffic. Everything becomes a flaky test.
Evals / CI your eval score jitters run to run, so a real regression is indistinguishable from numerical noise.
RL training the model generating rollouts and the model computing the training signal round differently, so your “on-policy” updates are secretly off-policy — which destabilizes training. This is the use case vLLM’s docs call out first.

If you’ve ever had a prompt “work yesterday” and fail today with nothing changed, this is a candidate explanation you now know how to test.

12. What determinism still won’t give you #

Turning on batch invariance fixes one axis. Be honest in your head about the others:

  • Cross-hardware. Bit-identical on an A100 does not mean bit-identical on an H100. Different kernels, different numerics.
  • Cross-version. A vLLM or driver upgrade can legitimately change the bits.
  • Cross-engine. vLLM-deterministic and SGLang-deterministic are not the same bits as each other.
  • It’s about reproducibility, not correctness. A batch-invariant model is not abetter model. It’s a model that gives you thesame answer, so you can finally reason about it.

There are also other routes to the same goal. Microsoft Research’s LLM-42, for instance, keeps the fast nondeterministic kernels but wraps them in a verify-and-rollback loop (borrowing the idea from speculative decoding), so you only pay the determinism tax on the traffic that actually needs it. Worth watching if the throughput hit in section 10 stings.

The field is moving, the fundamentals aren’t #

Models, kernels, and flags will keep changing. The mental model won’t:

  • Randomness and determinism are different problems.temperature=0 only solves the first.
  • Your logits are a sum of thousands of rounded numbers, and order changes the sum.
  • Batch size changes that order, and batch size changes with traffic — so your output secretly depends on your neighbors.
  • Batch-invariant kernels fix it by fixing the order, and they cost throughput. Measure the trade before you pay it.

Once you can see the batch hiding behind the “randomness,” temperature=0 stops being a lie you tell juniors and starts being a knob you actually understand.

Next up: I take the section-10 experiment to a real disaggregated setup and see whether prefill/decode splitting makes batch-invariance harder — or easier.

Experiments run on CPU (floating-point demos, numpy 2.5.3) and Lambda Cloud, 1x A10 (24GB PCIe), vLLM 0.34.0, Qwen3-1.7B. Scripts and raw results in gpu-labs/deterministic-inference. Platform engineer with 11+ years in distributed systems going deep on LLM serving infrastructure.

References

── more in #large-language-models 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/what-is-deterministi…] indexed:0 read:17min 2026-12-05 · —