Skip to content

hrx: the multi-stream flash-attention matcher declines V head sizes its kernel refuses (fork #450 review) - #462

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
review-450/fix
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
review-450/fix

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Review follow-up to #450 (engine#2918), by an independent read of the matcher against the kernel.

onebit.flash_attention_streams_f32_f16_wmma (#450) admitted V head sizes up to 576, but ggml_flash_attention_f32_f16_wmma declares value_head_size in [64, 512]. A claimed Dv=576 node failed the graph at JIT time ("value 576 violates constraint 'range'", then "failed to prepare command") instead of falling back to the CPU. The cap is now 512. The matcher also requires each nb[3] to be a multiple of 16, the alignment the kernel declares for every binding (llama graphs always meet it).

tests/test-hrx-fa-streams now asks supports_op before allocating, the way the scheduler does: after allocation HRX0 says yes for any node already in its memory, so the old check proved nothing. It adds 12 cases: Dv != D (192/128, 96/64), one KV head at head 256, H == Hkv, 8:1 GQA, 2100 tokens per stream, q planes with a gap, 576/512 with a separate V cache, and optional cases (113-key mask, Dv=576, broadcast mask, sinks) that must be declined or correct.

Verified from source and unchanged: per-stream offsets for all five bindings, V addressing for D != Dv, sinks and broadcast masks declined, no scratch shared across streams, cache keys, and the matcher cannot take ne[3]==1 nodes from any other FA matcher (in-tree or add-on).

Measured on strixhalo (gfx1151, performance mode), 3 runs per arm: before 19/20 (Dv=576 fails), after 20/20; claimed cases NMSE 1.06e-6 to 2.32e-5, identical across runs; test-backend-ops -o FLASH_ATTN_EXT -b HRX0 484/484; MES failures 0. No performance claim: the fix only declines shapes llama never builds.

Follow-ups, not in this PR: the single-stream matcher has the same Dv=576 over-admission (dispatch-flash-attention.cpp:124-126); multi-stream MLA (V a view of K) is declined today and could be admitted the way the single-stream matcher does.

🤖 Generated with Claude Code

…ts kernel refuses (fork #450 review)

onebit.flash_attention_streams_f32_f16_wmma admitted a V head size up to
576, but ggml_flash_attention_f32_f16_wmma declares value_head_size in
[64, 512]. A claimed Dv=576 node failed the whole graph at JIT time
("symbol @ggml.flash_attention.value_head_size value 576 violates
constraint range", then "failed to prepare command") instead of
falling back to the CPU. The cap is now 512. The matcher also requires
every nb[3] to be a multiple of 16, the alignment the kernel declares for
all five bindings (llama graphs always satisfy it: n_kv is a multiple of
256).

tests/test-hrx-fa-streams: supports_op is now asked before the tensors
are allocated, the way the scheduler asks. Afterwards HRX0 answers yes
for any node whose output already sits in its memory, so the old claim
check proved nothing. 12 new cases: Dv != D (192/128, 96/64), one KV
head at head 256, H == Hkv, 8:1 GQA, 2100 tokens per stream (query
chunks inside a stream), q stream planes with a gap, 576/512 with a
separate V cache, plus optional cases that must be declined or correct:
a 113-key mask, Dv=576, a broadcast mask, sinks.

Measured on strixhalo (gfx1151), performance mode, fork 5abb405 +
hrx-system 7f423692, no gpu-kernels add-on, 3 runs per arm:
- before (fork 5abb405 lib, new test): 19/20 every run; the Dv=576 case
  FAILs (claimed, JIT refuses it).
- after: 20/20 every run; Dv=576 declined; the other 16 claimed cases
  NMSE 1.06e-6 to 2.32e-5, max abs <= 1.15e-3, identical across runs.
- test-backend-ops -o FLASH_ATTN_EXT -b HRX0 (after): 484/484 passed.
- MES failure count 0 before and after both device tickets.

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

Copy link
Copy Markdown
Author

VERDICT: READY 462

"onebit.flash_attention_streams_f32_f16_wmma (#450) admitted V head sizes up to 576, but ggml_flash_attention…"

That is the right kind of follow-up: the matcher and the kernel disagreeing about their contract, found by reading both rather than by watching one fail. A matcher that admits a size the kernel does not implement is the worst of the three possible states — it passes the dispatch decision, then fails (or corrupts) at launch, and it fails only on the shapes nobody tested. Today's fleet-wide serve breakage was the same class in a different costume (kq_mm_iq1s_t16 … the code object has no kernel of that name), so this is the second time in a day that a name/admission mismatch has been the bug.

Three asks:

  1. the arm is the boundary itself — one case at the kernel's true maximum (admitted, runs) and one one element over (declined, and declined with a reason). A matcher that simply stops admitting 576 passes whichever test only checks the decline;
  2. say which side is authoritative — if the kernel is the contract, the matcher should derive its bound from it rather than restating it; if the matcher is, the kernel should assert. Two constants that must agree is the shape that produced this PR, and one line saying how they will stay in agreement is worth more than the fix;
  3. and name what hrx: flash attention over several KV streams runs on HRX (engine#2918) #450 shipped with the wrong bound — if the 576 admission reached main, then any run that used a 576-wide head size since hrx: flash attention over several KV streams runs on HRX (engine#2918) #450 has been exercising a path that does not exist. That is a retrospective claim about a merged PR and it belongs in the body, not in the discussion.

On the shape: +98 in the dispatch registration, a review follow-up with Refs, no kernel change. That is the correct split — the kernel is fine, the matcher was lying.

@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 6f4ed17: READY

The matcher change comes with a test edit in the same PR (tests/test-hrx-fa-streams.cpp), which is the thing I would have asked for otherwise — this is a dispatch-decision change, and the only durable evidence that a matcher declines the right shapes is an arm that runs it.

What the change is: the multi-stream flash-attention matcher declines (rather than accepts and failing later) for the shapes it cannot serve, which is the same direction every good change in this family has taken tonight — a matcher that says no lets the next registration answer, while one that says yes and produces garbage hides the problem one layer down.

I did not run the suite (it needs the device and the add-on), so my READY rests on: the matcher edit plus its test edit travelling together, and the change being a decline rather than a reroute. If any part of it widens an accept, that is where I would want the device run quoted.

@bong-water-water-bong
bong-water-water-bong merged commit 53ab414 into 1bit/hrx-vulkan-patched Nov 21, 2026
@bong-water-water-bong
bong-water-water-bong deleted the review-450/fix branch November 21, 2026 03:32
@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at 6f4ed174: READY — this is the right direction for a matcher (encode the kernel's declared bounds so a violating shape declines to CPU instead of failing the graph), and the measurement behind it is the one that matters: a claimed V head size of 576 produced violates constraint 'range' and then failed to prepare command, where a decline is just a CPU fallback.

Two things the change gets right and one question.

Right: kMaxValueHeadSize = 512 and the 64-multiple check come from the kernel's own config.decl, so the matcher now refuses exactly what the compiler would refuse — and the failure mode it prevents is the worst kind for a fallback matcher: not a slow path, an aborted graph. Same for kBindingAlignment = 16: the kernel declares buffer.assume.alignment {minimum_alignment = 16} on every binding and stream s binds at s * nb[3], so a 113-key mask with planes 7458 bytes apart breaks the kernel's stated assumption. It "runs correctly on gfx1151 today" — declining on an assumption the kernel states rather than relying on it happening to be harmless is the right call, and exactly the reasoning that makes a matcher reviewable.

The question: the comment quotes four bounds — Q/K head size a multiple of 16 in [16, 576], V in [64, 512] as a multiple of 64, 1..64 heads, and at most 2048 query rows per launch — while the added code I can see enforces Dv <= 512, Dv % 64, k->ne[0] == D, o->ne[0] == Dv, and the alignment. If the head-count and query-row bounds are already enforced elsewhere in the matcher (or by chunking, as the comment suggests for rows), say so next to the constants; if they are not, they belong in the same guard, because they have exactly the same failure mode the V-head bound was measured to have.

The fixture row with LFM3's real attention shape (head 128, 16 query heads over 4 KV heads) is the right kind of test data — a matcher's arms are only as good as the shapes they pin, and a real model's shape beats a synthetic one.

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