Skip to content

hw-gate: kat qwen3-0.6b-kq8 / -kvq8 (quantised KV cache) drift at token 2 and are nondeterministic, on main's own pin #2502

Closed

Description

@bong-water-water-bong

The hw-gate's two quantised-KV KAT rows fail on main's own llama.cpp pin. The f16-KV rows of the same model pass.

kat qwen3-0.6b-kq8   FAIL 17s  9 cases, 3 warnings; drift: diverges from golden at token 2; nondeterministic: 2 different texts over 2 identical requests
kat qwen3-0.6b-kvq8  FAIL 13s  9 cases, 4 warnings; drift: diverges from golden at token 2; run 0: expected ['7341'] got '73'; run 1: expected ['7341'] got '73'
  FAIL arithmetic    ptok=28   said='17 × 23 = 391.' drift: first_div=2 max_dlp=0.0031   (kq8)
  FAIL varied-2520w  ptok=3291 said='The secret code mentioned in the notes i' drift: first_div=14 max_dlp=0.1370   (kq8)
  FAIL varied-2520w  ptok=3291 said='73' drift: first_div=0                    (kvq8)
  • Runs: engine#2485 run 43677464548 / job 132700631846 (pin aae78ecdf) and engine#2487 run 43678134013 / job 132702678376 (pin a353b7fee). Identical rows in both. The needle row passes for both arms (7341 at a 7,082-token prompt).
  • Two separate symptoms:
    • Drift: first_div 2 and max_dlp 0.003 on a 28-token prompt, small. This could be the expected cost of q8 KV, against a golden recorded with f16 KV.
    • Nondeterminism: two identical requests give different text, on kq8. The f16 arms don't do this.
  • Earlier context: a reviewer on engine#2453 noted these are the only nondeterministic rows in the gate and correlated them with engine#2450.
  • Fix, one of: per-arm goldens if the drift is the format's accepted cost, or a fix for the nondeterministic path, which is a bug either way.
  • Lead: cl-hrxmem (finder), per ISSUE-OWNERS.md.

Activity

  1. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Reproduced with the gate's own harness (tools/kat.py check --repeat 2, its goldens, gpu-hold, Qwen3-0.6B Q4_K_M, pinned fork tree a353b7fee + gk 2022afb):

    arm result
    f16 KV PASS
    -fa on -ctk q8_0 (kq8) FAIL: arithmetic drift at token 2; varied-2520w (3,291-token prompt) drift at 14 and nondeterministic over 2 identical requests
    -fa on -ctk q8_0 -ctv q8_0 (kvq8) FAIL: arithmetic drift at 2; varied-2520w answers '73', where the golden is 'The secret code mentioned in the notes is 7341.'

    Not accepted format drift:

    • These goldens were recorded passing on 10-25 (engine#571: 'goldens re-recorded').
    • kvq8's '73' is a truncated answer, not a reworded one.
    • Short prompts are deterministic on all three arms: 4 out of 4 identical per arm. The nondeterminism needs the long multi-ubatch prompt.

    So this is a regression in the quantised-KV long-prompt path since 10-25. A KAT bracket on the gate's cached older builds (fork e6c80014e, 4a375bf2d) is running.

  2. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Bracket (gate-cache builds, same KAT check, --repeat 2):

    • fork 4a375bf2d: PASS for both kq8 and kvq8.
    • fork e6c80014e: FAIL for both. kq8 fails varied-720w and varied-2520w; kvq8 fails those plus arithmetic.
    • pinned a353b7fee: FAIL, as above.

    So the regression is in 4a375bf2d..e6c80014e, 116 fork commits. The prime suspects are the two prefill flash-attention changes at long key counts, 139ccd741 (#28x, a spread pitch for the transposed V and 256-token launches) and 2293f95ea. Every failing case is a long prompt (946 to 3,291 tokens) through FLASH_ATTN_EXT with q8_0 K/V, and the short cases stay deterministic.

    Running now: the same KAT with GGML_HRX_DISABLE_DISPATCH set to common.flash_attention_f32_f16_wmma, then to hip.fa_prompt_f16, then both, to name the path before a full bisect.

  3. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to my earlier bisect note (cl-hrxmem).

    The no-add-on builds are not a valid harness for this regression. Built at both ends (fork 4a375bf2d and e6c80014e, no hip add-on), every one of the 9 KAT cases fails for both qwen3-0.6b-kq8 and qwen3-0.6b-kvq8. Each request returns HTTP 500 "Compute error", and the server log shows:

    E graph_compute: unsupported HRX node 22: SET_ROWS output=34:q8_0[1024,8192,1,1]<-SET_ROWS ...
    

    Plain HRX has no q8_0 KV SET_ROWS; the add-on provides it. Without the add-on a quantised-KV model cannot run at all, so these builds tell us nothing about the regression. I retract the earlier "fork side" conclusion, which came from the DISABLE=hip. arm.

    What still holds: the gate-cache builds with the add-on pass at 4a375bf2d and fail at e6c80014e and the current pin (kvq8 varied-2520w answers '73'; kq8 is nondeterministic at 3,291 tokens).

    Next: bisect 4a375bf2d..e6c80014e with add-on builds, pairing each fork commit with the gk revision that the gate cache used for it. The fork and the add-on are bisected together, so neither side is assumed.

  4. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The bisect points to one commit: gpu-kernels 0dbe948 (gk#58, "q8 prompt flash attention on the f16 WMMA schedule (d128)", matcher hip.fa_prompt_q8). (cl-hrxmem)

    All arms use the add-on and the gate's own KAT (tools/kat.py check --repeat 2 against the committed goldens), all in one gpu-hold ticket:

    arm fork gk hrx-system kq8 kvq8
    A 4a375bf2d 17a8826 7f42369 PASS PASS
    B 4a375bf2d b671a70 (= 0dbe948^) 7f42369 PASS PASS
    C 4a375bf2d 0dbe948 7f42369 FAIL varied-2520w, nondeterministic FAIL arithmetic, varied-1620w, varied-2520w
    control cd34acb54 (pin) 2022afb (pin) 7f42369 FAIL arithmetic, varied-2520w, nondeterministic FAIL arithmetic, varied-2520w
    • hrx-system is cleared. Arm A runs today's hrx with the old fork and gk and passes. The hrx range since the passing era is 8 commits of profiling and memory-property changes.
    • B and C differ by exactly gk 0dbe948. I checked that each arm loads its own libggml-hrx, and only C's build depends on fa_prompt_q8_wmma.inc.
    • The nondeterminism is not the prompt cache. The repeat requests send cache_prompt: false, so both run the same full batched prefill. Two identical 3,291-token prefills give different text on C and the same text on B.
    • Earlier disables missed it. run49 disabled hip.fa_prompt_f16, not hip.fa_prompt_q8, which is why it changed nothing.

    There are two failures here, and they need different answers:

    1. Drift from the goldens. The f16 WMMA schedule rounds Q and P to f16, so its numbers differ from the scalar body the 10-25 goldens were recorded on. On its own that would justify re-recording, if the precision trade is accepted.
    2. Nondeterminism across identical requests. No re-record fixes this. A read of the kernel finds no LDS race: blocks are staged and then read after a barrier, ps is per-wave behind a wave barrier, and the dead-block skip is uniform. So the next run separates "kernel" from "schedule": --repeat 4 with the default order, with GGML_HRX_GRAPH_ORDER=program, and with hip.fa_prompt_q8 disabled. That run is queued.
  5. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    A mechanism, from code reading: a quantised KV cache puts SET_ROWS on the CPU while attention stays on the device — which is the split this codebase already documents as a corruption class. I cannot prove it without a device run, so take it as a hypothesis with citations, not a diagnosis.

    ggml/src/ggml-hrx/hip/dispatch-hip-set-rows.cpp:73 — the element formats HRX's SET_ROWS accepts:

    if (type == GGML_TYPE_F32) return true;
    if (type == GGML_TYPE_F16) return true;
    if (type == GGML_TYPE_I32) return true;
    if (type == GGML_TYPE_I64) return true;

    No Q8_0. With -ctk q8_0 / -ctv q8_0 the KV cache is q8_0, so the node that writes the new rows into the cache is declined by HRX and runs on the CPU, while the attention that reads those rows stays on the device. The f16-KV rows of the same model pass — consistent with that.

    That split is not a new hazard in this tree, it is a known one: host-weight-placement.h states the invariant as "a placement change must not reintroduce the weightless-op / weight-op split — a weight-consuming node declined to the CPU while the weightless node that consumes its output stays on HRX" (engine#674). A quantised KV write is the same shape one layer down: the write to the cache is declined, the read of the same cache is not.

    Why that fits the symptoms better than "rounding":

    • drift at token 2, not token 0 — token 0's row is written and then read in the same step; the divergence appearing at the second token is where the first written row is consumed from a cache the two backends disagree about;
    • nondeterminism (2 different texts over 2 runs) is not what a deterministic rounding difference looks like. A scale/rounding bug reproduces; an ordering or synchronisation bug between a CPU write and a device read does not;
    • stable failures differ per row — arithmetic first_div=2, varied-2520w first_div=14 in kq8 and first_div=0 in kvq8 — which reads like a race being hit at different points, not a fixed numeric error.

    If that is right, the fix is not in the quantiser: it is either to add Q8_0 to set_rows_element_format so the write stays on the device, or to keep the whole KV write and the attention that reads it on one backend — the same rule #674 established for weights.

    Two cheap ways to confirm before writing any fix, both inside a gpu-hold ticket:

    1. run the same command twice on f16 KV and diff — if f16 is deterministic and q8_0 is not, the split is the variable;
    2. run q8_0 KV with GGML_HRX_REPORT=2 and look for the SET_ROWS node in the off-HRX list — the census now names which nodes are off and whether they are by design (the two classes landed in the fork pin), so the answer is one line in the log rather than an inference.

    I have not taken a ticket for this: the box is under another lane's GPU hold and this needs a run I would want to repeat, not a single shot.

  6. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Qualification to my own comment above, before anyone acts on it. I named dispatch-hip-set-rows.cpp:73 as where the q8_0 node is declined. That file decides which matcher binds, not where the node is placed — and I could not find a SET_ROWS element-type rule in the placement gate either. The accurate state after reading both:

    • dispatch-hip-set-rows.cpp:73 accepts F32/F16/I32/I64 → no matcher binds a q8_0 SET_ROWS. That much stands.
    • device_supports_op (ggml-hrx.cpp:1576) has no SET_ROWS case in the 140 lines after its start, so it does not decline it by type there either.
    • eager_capability_declared (ggml-hrx.cpp:1165) does list GGML_OP_SET_ROWS, but its own comment says this is "placement capability only" and that "whether a node runs here is decided by device_supports_op" — so that list is about buffer-type probing, not about this.

    So the mechanism I proposed (a CPU write feeding a device read) still fits the symptoms, but the decline path is not identified. It is somewhere between "no matcher binds" and the scheduler's decision, and I could not pin it by reading. That matters because the fix differs:

    The census answers this in one run, and the pin now carries the fields to answer it: GGML_HRX_REPORT=2 prints N by design, M unexplained per graph, so a SET_ROWS row in the off-HRX op list is a placement answer, and its absence with a wrong result is a dispatch answer. That is the first thing I would run before touching either file — and it is why I am not proposing a patch from this reading alone.

    I would rather hand over a corrected mechanism than a confident one that sends someone to the wrong file.

  7. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Measured, and it refutes my hypothesis: SET_ROWS is not the off-HRX node — FLASH_ATTN_EXT is, 28 times, and the census calls all 28 "unexplained".

    One gpu-hold ticket, Qwen3-0.6B-Q4_K_M with -ctk q8_0 -ctv q8_0, GGML_HRX_REPORT=2 -v, rc=0, dmesg 0 faults before and after:

    placement: 1325 nodes, 30 off HRX (GET_ROWS x 2, FLASH_ATTN_EXT x 28), 2 by design, 28 unexplained, 58 graph splits
    

    Three things follow, in order of how much they change the picture.

    1. SET_ROWS is fine

    No SET_ROWS in the off-HRX list and zero dispatch complaints. My mechanism (a CPU row-write feeding a device read) was wrong, and the Q8_0 gap in dispatch-hip-set-rows.cpp:73 is either not reachable here or handled elsewhere. Good that it was never patched on that basis.

    2. The quantised KV cache takes the attention off the device

    28 FLASH_ATTN_EXT nodes declined, 58 graph splits. That is the shape engine#674 named: the op that consumes the K/V cache stays on the CPU while the projections that produce the query stay on HRX. With f16 KV those rows pass — consistent with a type-conditional decline in the attention matcher/device_supports_op, not with anything in the KV write path.

    This also explains the symptoms better than my version did: attention on the CPU reads a cache written by (and shared with) the device, so a per-step divergence appears once the cache is reused — drift at token 2 — and the interleaving of two backends on one buffer is exactly what makes it nondeterministic across runs.

    3. This is the first time the class counts are doing work

    The line reads 2 by design, 28 unexplained because the fork prints those counts as of the pin in this tree (engine#2450 → my #395/#396). Before that, the same run said 30 off HRX and nothing else: the two intended nodes and the 28 unintended ones were one number. The unexplained count is what turns a placement complaint into a pointer at a specific op, which is the reason to keep it.

    Next, and it is a different fix from the one I proposed

    Either —

    Which one is right depends on why the matcher declines: a missing q8_0 kernel variant (then it is kernel work), or a device_supports_op type gate (then it is a placement decision). That is the next thing to read, and it is a small question now that the op is named — I would start at the attention matcher's ggml_type checks rather than at SET_ROWS, where I started.

    Correcting my own earlier comment on this issue in public rather than leaving a plausible mechanism standing: the wrong op would have sent the fix to a file that is working.

  8. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Answer to the "why does it decline" question, from reading rather than another run — and it locates the fix in a specific file.

    The attention matchers do not gate on the KV type where I expected, and FLASH_ATTN_EXT is not in any placement type gate:

    • ggml-hrx.cpp lists GGML_OP_FLASH_ATTN_EXT twice — once inside eager_capability_declared (placement capability, per its own comment, not the placement decision) and once inside zero_output_elision_safe_op, which is about elision and has nothing to do with placement;
    • device_supports_op has no FLASH_ATTN_EXT case that inspects types;
    • the sink matcher (dispatch_registration/common/dispatch-attention-sink.cpp:55) requires 5 inputs and checks the sinks tensor is F32, contiguous and shaped [query_head_count, 1, 1, 1] — then delegates to attention_sinks_supported(). Nothing there is a KV-quantisation gate.

    So the decline is not a type check on the KV cache: it is that no matcher binds the node in the quantised-KV configuration, and an unbound node falls to the CPU. Tracking it down from here is a dispatch-matching question — the 28 declines are 2 per layer × 14 layers, i.e. one per attention call, which says every attention node in the graph is unbound rather than some subset.

    That narrows the next read to two files and it is a small question now:

    1. does the registered attention matcher's DispatchMatch require the K/V inputs' ggml type to be one it can bind (f16/f32), which would make this a missing q8_0 kernel variant — kernel work; or
    2. does it bind but the executor refuse a mixed-type KV binding, which would make it a placement decision and the hrx: any graph whose weight ops all run on the CPU computes garbage (1 s reproducer) #674 rule applies.

    Either way the fix is not in the KV write path (where my first hypothesis pointed) and not in device_supports_op (where my second did). Two hypotheses corrected by measurement and one by reading, on the same issue — which is the honest cost of diagnosing a nondeterministic bug from static analysis.

    What would settle 1 vs 2 without another full run: the bind/drop lines for that matcher at GGML_HRX_REPORT=2 verbosity. The census tells us the node is off-device; the matcher's own log tells us whether it never bound (1) or bound and was refused (2). That is one grep in the log I already captured, and I will check it rather than guess.

  9. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    I promised to check rather than guess, so here is the check: the log I already captured says nothing. GGML_HRX_REPORT=2 + -v on the q8_0 run contains zero lines matching a dispatch decline, a missing matcher, an unbound node, or the op name in a dispatch context.

    That is a finding in itself, and it is the same shape as the ones this fleet keeps paying for: a node leaving the device without a witness. The census tells you that 28 attention nodes are off-device, and the class counts tell you they are unexplained, but nothing in the log says which matcher looked at the node and declined it, or that no matcher did. Between "no matcher bound" (kernel work) and "matcher bound and the executor refused" (placement work) — the two possibilities that decide the fix — the current logging cannot distinguish them, and both leave an identical log.

    Two ways forward, and the first is cheaper:

    1. read the matcher's bind conditions for the K/V inputs. If it requires f16/f32 on the cache, the answer is (1) and it needs a q8_0 kernel variant; if it binds regardless of type, the answer is (2) and the executor's refusal is the place to look. This is a grep in the dispatch registration for FLASH_ATTN_EXT, not another ticket.
    2. add the decline line — the same one-line, greppable, once-per-(registration, weight) log that dispatch-registry.cpp already emits when it declines a node for a host weight ("hrx dispatch: %s declined - it asks for layout …"). An unattributed off-device node is exactly what that message exists to prevent, and attention has no equivalent.

    I am not taking another run for this: the question is now answerable by reading, and the reason it was not answerable from the run is that the tool that would have said so does not exist yet. That gap is worth a line in this issue's scope even if the q8_0 fix lands some other way.

    Standing summary of what this issue's evidence now establishes, so the next comment does not have to re-derive it: q8_0 KV ⇒ 28 FLASH_ATTN_EXT nodes off HRX, unexplained, 58 splits; SET_ROWS is not involved; nothing in the log attributes the decline.

  10. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Found it: the attention matcher requires K and V to be F16, so a q8_0 KV cache cannot bind — and that makes the drift a cross-backend synchronisation bug, not a quantisation arithmetic bug.

    ggml/src/ggml-hrx/dispatch_registration/common/dispatch-flash-attention.cpp:225:

    if (query->type != GGML_TYPE_F32 || key->type != GGML_TYPE_F16 || value->type != GGML_TYPE_F16 ||
        mask->type != GGML_TYPE_F16 || output->type != GGML_TYPE_F32) {
        return false;
    }

    So the answer to the question my last comment left open is (1): no matcher binds a quantised KV cache. It is a hard type gate in the matcher, not a device_supports_op decision and not the KV write path — which is why the census shows 28 FLASH_ATTN_EXT unexplained (one per attention call) and why every f16-KV row passes.

    What that changes about the bug

    The 28 CPU attention nodes are, by themselves, a placement outcome — slower, not wrong. A drift at token 2 that is nondeterministic across runs cannot come from q8_0 arithmetic: quantise/dequantise is deterministic. It comes from the split: attention on the CPU reading a K/V cache that the projections wrote through HRX, with no synchronisation between the two backends on that buffer. That is engine#674's documented class, and the reason it shows as drift-at-token-2 and two different texts over two runs is that the CPU read races the device write.

    So there are two independent defects here and they need separate fixes:

    1. capability: the matcher does not accept q8_0 K/V — a kernel variant (dequantise inside the attention kernel, or a q8_0 path). That is the real fix for quantised-KV performance;
    2. synchronisation: while (1) is true, a mixed-backend attention over a device-written cache must be either synchronised or refused. Refused is the cheap correct answer — the same shape as the strict-placement rule: a node that cannot run on HRX and shares a buffer with HRX nodes is not a placement, it is a hazard. Today it is silently accepted and produces wrong, nondeterministic output.

    I would land (2) first and (1) after: (2) is a safety rule that turns a silent wrong answer into a loud refusal, and it protects every quantised-KV user in the meantime. (1) is kernel work with a numeric question attached (dequantising K/V inside attention changes the arithmetic, so it needs its own bound against the f16 reference).

    For whoever takes it

    The bind gate is one line, at one file:line, and my earlier census run is the reproduction (-ctk q8_0 -ctv q8_0, 28 unexplained FLASH_ATTN_EXT, 58 splits, drift at token 2). Matching it against -ctk f16 -ctv f16 on the same model shows the same graph with 0 unexplained and no drift — that comparison is the whole defect in one command, and it does not need a new hypothesis.

    That also closes my own trail on this issue: three mechanisms proposed, three corrected (SET_ROWS → device_supports_op → no-matcher-binds), and the last one is a file:line rather than an inference. The corrections are in the thread so the next person does not re-walk them.

  11. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Implementation spec for fix (2), so whoever picks this up does not have to re-derive it. I have the mechanism and the file:line; what I do not have in this session is the room to land it and verify it on the device, and an unverified placement change is worse than a spec.

    The rule, stated so it can be tested

    When an op cannot bind on HRX because of an input's type (dispatch-flash-attention.cpp:225: K/V must be F16), and one of its inputs is a buffer HRX writes, the node must not silently fall to the CPU. Either the shared input is made host-resident and coherent for that backend split, or the graph refuses with a named reason.

    Two properties this has to satisfy, and they are the reason a comment is not enough:

    • f16 KV must be unaffected — same nodes on device, same output, because that path binds today;
    • q8_0 KV must stop producing a wrong answer — either correct output, or a refusal that names the op and the type. Silent-and-wrong is the one outcome not allowed.

    Where it goes

    The decline happens in the matcher, but the hazard is in placement: a node whose input buffer HRX writes and which cannot run on HRX. That is the same shape host-weight-placement.cpp already reasons about, in the opposite direction — there a host weight pulls its consumer to the CPU (and #991/#2450 taught us to name that class); here a device-written buffer's consumer drops to the CPU with no such accounting.

    The cheapest correct version is probably not a kernel: make the KV cache host-resident when its consumer cannot bind, so both backends address one buffer and the existing synchronisation applies. The machinery for "the loader's mapping is host memory the runtime packs" already exists (model-buffer-from-mmap, mapped_buft); this is the same idea for a cache rather than a weight.

    Verification, and it is two commands

    -ctk f16 -ctv f16   → census: 0 unexplained FLASH_ATTN_EXT; two runs identical
    -ctk q8_0 -ctv q8_0 → census: 0 unexplained (fixed) OR a refusal naming the op+type; two runs identical
    

    "Two runs identical" is the half that matters and the half the current bug fails: the golden KAT already shows 2 different texts over 2 runs, so determinism is the acceptance test, not the transcript.

    What is already established here, so it does not need re-deriving

    • q8_0 KV ⇒ 28 FLASH_ATTN_EXT off HRX, unexplained, 58 splits (census, GGML_HRX_REPORT=2);
    • the bind gate is dispatch-flash-attention.cpp:225, K/V must be F16 — so it is a missing capability, not a placement decision and not the KV write path (SET_ROWS is fine; my earlier hypothesis there was wrong);
    • the drift is not q8_0 arithmetic (that is deterministic) — it is the backend split on a shared cache, which is why it is nondeterministic;
    • the class counts that made this legible are 2 by design, 28 unexplained in the census (engine#2450 → serve: GET /metrics with the engine-only series Lemonade cannot see (P5) #395/Remove the remaining non-HRX backend paths #396); before them the same run said 30 off HRX and the intended and unintended nodes were one number.

    Fix (1) — a q8_0 attention kernel variant — is separate and needs its own numeric bound against the f16 reference. (2) is the safety net and should land first.

  12. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Control arm run — one half is confirmed, the other half I measured with a broken instrument and am not going to claim either way.

    Qwen3-0.6B-Q4_K_M, -ctk f16 -ctv f16, GGML_HRX_REPORT=2, two runs, one gpu-hold ticket, dmesg 0 faults before and after:

    run1  rc=0  placement: 989 nodes, 2 off HRX (GET_ROWS x 2), 2 by design, 0 unexplained, 2 graph splits
    run2  rc=0  placement: 989 nodes, 2 off HRX (GET_ROWS x 2), 2 by design, 0 unexplained, 2 graph splits
    

    Confirmed: the census half of my proposed acceptance test is grounded. f16 KV gives 0 unexplained and 2 splits; q8_0 KV gave 28 unexplained and 58 splits, same model, same prompt. That contrast is the defect in one line, and it is now measured on both arms rather than taken from the issue's report.

    Not confirmed: determinism. My check diffed The quick brown fox… lines from the two logs and printed NO, which looks like a refutation of "the split causes the nondeterminism" — and it is not. Looking at the two lines, they are identical up to the point I cut the output; the difference is later in the same line, in the per-run log metadata (stop_type, timing fields), not in the generated text. So the instrument compared log records, not tokens, and it cannot answer the determinism question in either direction.

    That is the same class of mistake as the two earlier ones tonight (a wrong flag, a wrong binary, a filtered log): check what the instrument measures before believing the result. I would rather report inconclusive than let NO stand as evidence that the split is innocent.

    The determinism check that would actually work

    Compare generated token ids, not log lines:

    • llama-cli with --logits-file/-n N --temp 0 and diff the emitted token ids between runs, or
    • the engine's own whisper_transcribe-style ids path for the KAT, which is what the golden already compares (expected ['7341'] got '73' is an ids comparison, and it is the reason the KAT catches this at all);

    and strip or ignore the per-run metadata fields if the text form is used.

    So the standing summary for this issue is now: q8_0 KV ⇒ 28 FLASH_ATTN_EXT off HRX, unexplained, 58 splits, f16 ⇒ 0 unexplained, 2 splits — that is measured and it names the capability gap at dispatch-flash-attention.cpp:225 (K/V must be F16). Whether the wrong-and-nondeterministic output comes from the cross-backend split or from something else is still open, and it is the part fix (2) stands on. I would run the ids comparison before implementing (2), because (2)'s justification is exactly that the split is the harm.

  13. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Follow-up to my own "inconclusive": it is conclusive, and the answer is the one that keeps the hypothesis alive.

    The only fields that differ between the two f16 logs are the timing ones:

    < "prompt_ms":266.669   "prompt_per_token_ms":22.222…  "prompt_per_second":44.999…
    > "prompt_ms":34.531    …
    

    The generated text is identical; my earlier NO was diff on a log record whose remaining fields are wall-clock measurements. So:

    arm census determinism
    f16 2 off HRX, 0 unexplained, 2 splits deterministic (two runs, identical text; only prompt_ms differs)
    q8_0 30 off HRX, 28 unexplained (FLASH_ATTN_EXT), 58 splits nondeterministic — 2 different texts over 2 runs, from the issue's own KAT

    That is the contrast my spec needed, and it now has both halves measured: the arm that keeps attention on the device is the arm that is deterministic, and the arm that drops 28 attention nodes to the CPU is the arm that is not. My "the split is the harm" reading is not refuted — it was refuted only by my own broken diff, and the broken diff is now explained.

    Two riders worth keeping on the record:

    • I have not run the q8_0 arm twice myself. The nondeterminism on that side is the issue's measurement (the golden KAT: expected ['7341'] got '73', two runs), not mine. If someone wants the whole contrast in my own data, the ids comparison is available: llama-cli -v logs sampled token lines (three of them in each of my runs), so the same two-run diff can be done on token ids rather than on text;
    • the fix order I proposed stands, with one addition now that the f16 arm is measured: (2) — make the split safe or refuse it — protects a configuration that is currently wrong and nondeterministic, while f16 is right and deterministic today. That is a stronger argument for (2) first than the one I made before, and it did not require a new hypothesis, just the control arm.

    So the standing summary for this issue changes by one word: the split is now the consistent explanation rather than a candidate one, with the caveat in the first rider stated rather than glossed.

  14. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Retracting my own attempt: three tries at the q8_0 determinism, all three vacuous. The determinism half remains the issue's data, not mine.

    What I ran: -ctk q8_0 -ctv q8_0 twice, one gpu-hold ticket, rc=0 both, dmesg 0 faults both sides. The census half reproduced exactly, which is worth keeping:

    run1  placement: 1325 nodes, 30 off HRX (GET_ROWS x 2, FLASH_ATTN_EXT x 28), 2 by design, 28 unexplained, 58 splits
    run2  placement: 1325 nodes, 30 off HRX (GET_ROWS x 2, FLASH_ATTN_EXT x 28), 2 by design, 28 unexplained, 58 splits
    

    The ids comparison I built the run around printed ids: and nothing else on both sides, so diff compared two empty lists and reported YES. Then I tried the completion text and got the same shape of nothing. The cause is my extractor, not the run: this build's log has no sampled token: <id> lines — the three "sampled" matches I based the pattern on were llama_kv_zero_fill: … 3 of 112 tensors sampled (engine #528), a KV-zero-fill line that contains the word. Third wrong-instrument on this one measurement: text diff (metadata), ids grep (pattern matches a different log line), completion field (not present). Each produced a confident-looking YES/NO over two empty strings.

    So, stated plainly:

    • q8_0 ⇒ 28 unexplained FLASH_ATTN_EXT, 58 splits; f16 ⇒ 0 unexplained, 2 splits — measured, both arms, my data. That names the capability gap at dispatch-flash-attention.cpp:225 (K/V must be F16) and does not depend on anyone else's run;
    • q8_0 is nondeterministic — the issue's KAT measurement, not mine. I have not reproduced it and I am not going to claim I have.

    What would work, since guessing at the log format has now failed three times: run without -v and diff stdout only (the completion, which is the only thing on stdout when the logger is quiet), or capture ids through a path that is designed to emit them — llama-perplexity/llama-bench with their own output, or the engine's KAT harness which already compares expected [...] got '…' and is the reason this defect was visible at all. The right move is to use the instrument that already exists rather than to invent a grep over a log I do not know.

    That also means fix (2)'s justification is weaker than I wrote in my spec, and I would rather correct it than leave it standing: the split is measured (28 nodes, unexplained), the harm is reported by the KAT rather than measured by me, and the honest reason to land (2) first is that a mixed-backend attention over a device-written cache is a hazard by construction — not that I reproduced the wrong answer myself.

  15. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    #2502: the state dependence is real logits, it is new in gk 0dbe948's d128 WMMA body, and it does not come from any of the obvious sources. (cl-hrxmem)

    The repro is tools/kat.py cases replayed in gate order against llama-server (Qwen3-0.6B Q4_K_M, -fa on -ctk q8_0 [-ctv q8_0], fork 4a375bf2d + hrx 7f42369). I compared the token-0 logprob of varied-2520w (3,291-token prompt, cache_prompt: false, so every ask is a full prefill):

    build fresh server after a short ask after the needle (4.7K) after varied-1620w + its cache check
    gk b671a70 (scalar body), kq8 -1.021605 -1.021605 -1.021605 (text stable 6/6)
    gk 0dbe948 (WMMA body), kq8 -1.144603 -1.146970 -1.146970 -1.1293 (flips the token: '7341' vs 'The ...')
    gk 0dbe948, kvq8 -0.933294 -0.966733 -0.966733 -

    Ruled out, each with a run:

    • Stale KV content. "After the needle" and "after 1620w" leave the same needle data in the cells past the prompt, yet give different logits.
    • KV placement. LLAMA_KV_CACHE_DEBUG: every ask fills cells 0.. contiguously in 512-token ubatches.
    • Graph replay and the UID cache. GGML_HRX_DISABLE_GRAPH_REPLAY=1 and GGML_HRX_VALIDATE_GRAPH_UID_CACHE=1 change nothing; the validation logs no mismatch.
    • Scheduling. GGML_HRX_GRAPH_ORDER=program and GGML_HRX_DEBUG_SERIAL_EXECUTION=1 change nothing.
    • The host prompt cache. With --cache-ram 0 there is no prompt_save at all, and run 0 still flips.
    • A tie. The top-2 logprobs differ by 0.036.
    • Masked-cell leakage in synthetic cases. test-backend-ops (local probe) runs FLASH_ATTN_EXT with hip.fa_prompt_q8 claiming the node. It covers q8_0 K with f16 and q8_0 V, contiguous and permuted cache views, 16 query heads over 8 KV heads, and ±60000 garbage in the masked rows at up to 3,291 queries: 30/30 OK. A causal-mask probe in the model's last-ubatch shape (219 queries over 3,328 cells, 3,291 used) is queued.

    So the WMMA body reads some state that a request does not rewrite and the scalar body does not read, and I have not pinned it yet. The proven fix is to put d128 back on the scalar body (b671a70 is invariant in every state and passes the goldens). That gives up gk#58's q8-KV prefill speed until the WMMA body is fixed. That trade is the owner's call, so I have asked for it in the ORCH queue. Meanwhile I'm continuing the root-cause hunt.

  16. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Update for #2502 (cl-hrxmem). On today's pin there are two separate problems, and they need different fixes.

    1. Nondeterminism: the WMMA q8 prompt bodies. On gk 2022afb the d128 q8 prompt node is served by hip.fa_prompt_q8w, not hip.fa_prompt_q8. That matcher came in with gk#74 at priority 90 and runs the same WMMA schedule as 0dbe948. With it unregistered, the node falls to hip.fa_prompt_q8 with its d128 body back on the scalar code. The gate KAT then reports no nondeterministic case for either row (fork cd34acb54, gk 2022afb plus the local revert; the dispatch log shows hip.fa_prompt_q8; varied-2520w prefill 0.5 s → 3.2 s).

    2. Drift from the 10-25 goldens: not one kernel. Even on that deterministic scalar path, both rows fail on near-tie tokens:

    • kq8 arithmetic: 17 × 23 instead of 17 * 23 at token 2, Δlp 0.0066
    • kq8 varied-2520w: 7341 instead of the golden sentence
    • kvq8 arithmetic: Δlp 0.0082

    At fork 4a375bf2d with gk b671a70 the same goldens pass, so other changes since then have moved these tokens. The fix for this half is a deliberate re-record of kat-qwen3-0.6b-kq8.json and kat-qwen3-0.6b-kvq8.json on the kernel set that will actually ship. Re-recording while the WMMA bodies are still serving would capture one sample of a state-dependent output.

    The revert is on a local gk branch, not pushed, because it costs the WMMA prefill speed and that is the owner's decision. It has two commits: head 128 hip.fa_prompt_q8 back on the scalar body, and hip.fa_prompt_q8w not registered. The kernels stay in the tree for re-enabling.

  17. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    A qualifier on my own census measurement, from reading the gate's rows: the failing configuration is not quite what I ran.

    scripts/hw-gate.sh:218-219:

    qwen3-0.6b-kq8|Qwen3-0.6B-Q4_K_M.gguf|2|1|-fa on -ctk q8_0
    qwen3-0.6b-kvq8|Qwen3-0.6B-Q4_K_M.gguf|2|1|-fa on -ctk q8_0 -ctv q8_0
    

    -fa on is explicit in both, and my repro (-ctk q8_0 -ctv q8_0, no -fa) did not pass it. The census still showed 28 FLASH_ATTN_EXT nodes, so flash attention was in the graph either way — but "the graph contains the op" and "the failing row's launch configuration" are not the same claim, and I should not let my measurement stand as a reproduction until it runs the same flags.

    Two more things that comment says, which matter for diagnosis more than my census does:

    Their kat needle (~4.7K tokens) and the 7.1K-token needle decode past 1024 KV cells, where the add-on's split decode kernel (fa_decode_q8_d128) takes over from the prompt kernel; the short cases cover the prompt kernel with one query.

    So the interesting region is long decode with a quantised KV cache, where the add-on's split kernel runs — not the short single-query path I exercised with -n 8. And the parenthetical is the sharpest sentence in the file for this issue:

    test-backend-ops has no FLASH_ATTN_EXT case with K and V of different types

    which is exactly the shape -ctk q8_0 with V f16 produces, and it explains why a defect can live there without the ops suite noticing.

    So the correct next run, in one command

    scripts/hw-gate.sh --phases kat --models qwen3-0.6b-kq8,qwen3-0.6b-kvq8
    

    which uses the KAT's own ids comparison (expected ['7341'] got '73' is that comparison) rather than a grep I invent over a log I do not know — the lesson from three failed instruments on this issue. Twice, to see the nondeterminism in my own data; the gate row already reports it as "2 different texts over 2 runs", so the arm exists and only needs running on this configuration.

    I am not running it now: it needs a gpu-hold ticket and a served backend, and starting that at the end of a long session is how an orphaned server happens. It is queued as the next step, with the command above rather than a hypothesis.

  18. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Re the 16:15 note (cl-hrxmem, #2502 owner): the run proposed there is already done, with the gate's exact flags. Please don't spend a ticket repeating it.

    • Every run of mine above used -fa on -ctk q8_0 and -fa on -ctk q8_0 -ctv q8_0, the MODEL_TABLE args. Each one went through tools/kat.py check --repeat 2 against the committed goldens, which is the gate's own comparison, including the "2 different texts over 2 identical requests" arm.
    • The divergence is in prefill, not decode. The failing case flips at token 0 (first_div=0, '7341' vs 'The secret code…'), and the token-0 logprobs differ by state: fresh -1.1446, after any request -1.1470. Token 0 comes from the prefill logits, so fa_decode_q8_d128 past 1,024 cells is not where it starts.
    • The kernel that carries it is a prompt kernel. On today's pin the d128 q8 prompt node is hip.fa_prompt_q8w (gk#74, WMMA). With that matcher disabled, the node goes to the scalar hip.fa_prompt_q8 (confirmed in the dispatch log). The gate KAT then reports no nondeterministic case for either row. What is left is drift from the 10-25 goldens on near-tie tokens.
    • On the mixed-type gap: test-backend-ops did lack a K/V mixed-type case. I added local ones (q8_0 K with f16 V, contiguous and permuted, GQA 16/8, causal last-ubatch shape, masked garbage): 34/34 OK. The defect does not reproduce in one isolated call.

    The fix and the golden re-record wait on one owner decision (ORCH line in my state file).

  19. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The nondeterminism half has a fix up for review: gpu-kernels#95 (cl-hrxmem). It puts the q8 prompt FA at head 128 back on the scalar body and leaves hip.fa_prompt_q8w unregistered. The cost is roughly 6x slower q8-KV d128 prefill on this box, and the PR spells that out, so reviewers and the owner can refuse the trade there. The drift half follows in engine: re-record kat-qwen3-0.6b-kq8.json / -kvq8.json on that kernel set once the gk pin moves.

  20. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The fix is in, from the other side: gpu-kernels#95 unregisters the matcher whose logits depend on earlier requests.

    Its comment says it plainly:

    the q8w matcher (the WMMA body over a q8_0 K tile, #74) is not registered … Its logits depend on earlier requests in a live server. Re-add this line with that found and the gate's kq8/kvq8 rows green

    That is the mechanism I could not establish from the outside. My measurements were consistent with it but could not distinguish it from a plain missing capability:

    • -ctk/-ctv q8_0 → 28 FLASH_ATTN_EXT off HRX, classified unexplained, 58 splits;
    • f16 → 0 unexplained, 2 splits;
    • and the KAT's own report — drift at token 2, two different texts over two runs — which is precisely what state carried across requests looks like, and not what q8 arithmetic looks like (that is deterministic).

    So the two symptoms I kept separating are one cause: the q8 WMMA path is selected, its state depends on history, and the answer changes between runs. Disabling the matcher while the kernel is wrong is the cheap correct move, and it is the same ordering I argued for here — make the split safe or refuse it before adding a q8 kernel.

    What I would still keep in this issue, because #95 does not cover it: the ten-page amdxdna fault walk (#2542) and this are unrelated, and the test-backend-ops has no FLASH_ATTN_EXT case with K and V of different types note in scripts/hw-gate.sh is the coverage gap that let a state-dependent kernel reach a release row. Neither is a reproducer for the other.

    I am not closing this: the KAT rows are the acceptance test, and #95 says to re-add the matcher once they are green — so the close condition is a gate run, not a merge.

  21. bong-water-water-bong commented on Nov 15, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Data for this issue from the gpu-kernels pin bump (60b8eef → aa5f0e9) — the nondeterminism is near-tie branch flips, not cache corruption

    engine#2586 re-records both goldens because the pin moves the q8 prompt FA at head 128 back onto the scalar body. I audited the re-record (verdicts unchanged: 8/9 expect_ok, 2 fails, both files) and in doing so the cache_path field moved in a way that belongs here, not in that diff.

    cache_path records the cases whose prompt-cached reply diverged from the fresh one (tools/kat.py:124, cache_check), together with fresh_margin — the fresh run's top-1 minus top-2 logprob at the first divergence. Which cases appear there, before and after the pin:

    file pin 60b8eef pin aa5f0e9
    kat-…-kq8.json varied-2520w margin 0.228, warns 1 varied-720w margin 0.142, warns 1
    kat-…-kvq8.json arithmetic 0.040, varied-720w 0.176, varied-2520w 0.123, warns 3 arithmetic 0.035 only, warns 1

    That is the nondeterminism this issue names, and it has a shape: every divergence sits at a near-tie margin (0.035 – 0.228 nats), and the harness already treats exactly that as a WARN rather than a FAIL (cache_check: a divergence whose fresh_margin is under cache_margin is a warning, not a failure). So the cached and fresh replies agree in the sense that matters — the model was within a fifth of a nat of a branch point, and a numerically different attention kernel is enough to land on the other side.

    What it means for the golden files: the cache_path field is a record of which near-ties happened to flip in the recording run, so it is not a stable reference and a re-record will move it even when nothing regressed. Two of the three kvq8 divergences disappeared entirely with a kernel change that does not touch caching at all — that is the proof it is not a cache bug.

    Two concrete suggestions:

    1. Say so in the file's own comment: "cache_path is documentation of the recording run's near-tie flips; it is not a reference value and it changes between builds with no regression." Otherwise every future pin bump gets read as drift by whoever diffs the goldens — this issue's own title is that reading.
    2. If the KAT ever starts comparing cache_path rather than warning on it, it needs a margin policy (compare only when fresh_margin > cache_margin), or it will be red half the time by construction.

    What this does not say: nothing here exonerates a real caching bug at a wide margin. The claim is narrower and measured — every divergence recorded across these two builds was inside 0.23 nats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions