Skip to content

Pin the multi-turn determinism probe to a backend that can be deterministic - #10234

Merged
danielhanchen merged 2 commits into
mainfrom
ci-gguf-smoke-determinism
Sep 3, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ci-gguf-smoke-determinism

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

GGUF inference smoke (API, tools, vision) and Chat UI, API, Update and GGUF inference are red on main and on roughly 25 open PRs, on Linux and macOS, with:

Nondeterministic: openai non-deterministic at turn 1 with temperature=0.0:
  run1: 'To find the sum of 58 and 27, we add the two numbers:\n58 + 27 = 95\nSo, 58 + 27 = 95\nTherefore, 58 + 27 = 95\n\nThe answer is 95.'
  run2: 'To find the sum of 58 and 27, we add the two numbers:\n58 + 27 = 95\n'

Nothing in the branches under test can reach that code path, and no commit correlates: the last green run on main is #10131 and the first red is #10090, which touches only context_refusal.py and the Anthropic error-wording paths. The run 20 minutes later passed.

What is actually happening

The probe compares two replays of a greedy conversation, check(label, runner(), runner()). The server it compares them against runs with speculative decoding on.

gemma-3-270m-it is a non-MTP GGUF, so _speculative_flags takes the else at studio/backend/core/inference/llama_cpp.py:25338 and appends --spec-default. The launch line in the failing run's own artifact:

--port 48489 --parallel 4 --flash-attn on --no-context-shift -c 2048
--kv-unified --fit-ctx 2048 --jinja --spec-default --load-mode none

That flag does not mean "no drafter". The server logs from the same run:

slot print_timing: id 3 | task 100 | draft acceptance = 0.46875 (30 accepted / 64 generated), mean len = 31.00
slot print_timing: id 3 | task 134 | draft acceptance = 0.50000 (56 accepted / 112 generated), mean len = 29.00

n-gram drafting, live, on every request. The draft pool is built from text the server has already seen, so the first turn-1 request after a load drafts nothing and decodes one token at a time, and every later one verifies a ~32-token draft in a single batch. check(runner(), runner()) evaluates its arguments left to right, so attempt 1 always compares the one cold replay against a warm one.

llama-server's README says what that costs: "the logits are not guaranteed to be bit-for-bit identical for different batch" sizes. And the divergences match that exactly. They are nested prefixes of each other, not different content:

A = "...58 + 27 = 95\n"
B = A + "So, ...\nTherefore, ... = 95\n"
C = B + "\nThe answer is 95."

A sampler that stopped being greedy produces different words. A 270M model near-tied on <end_of_turn> produces that ladder.

The green runs were diverging the same way. Comparing the last green run (33691479198) against the red one (33731460405), turn-1 requests are identifiable by their 35-token prompt:

attempt 1 replay 1 attempt 1 replay 2 later attempts
green task 0: 27 tok, no draft line task 67: 46 tok, draft acceptance = 0.06250 32 / 32, matched, passed
red task 0: 60 tok, no draft line task 100: 32 tok, draft acceptance = 0.46875 67 / 32, 67 / 32, failed

Identical argv, identical unslothai/llama.cpp b10715, identical model snapshot. The only difference is luck. The ATTEMPTS = 3 retry added in #10025 was carrying it.

Prompt caching is not the variable and never was: _apply_seeded_llama_request already sets cache_prompt = False for a seeded request, and every turn-1 request re-processes all 35 prompt tokens, including one the server matched at f_sim_best = 1.000. Slot contention is not it either: every request in both runs landed on slot 3.

The fix

Pin the probe's load to a configuration where greedy decoding is reproducible, and have the script check the pin took. The byte-exact comparison is unchanged: loosening it is what would hide a real regression.

The three loads that feed multi_turn_chat.py gain "speculative_type": "off", "n_parallel": 1. off is a documented LoadRequest value and takes the effective_mode == "off" branch, which emits no speculative flag at all. n_parallel: 1 also drops --kv-unified, whose shared-pool occupancy is a second input to the batch. Only those three loads change. The tool-calling and vision phases keep both defaults, so the configuration real users get stays covered by CI for correctness.

A workflow pin nobody verifies is worth nothing, so main() now calls assert_reproducible_backend() before it generates anything. It reads /api/inference/status, which already publishes speculative_type and parallel_slots through _InferenceRuntimeFields, and fails with a named reason:

this probe needs speculative decoding off and the server reports 'default'.
Load with "speculative_type": "off": a drafted batch replacing sequential decode
is not bit-identical, so the greedy output below would not be reproducible however
many times it is retried.

That is the difference between a mystery divergence and a sentence. #5669 left this leg printing a warning instead of asserting for three months because nothing was watching the check itself, so two new tests in tests/studio/test_smoke_workflows_share_one_script.py watch this one: every leg must carry both pins ahead of the probe, and main() must refuse a server reporting either the wrong drafting mode or more than one slot. 13 passed.

ATTEMPTS = 3 is deliberately left alone; the existing retry contract test needs it. Once all three legs have run green on the pinned config for a couple of weeks it should come down to 1, since over a genuinely deterministic config a retry can only hide an intermittent sampler regression.

What this still catches

  • temperature: 0 no longer mapping to greedy, from a reordered sampler chain or a coerced default
  • _operator_sampling_override or _fill_recommended_sampling_openai overriding an explicit temperature: 0.0
  • a repeat_penalty / presence_penalty default leaking into a greedy request and moving the argmax
  • seed being dropped, or _apply_seeded_llama_request no longer setting cache_prompt = False, since prefix reuse reintroduces the batch-shape difference immediately and fails
  • the server silently re-enabling drafting or extra slots, now as a named failure
  • everything the script already checked: empty replies, dropped history, turn 1 not producing a number, /v1/messages diverging from /v1/chat/completions

What it no longer catches

Byte-equality in the default, speculative-on configuration, which is the one users get. That is deliberate: it is not a property llama.cpp offers, and asserting it produces exactly this flake. Coverage of the drafting path itself belongs in a probe that asserts acceptance rate or quality, not byte-equality.

Two things found next to this, filed as notes rather than fixed here

--spec-default is read as "no drafter" throughout llama_cpp.py. Three branches append it under logger.warning("... loading without speculative decoding.") (:25054, :25063, :25091), and the comment at :25275 states "these models fall through to --spec-default, i.e. no drafter at all". The draft-acceptance lines above say otherwise. Those branches want --spec-type none, the spelling the MLA branch at :25220 already uses. The non-MTP else at :25338 is a separate decision and may well be intended.

The seed reproducibility contract is overstated. _apply_seeded_llama_request's docstring promises "repeated requests stay reproducible" and delivers only cache_prompt = False. With drafting on for every non-MTP GGUF that is not true, and llama.cpp offers no per-request remedy: its server schema keeps the whole speculative block, speculative.type included, under #if 0. Either narrow the docstring or have a fixed seed also select a non-speculative load.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-03T09:29:14.780803Z f3543f0 Manual request
🔒 Security Review ✅ Completed 2026-09-03T09:29:05.853269Z f3543f0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen
danielhanchen force-pushed the ci-gguf-smoke-determinism branch from f349e89 to 4fcaca1 Compare September 3, 2026 08:58
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: f3543f072f

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: f3543f072f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 9d3fcd1 into main Sep 3, 2026
30 of 31 checks passed
@danielhanchen
danielhanchen deleted the ci-gguf-smoke-determinism branch September 3, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant