Thinking Machines Lab Identifies the Root Cause of Nondeterministic LLM Inference
Summary:Thinking Machines Lab argues that user-visible nondeterminism in LLM serving is not an inevitable consequence of concurrent GPU execution. In a fixed-shape test, a 2048×2048 BF16 matrix multiplication produced bitwise-identical results across 1,000 launches. The deeper problem is that floating-point addition is not associative, while dynamic batching, variable sequence tiling, kernel selection, and reduction partitioning can change the numerical execution path. Temperature zero removes sampling
The central finding from Thinking Machines Lab is that an LLM API returning different outputs at temperature=0 does not mean GPU computation is inherently random. A kernel can be bitwise deterministic when its inputs, tensor shapes, and execution plan remain fixed. User-visible nondeterminism emerges when the service maps the same logical request to different batch shapes, reduction trees, or operator paths, each of which can introduce different floating-point rounding results.
Nondeterminism Is More Than Random Sampling
An LLM generation pipeline has two distinct stages. The model first computes a probability distribution for the next token, and the sampler then selects a token from that distribution. Temperature zero and greedy decoding remove randomness in the sampling stage, but they do not guarantee bitwise-identical upstream logits.
When two candidate tokens have nearly equal logits, an error of only one unit in the last place can flip the argmax. Once the first token changes, the subsequent context and KV cache diverge, amplifying a minute numerical difference into a large output difference. Greedy decoding is therefore not sufficient for determinism, and a fixed random seed cannot repair numerical instability upstream.
From Floating-Point Non-Associativity to Execution-Path Drift
A matrix multiplication computes values equivalent to:
C[i,j] = Σ_k A[i,k] × B[k,j]
Real-number arithmetic is independent of summation order, but finite-precision floating-point addition does not satisfy associativity:
(a + b) + c ≠ a + (b + c)
When values have different magnitudes, a smaller contribution can disappear during an early rounding step. The article's 0.1 + 1e20 example illustrates the effect. Transformer projections, attention scores, MLP operations, and MoE routing all contain floating-point reductions, so a changed reduction tree can alter the final bits of logits.
The important distinction is that GPU concurrency is not by itself sufficient to cause nondeterminism. If every output element has a fixed reduction tree, the same CUDA kernel with the same input, shape, and launch configuration can repeatedly produce identical results. The problem arises when the serving layer changes that execution context.
Why Fixed-Shape Kernels Are Still Insufficient
Thinking Machines Lab provides a direct test using 2048×2048 BF16 matrices. Repeating torch.mm on CUDA 1,000 times produced a maximum absolute difference of zero from the reference result. This shows that the blanket claim that all concurrent GPU computation is nondeterministic is too broad: a fixed-shape matrix multiplication can remain bitwise stable.
That test does not cover the dimensions that vary most in an LLM service. Continuous batching changes the batch dimension M, sequence lengths, prefill-to-decode mix, and attention tiling as requests arrive and leave. A GEMM may consequently select a different algorithm, split-K strategy, or reduction partition. FlashAttention-style kernels can also vary their accumulation order with sequence chunking and online Softmax updates. The same logical request can therefore follow a different numerical path under different concurrent loads.
This resolves the apparent contradiction: an individual kernel is deterministic, and a forward pass with fixed arguments is deterministic, yet the user still observes nondeterministic results. The unstable mapping is between a user request and the kernel arguments and execution plan—not inside the kernel itself.
Four Levels of Determinism
| Level | Conditions that must remain fixed | Common misconception | |---|---|---| | Kernel | Inputs, tensor shape, algorithm, hardware, launch configuration | GPU concurrency is automatically random | | Forward pass | Weights, KV cache, batch size, reduction partitioning, operator versions | Fixing the prompt is sufficient | | Service | Scheduling, batch composition, arrival order, cache state | A single-kernel test represents API behavior | | End-to-end | Model revision, tokenizer, hardware, runtime, sampling, stopping criteria | Semantic similarity guarantees reproducibility |
Only the final level supports reproducibility for scientific experiments, production audits, or incident reconstruction. Bitwise identity across different hardware architectures is usually unrealistic. The more portable objective is bitwise repeatability within a pinned environment, combined with statistical and semantic stability across environments.
Two Engineering Approaches
1. Pin the Execution Configuration
The direct approach is a deterministic inference profile backed by a dedicated queue or endpoint. It fixes batch size and sequence-length buckets, disables features that alter the execution graph—such as continuous batching, dynamic chunked prefill, prefix-cache reuse, or speculative decoding—and pins tensor and pipeline parallelism, dtype, attention backend, and CUDA/cuBLAS versions.
This is operationally simple but often inefficient. Fixed-length buckets introduce padding waste, while reserving a full batch during low traffic can reduce throughput and increase queueing latency. torch.use_deterministic_algorithms(True) can expose unsupported nondeterministic operators, but it does not automatically make a dynamically batched server batch-invariant.
2. Deploy Batch-Invariant Kernels
A more general approach changes numerical kernels so that each row's result does not depend on other rows in the batch. Matrix multiplication, RMSNorm, Softmax, and Attention must use a fixed reduction order across different M values or sequence partitions. This preserves the utilization benefits of continuous batching while allowing the same request to produce consistent logits under different loads.
The main cost is kernel engineering. Fixing the reduction tree may require abandoning shape-dependent split-K paths or restricting aggressive parallel reduction. Custom CUDA or Triton kernels also add compilation, hardware-portability, and maintenance burdens. Batch invariance is not inherently slow, but its performance must be measured with real models, sequence lengths, and concurrency traces.
Verification Must Go Beyond Output Similarity
A useful test matrix should vary batch size, concurrent request combinations, repeated executions, and mixed prefill/decode workloads. Validation should compare more than final text:
- Exact first-token and complete token-ID sequences;
- Maximum absolute logit error, ULP distance, and Top-k ordering;
- Stopping behavior, tool calls, and structured outputs;
- TTFT, TPOT, throughput, tail latency, and GPU utilization.
The test set should deliberately include prompts with nearly tied Top-2 logits to magnify small numerical differences. For agents, code generation, and structured-output workloads, semantic similarity alone is inadequate because one incorrect token can trigger a completely different tool trajectory.
Reproducibility as a Versioned Service Contract
In production, reproducibility should be treated as a versioned service contract rather than a single feature flag. A request record should preserve the model and tokenizer revisions, prompt, sampling configuration, hardware model, runtime and operator versions, execution profile, seed, and output token IDs. For critical workflows, teams can also retain logit hashes and execution traces for key stages.
Environment pinning remains essential. Upgrading a GPU driver, cuBLAS, FlashAttention, or the inference framework can change operator selection and numerical paths. Strict reproduction should pin container digests, model revisions, and attention backends instead of recording only a coarse dependency such as “vLLM.”
Conclusion
Nondeterminism in LLM inference can be defeated, but setting temperature=0 or fixing a random seed is not enough. The real engineering objective is to give every request a stable and auditable floating-point path: either pin the execution plan or make kernels batch-invariant. Thinking Machines Lab's analysis moves the discussion from the vague notion of “GPU randomness” to a testable systems-design problem with concrete mitigations.
— END —Source: Thinking Machines Lab Blog (2026-11-29)
Tags: #LLM Inference #Deterministic Inference #Floating-Point Arithmetic #Dynamic Batching #vLLM
Editorial & Fact-Checking Note: This article is compiled from primary research, official release documentation, and source papers by the ZICQ Newsroom pipeline with automated entity verification and human editorial review. If you notice any technical inaccuracy, please submit a correction via our corrections policy or email our editorial desk directly.
Community Comments