Delve · Field guide

Why AI gives different answers to the same question

Randomness is the first layer. Context drift and a serving stack that never repeats itself exactly are the other two.

Delve Editorial · AI Engineering · 8 min

#non-determinism #temperature-sampling #context-drift #model-routing #reliability #structured-output

The short answer

Because a language model does not look up an answer. It samples one token at a time from a probability distribution, and that distribution is conditioned on far more than the sentence you typed. Change the sampling, the hidden context, or the serving stack, and you get a different draw.

Three layers produce the difference. Decoding randomness (temperature, top-p, seeds) is the layer you can see and set. Context drift — chat history, system prompts, message order, retrieved documents — silently rewrites the question. System drift — dynamic batching, kernel reduction order, model version, routing — changes output even at temperature zero, because floating-point addition is not associative and GPU kernels reorder their sums by batch shape.

01 · The mechanism

An answer is a sample, not a lookup

A language model scores every token in its vocabulary, turns those scores into a probability distribution, and picks one token. That token is appended to the input and the loop repeats. Generation is a chain of conditional draws, not retrieval from a table.

Temperature divides the scores before normalization: low values sharpen the distribution toward the top candidate, high values flatten it so unlikely tokens get real probability. Top-p truncates the tail and renormalizes. A seed fixes the pseudorandom sequence used for the draw — which makes a run repeatable only if everything upstream of the draw is also identical, and it usually is not.

At temperature zero the sampler takes the highest-probability token, which sounds deterministic. It is not, because the scores are the output of floating-point arithmetic whose order changes with batch shape. Divergence matters only when it changes the winner: the LLM-42 work found that tokens become inconsistent only when floating-point drift is large enough to alter the sampler's pick among near-tied candidates . Early flips compound, because a different token becomes part of the context for every token after it.

A model's answer is one draw from a distribution, not the distribution's peak.

02 · The context

Context is part of the question

The visible question is one term in a much larger conditional. A chat model computes the next token from the entire token sequence: system instructions, prior turns, the order of your messages, retrieved documents, tool outputs, and the formatting around all of it. Change any of those and you have asked a different question, even when the sentence you typed is byte-identical.

Order is the sharpest example. The same three retrieved paragraphs, shuffled, produce different answers because they now sit at different positions and carry different attention weights. A long session does this slowly: an aside early in the conversation keeps conditioning every later turn, so the model appears to change its mind when nothing in your last message changed. Product-level personalization is the deliberate version — the same underlying model behaves differently in two apps because one appends a persona and a policy block.

The honest caveat: prompt sensitivity is real and easy to demonstrate, but it is not a single number. It varies by task, by model, and by how far apart the candidate answers are. The retrieved evidence here contains no controlled measurement of the effect size, so treat any specific magnitude you read elsewhere as task-specific.

An irrelevant sentence can outperform a relevant one in the wrong position — relevance is not the only thing attention is sensitive to.

03 · The stack

The same model is not the same system

A transformer's forward pass is a deterministic function of its weights, its input tokens, and its numeric environment . Weights and tokens can be held fixed. The numeric environment cannot, because it depends on who else is calling the service at that moment.

Serving systems batch requests to keep GPUs busy. The kernels implementing matrix multiplication, normalization, and attention are not batch-invariant: batch shape selects different reduction strategies, and floating-point addition is not associative, so summing the same numbers in a different order yields slightly different results . One reported demonstration sent a thousand identical requests to a 235B-parameter model and received eighty distinct completions . The per-token differences come from how each token's own reductions are performed, not from the values of the other requests in the batch .

Disabling batching restores determinism and destroys throughput; dynamic batching is the single largest serving optimization . Batch-invariant kernels fix it by construction but impose fixed overhead whether or not a workload needs determinism . LLM-42 takes a third route: decode fast and nondeterministically, then verify against a fixed-batch reference and roll back mismatches, paying only for traffic that demands determinism . Model versioning and request routing add a slower-moving layer of the same problem.

Nondeterminism in a deployed model is a throughput purchase — its price is now known.

Temperature-zero reproducibility guidance describes the sampler, not the arithmetic. The taxonomy in — floating-point drift, kernel scheduling, batch dependence, library heuristics — is useful, but that source is an unvetted preprint; only the first three are corroborated by the system-level work in .

04 · The trade-off

When variation is a feature and when it is a fault

Variation is a property, and whether it is a defect depends on what the output is for. In extraction, classification, and factual lookup, the same input should map to the same output; two different labels for the same support ticket are a bug, not creativity. In brainstorming, naming, and red-teaming, a single deterministic answer is the failure mode — temperature zero makes a generator repeat its safest guess.

The controls overlap. Schema-constrained decoding, enum-only answers, and short output limits all shrink the space the model can wander through, which raises consistency — and moves the failure from visible variation to a schema-valid wrong answer. A JSON object can be perfectly formed and contain the wrong invoice total.

Caching is the blunt instrument: key on model version, prompt, and parameters, and the second identical request returns the first answer. That buys latency and stability together, and freezes any error in place until the cache is invalidated.

The practical line is to validate the output rather than the prose. Run the extractor, then check the total against the line items. Consistency without verification just makes a mistake reproducible.

Near-tied candidates are the tipping point: when top-two token probabilities are close, a tiny numerical nudge decides the answer; when one candidate dominates, the same nudge changes nothing.

05 · The controls

What consistency can and cannot be engineered

Diagnose before you control. Repeat an identical prompt in a fresh session at temperature zero — if the output still moves, you have system drift, not sampling. Replay it with the exact same history against a fresh context — if the answer changes, you have context drift. Then vary only temperature, which isolates decoding.

Each layer has a matching control, and each control has a blind spot. Pinning a model snapshot and recording its date stops silent upgrades but forfeits improvements. A fixed seed reduces variance where it is supported without touching arithmetic order. Versioning prompts and retrieval sets turns "the AI got worse" into a diff you can inspect. For pipelines that feed another system, constrain the format and validate the content, and key the cache on model version so a snapshot change does not silently serve stale answers.

The strongest caveat: bitwise reproducibility is an infrastructure property, not a prompt setting. Reaching it requires batch-invariant kernels or a determinism-enforcing scheduler, and both cost throughput . For most products the right target is a stable-enough distribution plus a validation layer, not an identical string.

Consistency is engineered within limits, not assumed.

What each control actually fixes

Controls are layer-specific; pairing one with the wrong layer produces the illusion of reliability.

ControlFixesDoes not fixCost
Temperature 0Sampling noiseBatching and kernel driftRemoves useful diversity
Fixed seedThe pseudorandom draw streamFloating-point reduction orderProvider-dependent support
Pinned model snapshotSilent upgrades and reroutingWithin-version batch varianceMisses model improvements
Schema-constrained outputFormat drift and free-form wanderingWrong content in a valid shapeCan force a bad choice
Prompt-hash cacheRepeat cost and repeat variationErrors baked into the first answerStaleness until invalidation

Common misconceptions

  • Temperature zero makes the model deterministic. It removes sampling randomness only. Batch-dependent floating-point reduction order still shifts token scores, and drift changes the output when it flips a near-tied candidate [S1][S3].
  • The same prompt is the same input. Prompt text is a fraction of the conditioning. System instructions, history, message order, retrieved documents, and tool results all enter the same conditional.
  • Setting a seed makes results reproducible. A seed fixes a pseudorandom stream. It does not control kernel selection, batching, hardware, or provider-side routing.
  • Different answers mean the model is malfunctioning. Sampling from a distribution is the intended design. The defect is an unstable output where the task requires a stable one.

Make variation visible, then bound it

Treat nondeterminism as an engineering property to be located and measured, not a mystery to be argued about.

Record the full input

Log the model snapshot or version string, the exact system prompt, the full message history, parameters, and the retrieved documents. A prompt alone is not a reproducible artifact.

Localize the variance

Run the three tests: fresh session at temperature zero, same-history replay, and temperature sweep. Each isolates one layer before you spend effort on the wrong fix.

Constrain the output surface

Force enums, JSON schemas, or short answer formats where downstream systems consume the result. Fewer free tokens means fewer places for a sampling difference to change the outcome.

Cache on a complete key

Key the cache on model version, prompt version, parameters, and relevant context hash, so a snapshot change invalidates rather than silently serves stale answers.

Test with tolerance

Score regression suites on semantic equivalence or on extracted field accuracy, not string equality. Exact-match evals on a nondeterministic system measure noise, not quality.

What would change my mind: A provider publishing bitwise-identical outputs across batch sizes and hardware at temperature zero, with batch-invariant kernels and no documented throughput penalty.

Recall check

A team sets temperature to 0 and still sees occasional different outputs for the same prompt. What is the most likely explanation?

  1. The sampler still applies randomization at temperature zero
  2. The output depends on batch-dependent floating-point reduction order in the serving kernels
  3. A safety filter rewrites a fraction of responses
  4. The model is retrained between requests

Temperature zero removes sampling noise, but the underlying arithmetic is not batch-invariant: different batch shapes reorder floating-point sums and can flip a near-tied token choice .

A support assistant gives different answers to identical typed questions over a long chat. Which control addresses the most likely cause?

  1. Lowering the temperature to zero
  2. Adding a random seed
  3. Pinning and versioning the exact system prompt, history, and retrieved documents
  4. Increasing the max output length

In a long session the accumulated history and retrieved context are themselves changing the conditional, so the effective question differs even when the typed sentence does not.

Which statement best captures when variation should be suppressed?

  1. Variation is useful for brainstorming and harmful for extraction, where output should be constrained and validated
  2. Both brainstorming and extraction should be fully deterministic
  3. Both should allow maximum variation to improve quality
  4. Temperature only affects extraction pipelines

The task decides. Exploration benefits from multiple draws; structured extraction needs a stable mapping from input to output, backed by format constraints and content validation.

Open questions

  • Can batch-invariant kernels become the default without a throughput penalty? If yes, bitwise reproducibility becomes a standard product property; if no, it stays a premium setting for auditable workloads.
  • How much output variation comes from provider-side routing versus the model itself? Providers rarely publish routing details, which makes cross-vendor reproducibility auditing closer to folklore than measurement.
  • Is semantic-equivalence scoring reliable enough to replace exact-match evaluation? Teams need a pass/fail signal on nondeterministic systems, and a weak scorer can silently grade a regression as acceptable.

Sources

Browse all public guides