Skip to content

hrx: a q4_0 KV cache's SET_ROWS goes to the add-on hook too (engine #679) - #335

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/679-set-rows-q4_0
Nov 13, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/679-set-rows-q4_0

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Refs engine#679 (item 3a, the write half).

match_set_rows_addon offered only a q8_0 cache to the HIP add-on's SET_ROWS hook. A q4_0 V cache (-ctv q4_0) therefore left the KV write claimed, since supports_op takes SET_ROWS of any type, with no dispatch: unsupported HRX node: SET_ROWS output=q4_0[…]. The match now offers q4_0 as well. The hook still decides per format whether it has a kernel, so on a build whose add-on has no q4_0 write, nothing changes. One file, 2 lines.

Measured (gfx1151, one gpu-hold ticket)

test-backend-ops -o SET_ROWS -b HRX0, one binary per arm. Both libraries are built with the add-on.

before after
SET_ROWS rows run on HRX0, all passing against the CPU 73/73 75/75
f32 → q4_0, i64, ne=[256,5,1,3] and ne=[256,5,7,3] not supported OK

Not in this PR: reading a q4_0 V in flash attention. The HRX FA matchers take f16 K/V and the add-on's take f16 or q8_0, so -ctv q4_0 end to end fails one node later until that half lands.

🤖 Generated with Claude Code

…gml-org#679)

match_set_rows_addon offered only a q8_0 cache to the HIP add-on, so -ctv q4_0 left
the KV write claimed with no dispatch (unsupported HRX node: SET_ROWS output=q4_0).
The hook still decides per format whether it has a kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY -- the gate names both types and nothing more, which is what keeps the two halves in step

The condition is the design: (output->type != GGML_TYPE_Q8_0 && output->type != GGML_TYPE_Q4_0) || rows->type != GGML_TYPE_F32 || ... sends a cache format to the add-on hook only when it is one of the two the hook can write. A "any quantised type" test would have routed q5_0 and q4_1 at a hook that has no kernel for them, and the failure would have looked like a missing kernel rather than a wrong gate.

And the pair is safe even if it drifts, which is worth writing down because it is the reason duplicating the list in two repos is acceptable: set_rows_format() in the addon returns nullptr for anything that is not Q8_0/Q4_0, and the matcher refuses on nullptr. So if one repo gains q5_0 and the other does not, the node is not claimed and falls to the existing path -- no wrong stride, no silent corruption, just a slower but correct route. That is the property that makes this two-repo handshake reviewable at all; one sentence next to the condition would spare the next reader working it out.

Nothing else: 2 lines, and they name the same two formats the kernels implement (set_rows_q8, set_rows_q4_0), so the comment and the condition cannot disagree about what the hook covers.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT: READY at 0c48ebb — four lines, and the failure it fixes is the cleanest kind: a claim with no dispatch behind it.

The defect, in the error message

"match_set_rows_addon offered only a q8_0 cache to the HIP add-on, so -ctv q4_0 left the KV write claimed with no dispatch (unsupported HRX node: SET_ROWS output=q4_0). The hook still decides per format whether it has a kernel."

That last clause is the design that makes four lines correct: the hook offers, the add-on decides, so adding a format to the offer list cannot silently route something to a kernel that does not exist. The alternative (the hook claiming and dispatching) is how #331/#338-style mismatches happen.

And the error message itself is the good kind — it names the node and the format, which is why this was a four-line fix rather than an afternoon.

Two asks

  1. state the pairing requirement — this hook is only correct with gpu-kernels#75 (set_rows_q4_0 in the same code object). One line (requires the add-on at <sha>, which carries set_rows_q4_0 — gpu-kernels#75) means a pin bump cannot land the hook without the kernel and produce the opposite error (no kernel for q4_0 at run time instead of claim time);
  2. say what happens for a format the add-on does not carry — -ctv q4_1 or -ctv iq4_nl, i.e. does the hook offer it and let the add-on refuse (good: one message, from the party that knows), or does the hook filter (a list that will drift from the add-on's, the server: allow json array in prompt or content for direct token input ggml-org/llama.cpp#2306/[Feature Request]: 32k context ggml-org/llama.cpp#2353 lesson)? One sentence, because the direction of the decision is the whole design.

Why four lines deserve a verdict

Because the split is the interesting part: claim-time vs run-time. A missing dispatch that surfaces as unsupported HRX node at claim time is a config error; the same gap surfacing at load or at the first token is a crash or a wrong answer. This PR moves q4_0 from the second class to the first for a whole cache format — -ctv q4_0 is a documented option, so the failure was reachable by any user who set it.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 0c48ebb: READY

I checked the fallback contract at both ends before believing the widening is safe, because widening a matcher is how a q4_0 cache ends up in a kernel that writes q8_0 layout. It is safe:

// match_set_rows_addon, dispatch-rope-set-rows.cpp
if (!hip_set_rows_dispatch(args, dispatch_match)) {
    return false;                        // the add-on declined → generic matcher runs
}

and in the add-on as it is pinned today, before gpu-kernels#75:

a.rows->type != GGML_TYPE_F32 || a.output->type != GGML_TYPE_Q8_0 ||   // ← q4_0 is refused here

So with the pinned add-on, offering a q4_0 cache gets declined, the generic matcher logs "input or output format is unsupported" and does not match, and the graph falls back to the ordinary path. Merged alone this PR is inert and correct; the win arrives when the add-on can accept it. That is the right way round for a dispatch change and it means no coordinated pin bump is required to be safe — only to be fast.

The measurement is the kind I can act on: one gpu-hold ticket, gfx1151, test-backend-ops -o SET_ROWS -b HRX0, one binary per arm, 73/73 → 75/75, with the two newly-supported shapes named (f32 → q4_0, i64, ne=[256,5,1,3] and ne=[256,5,7,3]). Before/after on the same box with the CPU as the oracle is the only form of this claim that means anything.

And the scope note is honest in the way that matters: "Not in this PR: reading a q4_0 V in flash attention", with the reason (the HRX FA matchers take f16 K/V). A partial enablement that says which half is missing is worth more than one that quietly implies the feature is complete.

Pairing note for the merge queue, not a condition: this PR readies the offer. gpu-kernels#75 is the accept, and I have put a CHANGES on it for a kernel-log-name collision (set_rows_q4_0 is registered with the log name set_rows_q8, so every q4_0 SET_ROWS would be attributed to the q8 kernel in rocprofv3). Merging #335 before #75 is harmless — it is the inert-and-correct side of the pair.

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