AI State of the Art
SOTA/Inference & Optimization/26 min
Section 124

Deterministic inference: why temperature zero is not enough

Listen as a podcast →

An experiment that should be boring

Ask a language model the same question a thousand times, and tell it never to pick at random. You would expect a thousand identical answers, word for word. That is the temperature zero setting: at every step the model simply takes the most likely next word, with no random draw at all (what temperature does is covered in sampling).

In September 2025, the team at Thinking Machines Lab ran exactly this experiment. The model: Qwen3-235B-A22B-Instruct-2507, a large open model. The prompt: "Tell me about Richard Feynman". A thousand completions at temperature zero. The outcome: 80 different answers. The most common one came out only 78 times out of 1,000.

Stranger still, every answer was identical for the first 102 tokens (a token is a piece of a word, the unit the model produces at each step). At token 103 they split: most said Feynman was born in "Queens, New York", some said "New York City". From there on, the rest of the text drifted apart.

This is not one provider's bug. It is close to universal behavior for inference servers (inference means running an already-trained model to get its answers). This page explains where it comes from, why the usual explanation falls short, and how to get rid of it.

First ingredient: the order of additions matters

In school we learn that addition is associative: (a+b)+c=a+(b+c)(a+b)+c = a+(b+c). On a computer, that stops being true. Numbers are stored in floating point: a limited number of significant digits plus an exponent that places the decimal point. After every operation, the result is rounded to fit that format.

Picture a toy calculator that keeps only four significant digits, and add 1,000, 0.4 and 0.4:

  • left to right: 1000+0.4=1000.41000 + 0.4 = 1000.4, rounded to 10001000; then 1000+0.41000 + 0.4, rounded to 10001000 again. Result: 1,000;
  • small numbers first: 0.4+0.4=0.80.4 + 0.4 = 0.8; then 1000+0.8=1000.81000 + 0.8 = 1000.8, rounded to 10011001. Result: 1,001.

Same three numbers, two results. Each small number added alone to the big one gets swallowed by the rounding; added together first, they weigh enough to count. Your computer does the same thing at a finer scale:

>>> (0.1 + 0.2) + 0.3
0.6000000000000001
>>> 0.1 + (0.2 + 0.3)
0.6

GPUs (the graphics processors that run models) often compute in formats even shorter than Python's, such as BF16, which keeps only about two to three significant decimal digits (see mixed precision). And a language model spends its life adding: every matrix multiplication is a huge pile of sums of products. Change the order of those sums and you change the last digits of the result.

The usual explanation, and why it falls short

The explanation you hear most often fits in two words: concurrency plus floating point. A GPU's thousands of cores work in parallel; whichever finishes first adds its share to the total; the finishing order varies from run to run, so the order of additions varies, so the result varies.

That mechanism is real (it goes by the name of atomic adds, where several cores write into the same memory slot in an unpredictable order). But the Thinking Machines post shows it is not the culprit here. The compute kernels used in an LLM's forward pass (the computation that turns the input text into probabilities for the next token) generally do not use them. A kernel is a small program that performs one specific operation on the GPU, a matrix multiplication for instance. Give the same kernel exactly the same batch of requests and you get exactly the same bits, every time.

In other words: seen from inside, the server is deterministic. Seen from the user's chair, it is not. A piece is missing.

The real cause: your answer depends on the traffic

The missing piece is batching. An inference server does not process your request alone: it groups it with whatever other users are sending at that moment, to keep the GPU busy (see continuous batching). The batch size, meaning how many requests or tokens are processed together, therefore depends on the server's load at the second you show up.

And compute kernels change strategy depending on batch size. To add up 4,096 numbers, a kernel can hand the whole sum to a single group of cores, or split it into four chunks added in parallel and then combined. The second option is faster when the batch is small, because it puts to work cores that would otherwise sit idle. But it adds in a different order. The last digits change.

So the full chain is:

  1. other users send more or fewer requests;
  2. the batch size changes;
  3. the kernel picks a different way to split its additions;
  4. the numbers computed for your request differ in their last digits;
  5. if two tokens were nearly tied, the top one flips, and the rest of the answer heads somewhere else.

That is what happened at token 103 of the Feynman biography: "Queens" and "New York" were neck and neck, and a microscopic difference tipped the balance. Since every token depends on all the ones before it, a single fork is enough to change everything that follows.

The missing property has a name: batch invariance. A computation is batch-invariant if the result for a given request is the same, bit for bit, whatever the size and contents of the batch it is processed in.

The source: a blog post, not a peer-reviewed paper

Horace He and the Thinking Machines Lab team, "Defeating Nondeterminism in LLM Inference", September 10, 2025, thinkingmachines.ai/blog/defeating-nondeterminism-in-llm-inference. It is a technical blog post with accompanying code, not a peer-reviewed publication. Its experiments have nonetheless been widely picked up, and the main inference engines adopted the idea within weeks.

The fix: three operations to make invariant

Inside an LLM, only a handful of operations perform reductions, that is, combine many numbers into one (a sum, a maximum). Those are the ones to watch. The post singles out three.

1. Normalization (RMSNorm)

RMSNorm rescales each token's vector: it computes a kind of average size of the vector (a sum of squares) and divides by it (normalization layers are introduced in normalization). The standard kernel gives each token to one group of cores, which does the whole sum in a fixed order. Trouble starts when the batch is too small to fill the GPU: some kernels then switch to a strategy where several groups share a single token. The invariant rule is simple: always the same reduction order for each token, even if that leaves part of the GPU idle on small batches.

2. Matrix multiplication

Same logic, more subtle. When matrices are small, kernels like to use split-K: cut the long dimension being summed over into several chunks computed in parallel, then add the chunks. Depending on the matrix shapes, they may also pick different hardware instructions that do not add in the same order. The rule: one kernel configuration for every shape, with no split-K. You give up a little speed on small batches and gain the guarantee that each row of the result is computed the same way, however many rows there are.

3. Attention

Attention is the operation through which each token looks back at the tokens before it. To avoid recomputing everything, the server keeps intermediate results for tokens it has already seen: the KV cache. Two traps here.

First, the same request can be processed in several ways: its input in one block, or in chunks, or partly read from the cache. The order of additions for a given token must depend neither on how many tokens are processed at once nor on how the cache is laid out.

Second, during generation each request contributes a single token per step, which leaves the GPU underused. The usual workaround (called split-KV, popularized as FlashDecoding, a cousin of FlashAttention) cuts the long history into slices processed in parallel. Fix the number of slices and their boundaries move with the length and with how the work is split, so the order of additions moves too. Fix the size of the slices (always 256 positions, say) and the boundaries stay put, so the order no longer changes.

The common thread

In all three cases the rule is the same: how a request's numbers get added up must depend only on that request, never on what surrounds it in the batch. You give up the shortcuts that adapt to load, and accept that the GPU will sometimes be less busy.

What it costs

With these invariant kernels, the same Feynman experiment yields 1,000 identical answers out of 1,000.

The price, as measured by Thinking Machines on Qwen3-8B (a thousand sequences of 90 to 110 tokens):

SetupTime
Default vLLM26 s
Deterministic, unoptimized55 s
Deterministic, with a better attention kernel42 s

That is roughly 1.6 times slower in the best measured version. The author stresses that these kernels were not optimized, and the gap has narrowed since: the SGLang team, for instance, reported an overhead of roughly a third in its own implementation. The numbers depend heavily on the model, the hardware and the load; none of them is universal.

Determinism is not universal reproducibility

Batch invariance guarantees that the same input gives the same output on the same system: same model, same software, same GPU type, same configuration. It does not promise that two different GPUs, or two software versions, will produce the same bits: their kernels may add in different orders. Determinism is a property of a given installation, not of a model.

Why it matters

For a casual user, a little variation in an answer changes nothing. For people building on top of models, it is a different story.

  • Debugging: odd behavior you cannot reproduce is close to impossible to fix.
  • Regression tests: checking that a server update does not change outputs assumes that, absent any change, outputs are identical.
  • Reproducible evaluations: a benchmark score that wobbles by a point between runs makes small comparisons shaky.
  • Caching and verification: serving a previously computed answer again, or checking that an output really came from a given model, is much easier when the computation is reproducible.
  • Reinforcement learning: the deepest use case, covered below.

The reinforcement learning case

In reinforcement learning with verifiable rewards, the model generates answers, they get scored, and the model is nudged to make good answers more likely. Two separate pieces of software are involved: a fast inference engine that generates the answers (the sampler), and a trainer that recomputes the probabilities of those same answers to update the weights (see RL agent training infrastructure).

On paper the learning is on-policy: it learns from answers produced by the model as it currently is. But if the two programs do not add in the same order, they do not compute exactly the same probabilities. The model that generated is not quite the model being trained, so the learning is in fact slightly off-policy, which can destabilize it. The same distinction sits at the heart of on-policy distillation.

Thinking Machines measured this by training a Qwen 2.5-VL 8B instruct model on math problems (the BigMath dataset). They tracked the gap between the two programs with the KL divergence, a measure of distance between two probability distributions (zero means identical):

  • with no correction: the reward collapses partway through training, at the moment of a spike in divergence;
  • with an importance-weighting correction (each example is reweighted by the ratio of the two probabilities, to compensate for the gap): training holds up, but the divergence sits around 0.001, with spikes;
  • truly on-policy, with bit-identical computations on both sides: the divergence stays at zero throughout.

Where inference engines stand

Following the post, the two major open engines added a batch-invariant mode in the fall of 2025 (see serving frameworks): vLLM (environment variable VLLM_BATCH_INVARIANT=1, initially limited to recent NVIDIA GPUs) and SGLang (the --enable-deterministic-inference option). Neither turns it on by default, because of the cost.

The DeepInfer engine, released by DeepSeek on October 20, 2026 under the Apache 2.0 license, goes one step further by separating two guarantees, both limited to NVIDIA GPUs in this release (not Huawei Ascend chips):

  • batch-invariant inference (DEEPINFER_BATCH_INVARIANT=1), exactly the principle described above;
  • deterministic sampling: the same input tokens and the same sampling parameters give the same output, provided you fix a per-sequence seed (seq_seed) and turn off variable-length speculative decoding (DEEPINFER_ENABLE_MTP_VARLEN=0).

Those two extra conditions deserve an explanation.

The seed. Above temperature zero, the model genuinely draws at random among likely tokens. For that draw to be reproducible, the sequence of "random" numbers must be reproducible too: it is generated from a seed, a fixed starting number. And the seed has to belong to each sequence: if a single random generator served the whole batch, the number drawn for you would still depend on who else was being served at the same time.

Speculative decoding. Speculative decoding proposes several "draft" tokens at once (at DeepSeek, through multi-token prediction), which the main model then checks together. In the variable-length version, the number of drafts being checked changes from step to step and from request to request. The shape of the computation therefore changes at every step, and with it the order of additions: exactly what batch invariance is trying to prevent.

A competing approach

Not everyone is convinced batch invariance is the right road: it makes every request pay the cost, even those that do not need determinism. One research team proposes instead to generate quickly, then replay the produced tokens under a fixed computation order and keep only those that check out, in the spirit of speculative decoding. The debate is open.

LLM-42: Enabling Determinism in LLM Inference with Verified Speculation

Key takeaways

  1. Temperature zero does not guarantee the same answer: over a thousand identical requests, a large model produced 80 distinct answers, diverging from a single nearly tied token.
  2. Floating-point addition depends on order, but a given forward pass is generally deterministic: concurrency between cores is not the real cause.
  3. The real cause is a lack of batch invariance: kernels change how they split work depending on batch size, which depends on other users' traffic.
  4. The fix comes down to three operations (normalization, matrix multiplication, attention) made independent of batch size, at a cost of about 1.6 times in the original measurement, reduced since.
  5. The deepest stake is reinforcement learning: without identical computations in generator and trainer, "on-policy" learning is only approximately so.
  6. Deterministic does not mean reproducible everywhere: the guarantee holds for a given system, and above temperature zero it also requires a per-sequence seed.
Vérifiez votre compréhension0 / 4

1. Why can an inference server give two different answers to the same question asked at temperature zero?

2. For attention during generation, why cut the history into slices of fixed size rather than into a fixed number of slices?

3. Why is nondeterminism a particular problem for reinforcement learning?

4. Why does DeepInfer require turning off variable-length speculative decoding to get deterministic sampling?