# Defeating Nondeterminism in LLM Inference

- **ID:** 1407
- **Kind:** post
- **URL:** https://thinkingmachines.ai/blog/defeating-nondeterminism-in-llm-inference/
- **Authors:** Horace He (Thinking Machines Lab)
- **Venue:** Thinking Machines Lab blog, "Connectionism" series, published Sep 2025
- **Published:** 2025
- **Source:** blog
- **Language:** en
- **Access:** free
- **Added:** 2026-10-19
- **Verified:** 2026-10-19
- **Page:** https://papers.projxon.ai/entries/1407

## Summary

The "concurrency + floating point" story for LLM nondeterminism is incomplete: the forward pass contains no atomic adds and is run-to-run deterministic. The true culprit is lack of BATCH INVARIANCE — matmul/RMSNorm/attention kernels change reduction order/tiling with batch size (split-K matmuls, tensor-core tile choice, attention split on KV cache vs current tokens), and inference servers change batch composition via continuous batching, so "identical" requests from one user's perspective get different outputs. Fix: batch-invariant kernels for the three reduction ops (data-parallel RMSNorm; single compiled matmul config, ~20% cost vs cuBLAS; attention with pre-kernel KV-cache/page-table layout update and FIXED-SIZE split-KV — which required internal FlexAttention changes not included in the code release). Evidence: 1000 temperature-0 completions of 1000 tokens from Qwen3-235B-A22B-Instruct-2507 ("Tell me about Richard Feynman") → 80 unique completions, identical for first 102 tokens, first divergence at token 103 ("Queens, New York" 992 vs "New York City" 8); with batch-invariant kernels all 1000 identical. True on-policy RL: RLVR on BigMath with Qwen2.5-VL-Instruct-8B, bitwise-identical sampler/trainer → KL divergence flat at 0, trains smoothly without importance weighting; the naive run's reward collapses ~step 318 with a KL spike. Claim: train/inference numeric mismatch "implicitly turns our on-policy RL into off-policy RL." Fun detail: Triton FlashAttention backward differs algorithmically from the FA-2 paper — recomputes to avoid atomics at 40% more FLOPs. Repo: github.com/thinking-machines-lab/batch-invariant-ops (torch.Library substitution layer + vLLM FlexAttention deterministic-mode demo), MIT.

## Research notes

- Discovery: Hudson shared the bare blog link 2026-10-19. Relevance: (1) his RLVR work — train/inference numeric mismatch makes his rollouts implicitly off-policy; true on-policy RL via deterministic inference is the fix; connects to #47 (Thinking Leakage — RLVR must-read) and the precision theme of #59 TF-OPD (bf16 gotcha) and #66 (Muon grid float32 gotcha); (2) his training stack uses FlashAttention — the FA-backward-algorithm-difference detail is directly on his axis; (3) Launch Helm: bit-reproducibility as a monitoring primitive (same request → same output regardless of server load); (4) Model Axes: eval reproducibility — 80 unique temperature-0 completions means "temperature 0" is not the fixed point people assume; his evals should pin or monitor batch-invariance. Adoption evidence (secondary, labeled): vLLM ships VLLM_BATCH_INVARIANT=1 with a docs page and Oct-2026 release-note items; vLLM's 2026-10-14 RL blog productizes bitwise train/inference consistency; Cybernetic Physics applied TML kernels to π0 and hit two sharp edges (SigLIP conv reduction-order switch at batch 32; rank-4 matmul dispatching to aten::bmm bypasses the TML mm kernel); SGLang experimental options and TensorFold's byte-identical marketing are third-party claims, not independently verified. Open: whether the promised upstream FlexAttention changes were delivered (not found); the repo's star count and README date are unverified (browser fetch of the repo failed and was not retried). Cluster: training/inference consistency, eval reproducibility, numerical precision (#59, #66).
- License: blog text itself carries no stated reuse license (noted); code MIT (verified via LICENSE file text)

## Similar entries

- [Etalon: Holistic Performance Evaluation Framework for LLM Inference Systems](https://papers.projxon.ai/entries/859) (paper, #859)
- [Automated Tensor Scheduling for Hybrid CPU-GPU LLM Inference on Consumer Devices](https://papers.projxon.ai/entries/642) (paper, #642)
- [Disaggregated Quantization: Specializing LLM Prefill and Decode](https://papers.projxon.ai/entries/829) (paper, #829)
- [daVinci-LLM: Towards the Science of Pretraining](https://papers.projxon.ai/entries/1127) (paper, #1127)
- [dattri-LLM: A Unified and Efficient Library for Training Data Attribution at LLM Scale](https://papers.projxon.ai/entries/1329) (paper, #1329)
- [Score Centering Stabilizes Off-policy Reinforcement Learning](https://papers.projxon.ai/entries/1281) (paper, #1281)
