Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Reference | The implementation you agree to treat as “right” and compare everything else against. |
| Bitwise identical | Every bit of every output number is the same. The strictest kind of “same”. |
| Greedy decoding | Always picking the most likely next token (temperature 0), so there is no randomness in the choice (12.o). |
| Logprob | The natural logarithm of the probability the model gave a token. 0 means certain; −0.7 means about 50%. |
| Margin | How far ahead the top token was: its logprob minus the second-best token’s logprob. A small margin is a near-tie. |
| Distribution | The full list of probabilities the model gives to every possible next token. |
| Regression | A change that makes something worse than it was before. |
| Contract | A written statement of which kind of “same” a system promises, and how it is checked. |
1. What is it?#
An inference server never reproduces the model exactly. It quantizes weights, fuses kernels, batches requests together, splits work across GPUs and guesses tokens ahead. Each of these changes the arithmetic a little. So “is the server correct?” has no yes/no answer until you say what “same as the reference” means.
This lesson gives you a ladder of meanings, from “every bit is the same” down to “users cannot tell the difference”, shows which engineering change breaks which rung, and separates two kinds of difference that look alike from the outside:
- Numerical drift: tiny arithmetic differences that occasionally flip a near-tie. Expected, bounded, explainable (11.k).
- Defects: a wrong chat template, a misrouted request, a broken sampler, a kernel bug. These are bugs, even when they only affect a few percent of requests.
The rest of this module builds the tools: kernel tests (28.b), determinism (28.c), evaluating serving changes (28.d), logprob and KL regression tests (28.e) and debugging incidents (28.f).
Facts checked on 13 November 2026.
2. Why does it matter?#
Because quality bugs in inference are quiet. A crash pages someone in minutes. A server that is slightly worse returns HTTP 200, valid JSON and fluent text. Three public examples:
- Anthropic, August to September 2025. Three separate infrastructure bugs degraded Claude’s answers for weeks: some requests routed to servers configured for a different context window (at the worst hour 16% of Sonnet 4 requests), a TPU misconfiguration that occasionally gave high probability to rare tokens (Thai or Chinese characters in English answers), and a compiler bug in an approximate top-k operation that sometimes dropped the most likely token. Anthropic’s postmortem says its standard evaluations did not catch the degradation, partly because the model often recovers from an isolated mistake.
- Kimi K2 across providers. Moonshot AI saw large differences in tool-call reliability between vendors serving the same open model and published the K2 Vendor Verifier to measure them.
- gpt-oss. OpenAI published a guide and a compatibility test suite for providers, because a wrong prompt format (harmony) or a mishandled reasoning channel “can have cascading generation issues”.
In all three, the weights were fine. The serving system was not. Someone has to own the definition of correct for the serving system, and that is the inference engineer.
3. Simple analogy#
Printing a book. A second print run from the same plates is bitwise identical. A new edition reset in a different font has the same words on different pages: token identical. A careful translation says the same things in other words: equivalent in meaning. An abridged edition keeps the story but drops detail: task equivalent, perhaps. A misprint that swaps two chapters is a defect, even if every individual page is perfect.
Before you complain that the new edition “differs”, agree which of these you were promised.
4. Tiny example: is this divergence noise or a bug?#
Two runs of the same greedy request differ. The useful question is not whether they differ but where and how confident the reference was there. If the reference itself was nearly tied between two tokens, arithmetic noise can flip it. If the reference was confident, noise cannot explain the flip.
// triage.go — classify a divergence between a reference run and a candidate run.
// A divergence at a near-tie is what numerics alone can explain; a divergence where
// the reference was confident is evidence of a real defect.
package main
import "fmt"
// step is what a server returns for one generated position with logprobs on:
// the chosen token and the log-probabilities of the top two candidates.
type step struct {
token string
top1LP, top2LP float64 // natural-log probabilities of the best and second-best token
}
type run []step
// firstDivergence returns the first position where the two runs chose different tokens, or -1.
func firstDivergence(ref, cand run) int {
for i := range min(len(ref), len(cand)) {
if ref[i].token != cand[i].token {
return i
}
}
return -1
}
// classify looks at the reference's own margin at the divergence point.
func classify(ref, cand run, nearTie float64) string {
i := firstDivergence(ref, cand)
if i < 0 {
return "identical tokens"
}
gap := ref[i].top1LP - ref[i].top2LP
verdict := "SUSPECT: reference was confident here; look for a real defect"
if gap < nearTie {
verdict = "expected: near-tie, numerics can flip it"
}
return fmt.Sprintf("diverge at position %d (%q vs %q), reference margin %.3f nats -> %s",
i, ref[i].token, cand[i].token, gap, verdict)
}
func main() {
ref := run{{"The", -0.01, -5.2}, {" capital", -0.20, -2.9}, {" is", -0.05, -4.1},
{" Paris", -0.02, -6.3}, {",", -0.70, -0.74}, {" a", -0.9, -1.6}}
numerics := run{{"The", -0.01, -5.2}, {" capital", -0.20, -2.9}, {" is", -0.05, -4.1},
{" Paris", -0.02, -6.3}, {".", -0.73, -0.71}}
defect := run{{"The", -0.01, -5.2}, {" capital", -0.20, -2.9}, {" is", -0.05, -4.1},
{" Lyon", -1.90, -2.4}}
const nearTie = 0.10 // nats; see section 5 for how to choose it
fmt.Println("candidate A:", classify(ref, numerics, nearTie))
fmt.Println("candidate B:", classify(ref, defect, nearTie))
fmt.Println("candidate C:", classify(ref, ref, nearTie))
}Output:
candidate A: diverge at position 4 ("," vs "."), reference margin 0.040 nats -> expected: near-tie, numerics can flip it
candidate B: diverge at position 3 (" Paris" vs " Lyon"), reference margin 6.280 nats -> SUSPECT: reference was confident here; look for a real defect
candidate C: identical tokensCandidate A differs from the reference, and that is fine: at position 4 the reference gave the comma and the full stop almost the same probability. Candidate B differs at a position where the reference was more than 6 nats sure (a probability ratio of over 500 to 1). No rounding error does that. Look for a wrong template, wrong weights or a broken kernel.
This one idea, judge a difference by the reference’s own confidence, runs through the whole module. 28.e turns it into a full regression test.
5. Technical explanation#
The ladder of sameness#
From strictest to weakest. Each rung implies the ones below it.
RUNG NAME MEANS HOW YOU TEST IT
L0 Bitwise identical every logit bit equal hash the logits
L1 Token identical greedy outputs equal, token for token compare token ids
L2 Same distribution sampled outputs follow the same probability statistical test over many
distribution (individual samples differ) samples (28.d)
L3 Within tolerance per-position distributions close: KL, top-1 teacher-forced logprob and
agreement, logprob deltas under set bounds KL comparison (28.e)
L4 Task equivalent same accuracy, few answer flips on your evals paired evaluation (28.d)
L5 Behaviour equivalent users and downstream systems notice nothing: long generations, tool calls,
tool calls, JSON, length, refusals unchanged JSON validity, canary (23.g)Two warnings about the ladder:
- L1 is weaker than it looks and harder than it sounds. Weaker, because two servers can agree token for token on your test prompts and still differ on a prompt with a near-tie. Harder, because without batch invariance even the same server does not give L1 against itself under load (11.k, 28.c).
- L4 is not implied by a matching average. Two models can both score 71% on a benchmark while answering different questions correctly. Dutta et al. (“Accuracy is Not All You Need”, 2024) call these answer changes flips and argue for KL divergence and flip counts alongside accuracy. 28.d measures them.
Which change breaks which rung#
CHANGE FIRST RUNG IT CAN BREAK NORMAL RESULT IF DONE RIGHT
Batch composition, chunk boundaries L0 (L1 at near-ties) L3 holds easily
Tensor-parallel degree change L0 (L1 at near-ties) L3 holds easily
Kernel or library upgrade L0 L3 holds; must be tested (28.b)
Speculative decoding, greedy L0 (in theory L1 holds) L1 except at near-ties
Speculative decoding, sampling L1 by design L2 holds (12.n)
FP8 weights and activations L0 L3 with small KL (13.e)
4-bit weights, FP8/4-bit KV cache L0 L3/L4; check L5 (13.b, 13.h)
Sampler rewrite (order of top-k, top-p, ...) L1 for sampled requests L2 only if order unchanged (18.e)
Chat template or tokenizer change anything a template is not numerics: test L5
Routing, config, context-window change anything not numerics: test L5Speculative decoding deserves a precise statement, because people overclaim it. The algorithm is exact: with the right acceptance rule, the output distribution equals the target model’s (12.n). The implementation runs the target over several tokens at once to verify them, which is a different shape and therefore a different summation order. vLLM’s documentation says it plainly: speculative decoding is “theoretically lossless up to the precision limits of hardware numerics”, its tests check that the rejection sampler matches the target distribution and that greedy output with speculation equals greedy output without it, and batch size can still shift logprobs. So the honest claim is L2 by construction, L1 except at near-ties.
Choosing the reference#
There is no perfect reference. Pick one on purpose and write it down:
REFERENCE GOOD FOR WEAKNESS
Model author's code, BF16, batch 1, eager porting a new model slow; itself not bitwise stable
(e.g. Hugging Face Transformers) across GPUs and versions
The model author's own API "do we match the original?" you cannot see its logits
or configuration
Your current production build every upgrade and config change inherits its bugs
Your own build in a reproducibility mode investigating incidents slower; still not the author's
(batch invariant, FP32 sampler, TP fixed)Most teams need two: the author’s implementation when a model is first ported, and the previous production build for everything after that.
The serving-layer surface: bugs that are not numerics#
Numerics produce small, unbiased, mostly harmless differences. The incidents that hurt users usually come from the layer around the model:
INPUT SIDE chat template, special tokens (BOS twice or missing), tokenizer version,
system prompt injection, truncation of long prompts, multimodal preprocessing
MODEL SIDE wrong weights or revision, wrong RoPE scaling or context config,
a quantized checkpoint with a broken layer, a kernel bug on one GPU type
OUTPUT SIDE sampling parameters ignored or applied in a different order, stop tokens,
detokenization (12.b), reasoning and tool-call parsing (18.i), structured output
ROUTING SIDE request sent to the wrong model, revision or configuration (the first
Anthropic bug above)28.f is the field guide to these.
Write the contract down#
Every model deployment should carry a short, explicit statement like this, owned by a person and checked automatically:
model: example-org/model-70b-instruct@rev-3f2a # pin the revision
reference: prod build 2026-10-02 (vLLM v0.32.0, BF16 weights, TP=4)
promise:
default_mode: L3 # per-position closeness, not bitwise
l3_bounds: {mean_kl: 0.005, p99_kl: 0.10, top1_agreement: 0.99} # measured, see 28.e
l4: {evals: [internal-qa-500, tool-call-300], max_net_flips: 2%} # see 28.d
l5: {json_valid: ">= 0.995", mean_output_tokens: "within 10%"}
reproducibility_mode: available on request (VLLM_BATCH_INVARIANT=1, seed required)
not_promised:
- identical output for identical prompts in default mode
- identical output across GPU types, engine versions or tensor-parallel degreesThe bounds are not universal constants. 28.e shows how to derive them from the noise between two runs of the reference itself.
6. Under the hood: why “the same text” is such a fragile test#
Autoregressive generation turns small differences into big ones. Once one token differs, the next step sees a different prefix, and every later token is conditioned on something new. So comparing two free-running generations tells you almost nothing after the first divergence: the rest of the text differs because of the first flip, not because of anything new.
Two consequences shape every test in this module:
- Compare position by position on the same prefix. Feed both systems the same tokens (the reference’s output, or a fixed text) and compare their distributions at every position. This is called teacher forcing, and it removes the cascade. 28.e is built on it.
- Count divergences where the reference was confident. A flip at a 0.04-nat margin is expected; a flip at a 6-nat margin is a bug. How many near-ties a generation contains depends on the model, the prompt and the temperature, so measure it: take a few hundred generations from your reference and plot the histogram of the margin between the top two tokens. That histogram tells you how often numerical noise can change the text, which is the honest answer to “why did the same prompt give a different answer?”
The near-tie threshold in the example (0.1 nats) is a starting point, not a standard. Set it from data: run the reference twice with different batch compositions, and find the largest margin at which the two runs ever disagree. Anything well above that is suspicious.
7. Performance implications#
Each rung up the ladder costs speed:
- L1 under load requires batch-invariant kernels, which give up the per-shape kernel choices that make serving fast. Thinking Machines reported 26 s for default vLLM against 42 s for their improved deterministic version on one workload (and 55 s before optimizing attention); SGLang reported an average slowdown of 34% for its deterministic mode in September 2025. Details and the 2026 state are in 28.c.
- L3 with tight bounds rules out aggressive quantization of some layers or of the KV cache.
- Most gains in Module 13 live at L3 or L4. If you promise L1 by default you have promised not to use most of Module 13.
So choose the weakest rung that serves the product, and offer a stronger rung as a mode for the users who need it (evaluation, debugging, reinforcement learning).
8. Production implications#
- Every model deployment gets a written contract (section 5) with a named owner.
- Correctness checks run continuously in production, not only before release. Anthropic’s postmortem lists exactly this as a lesson: run quality evaluations on production systems continuously, and add tests for unexpected characters to the deployment process.
- Rollout guards (23.g) need quality signals, not just latency and errors: output length, finish reasons, JSON validity, refusal rate and, where you can afford it, a logprob probe (28.e).
- Pin everything that defines the model: weight revision, tokenizer revision, chat template hash, engine version, kernel backends, quantization config. A difference you cannot attribute to a change is a difference you cannot fix.
- Have the “why did it change?” answer ready for customers: what you promise (usually L3/L4), what you do not (bitwise repeatability), and how to request a reproducibility mode.
- When you serve someone else’s model, test against the author’s reference, the way the gpt-oss guide asks providers to: format compatibility, tool-call tests and published eval scores.
9. Common mistakes#
- Saying “the outputs differ” without saying at which rung. Every discussion starts with the ladder.
- Promising determinism by default. Without batch-invariant kernels you cannot keep it.
- Treating every difference as numerics. A flip where the reference was confident is a bug.
- Treating a matching benchmark average as proof of equivalence. Count flips (28.d).
- Comparing free-running generations past the first divergence. Everything after it is a consequence, not new evidence.
- Using the author’s reference for every comparison. After the port, compare with your last production build; it is faster and isolates the change.
- Testing the model and not the server. Template, tokenizer, sampler and routing bugs hide behind perfect weights.
10. Hands-on exercise#
- Run
triage.go. Add a candidate that differs at position 1 (" capital", margin 2.7 nats). Is that above any sensible near-tie threshold? - With any OpenAI-compatible server, request 200 greedy completions of 300 tokens with
logprobs: 2. Build the histogram of top-1 minus top-2 logprob. What fraction of positions have a margin under 0.1 nats? Under 0.01? - Run the same 200 prompts twice: once one at a time, once together with background load. Record where they first diverge and the reference margin at that point. What is the largest margin at which a divergence occurred? Use it as your near-tie threshold.
- Write the section 5 contract for a model you serve. For each line, name the test that checks it.
11. Interview questions#
- Someone reports “the same prompt gives different answers”. Walk through how you decide whether it is a bug.
- Describe a ladder of output equivalence for an inference server. Which rung does speculative decoding preserve, and why not a stronger one?
- Why is comparing two generated texts a poor regression test? What do you do instead?
- Two configurations score the same on a benchmark. Are they equivalent? What else do you measure?
- What should you use as the reference when porting a new model, and when upgrading the engine?
- Name five ways a serving system can degrade quality with correct weights and correct kernels.
- Which correctness guarantee would you offer by default, and which as an opt-in mode? Why?
12. Further reading#
Checked on 13 November 2026.
- Anthropic, “A postmortem of three recent issues” (17 September 2025)
- Dutta et al., “Accuracy is Not All You Need” (arXiv 2407.09141, NeurIPS 2024)
- OpenAI cookbook, “Verifying gpt-oss implementations”
- Moonshot AI, K2 Vendor Verifier
- vLLM v0.32.0 docs, speculative decoding (lossless guarantees section)
- He and Thinking Machines Lab, “Defeating Nondeterminism in LLM Inference” (2025)
- Numerical basics: 11.k. Speculative decoding exactness: 12.n. Rollout guards: 23.g.