Repository navigation
serve: --precise — a follow-up turn comes out bitwise identical to a cold run - #504
Conversation
…cold run A follow-up turn in the same conversation is not bit-identical to a cold run of that conversation: it continues from the KV cache and prefills only its new user message, where a cold run prefills the whole conversation in 512-token ubatches, and HRX takes a different kernel family for a different token count. Qwen3.8-27B prefills a cold conversation in the WMMA tile kernels (T >= 128, multiples of 128 or 256) and a 28-token follow-up in the generic post-ops matmul (16 < T < 128), with a different activation quantisation, a different split-K and a different combine tree; the last bits differ and a near-tie flips. Measured on 2026-10-22 (engine main, one fresh serve per arm, temperature 0, cache_prompt true on the follow-up, 10 two-turn chats per model; a follow-up against a cold run of the same conversation): - Qwen3.8-27B: 0/10 chats differ with --precise on. Prompt tokens per chat are identical between the arms (88 vs 88, 104 vs 104), i.e. the follow-up really does take the cold path. - Qwen3-4B: 1/10 differs, at token 26 with a 0.0385-nat gap at that position, both arms having prefilled the same tokens - a determinism question about that path, not about batch size, and a separate follow-up. The flag rewrites cache_prompt to false before the request is forwarded, so every request re-prefills its whole conversation and takes exactly the path a cold run takes. ONEBIT_PRECISE=1 does the same from the environment. Cost, measured on the 27B as the follow-up's own prompt time: 672 ms -> 4785 ms after a ~1.6k-token conversation (1599 tokens re-prefilled at 334 tok/s) and 676 ms -> 12348 ms after ~5.4k tokens (5464 tokens at 443 tok/s). Off by default; a single-turn request is unchanged either way. This is exactness by construction, not batch invariance: a follow-up is identical to a cold run because it is one. Batch invariance (the same reduction order for T = 1, 2-8 and prefill) would keep the cheap KV-cache prefill and is written up separately - it means ~10 kernel families with one activation quantisation, split-K and combine tree, weeks of work and a prefill-throughput risk, because the WMMA fragments are where prefill's throughput comes from. docs/serve.md documents the flag, the numbers and the alternative. Co-Authored-By: Claude Opus 5 <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
…ishes its Q8_1 alternate only when a consumer reads it (llama.cpp#511; engine#3380) (#3490) The split-FA decode matcher (match_flash_attention_decode_split_next_q8_dispatch) runs a loom kernel that writes the attention output AND its Q8_1 x4 packing in one launch so the next projection need not quantize the activation, and it called append_alternate_value unconditionally. A graph that ends at the attention output -- exactly the qwen_flash_attention row -- therefore planned a copy nothing can read; the row had been parked as the suite's last known-fail with that reason (engine#3380). llama.cpp#511 applies the existing graph-only consumer qualification (dispatch-q8-publication.h's common_for_each_q8_consumer through full ordered reshape aliases + common_q8_consumer_is_qualified_projection, the #449/#504 machinery) to that publication. Kernel selection, the q8 transient and bindings[9] are untouched -- only the alternate metadata is conditional. The qwen_flash_attention row becomes a plan-only host case with the known-fail label gone; the seven test-hrx-ops fa_decode_split.* rows assert the no-alternate plan and keep asserting the q8 transient binding. Publication-when-a-consumer-exists stays pinned by qwen_decode_split_flash_attention.*.masked.head96.value64 and qwen_decode_attention_output_next_q8.*. Device evidence (strixhalo gfx1151, add-on, package runtime libs, root, one box-hold both ticket): before (d2369fe2): hrx-ops-test 410 passed, 0 failed, 1 known-fail (qwen_flash_attention) after (#511) : hrx-ops-test 411 passed, 0 failed, 0 known-fail, 411 total; the single row PASSes; test-hrx-ops 295 passed, 0 failed; the 7 publish rows pass; no reset/fault in the window Host control (no device): pre-fix source + the new host row FAILs (find_alternate_value(...) == nullptr, and the fa_decode_split rows FAIL the no-alternate assertion); with the fix all 5 rows pass, host hrx-ops-test 18/0, test-hrx-ops 2/0, check_stale_expectations 488/488 selectable. registry/architectures.json is regenerated by scripts/registry-regen.sh (llama.cpp source sha). Co-authored-by: bong-water-water-bong <[email protected]>
The problem
A follow-up turn in the same conversation is not bit-identical to a cold run of that conversation. The follow-up
continues from the KV cache and prefills only the new tokens, so those tokens go through a different batch than
the cold prefill does — and HRX picks a different kernel family for a different token count, with a different
reduction order over the weights. Near-ties at the top of the distribution then flip and the answer takes another
branch.
Measured with the engine's own stack (
precise.py, 10 two-turn chats, greedy,cache_prompttrue on thefollow-up, one fresh server per model):
With
--preciseon, the follow-up re-prefills exactly the tokens a cold run does (per chat the prompt tokencount is identical, e.g. 88 vs 88):
The 4B's single remaining difference cannot be explained by batch size any more (both arms prefilled the same
tokens), so the open question there is whether that path is deterministic at all - a follow-up experiment, not a
gap in this change.
The kernel families involved, from the dispatch registrations:
T == 1takes the q8-activation decode kernels(
token1_requires_q8_activation),T <= 5thelowtoken_dotones (lowtoken_contraction, anduse_split_direct_dotwhen K splits),T = 2..8our private kqt kernels,5 < T <= 16another family, andT >= 128(multiples of 128/256) the WMMA prefill tiles. A ~20-token follow-up lands in the16 < T < 128band while a 512-token cold ubatch lands in the tile band — different code, so different rounding.
The fix
--precise(orONEBIT_PRECISE=1) makes every request re-prefill its whole conversation: serve rewritescache_promptto false before forwarding, so the follow-up takes exactly the path a cold run takes. Off bydefault; nothing changes for a single-turn request; documented in
docs/serve.md.Cost, measured on the 27B at 2k and 7k conversation tokens (turn 2's own
prompt_ms, 75 W cap):What it is not
It is not batch invariance. Somebody who wants follow-ups identical to cold runs and the cheap KV-cache prefill
needs the kernels to reduce in the same order for every T. The kernel families differ by token count (T=1 decode,
T<=5 lowtoken, T=2..8 our kqt, 5<T<=16, 16<T<128 generic post-ops, T>=128 WMMA tiles), so a ~20-token follow-up
and a 512-token cold ubatch run different code with different activation quantisation, split-K and combine trees.
A cheap middle step exists - pad every prefill chunk to the tile size so both take one kernel with one split-K
(~0.65 s per short turn instead of 4.8-12.3 s) - and full invariance is weeks across ~10 kernel families with a
-15..-45 % prefill risk, because the WMMA fragments are where prefill's throughput comes from. Both are written
up in
~/briefs/TPRECISE-REPORT.md.Checks
--preciseon, cold run vs follow-up: 27B 0/10, 4B 1/10(the 4B one at a 0.0385-nat tie, both arms having prefilled identical tokens - a determinism question for the
4B path, filed for a follow-up).
scripts/hw-gate.shfull on the binaries this engine ships (build-warm/hrx/llama/bin), seven models, with aprivate snapshot of the kld store: PASS — ops 663/663, and kat + placement + kld PASS on qwen3.8-27b
(kld 0.002217), zaya1-8b (0.007729), qwen3-coder-30b-a3b (0.000912), qwen3-4b-iq4xs, qwen3-0.6b and its
-kq8 / -kvq8 variants. 0 amdgpu ring timeouts.
gpu-holdand every build through a claim (build.sh/build-guard.shnow wrapgpu-hold -l "build <dir>" -t 30 -- ~/lb/thermal-run.sh), and every script that starts a backend exportsIREE_HAL_AMDGPU_LIBHSA_PATH— without it the HRX backend silently registers no device.🤖 Generated with Claude Code