Skip to content

tests: size the flash-attention K/V at the kernel's 64-token tile, and pin the fallback (engine#2870) - #433

Merged
bong-water-water-bong merged 4 commits into
1bit/hrx-vulkan-patchedfrom
corpus/fa-kv-tile-on-hrx
Nov 20, 2026
Merged

bong-water-water-bong merged 4 commits into
1bit/hrx-vulkan-patchedfrom
corpus/fa-kv-tile-on-hrx

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 20, 2026 •

Copy link
Copy Markdown

The split-attention fixtures allocated K/V at exactly key_value_token_count, so the kv=65 and kv=513 cases handed the matcher a cache it refuses by design: dispatch-flash-attention.cpp requires the storage to be at least the padded capacity ceil(kv/64)*64 (engine#2494, added after the kv65 page faults). A real cache is allocated to the tile, so the rig is now too.

The mask is left alone: mask->ne[0] is the matcher's key_value_token_count, i.e. how many keys are real. Padding it would rewrite the shape under test (and silently turn kv=513 into kv=576, so the split arm would be selected for a different reason). Only the K/V storage is padded.

Ports the same fix as #430 (tests/fa-kv-tile-capacity) onto 1bit/hrx-vulkan-patched, where the exported matcher is already ggml_flash_attention_decode_split_f32_f16_wmma_next_q8.

Evidence (ryzen, gfx1201, GGML_HRX_GTT_RESERVE_MB=1024, SDK libhsa on LD_LIBRARY_PATH)

fa_decode_split — before: 3 passed / 2 failed (fa_decode_split.4.513, fa_decode_split.4.513.true.96.64.1/sqrt(96.0f), both failing plan.dispatches.size() == query_token_count because the split arm declined and nothing else took the node). After: 7 passed, 0 failed, 372 ms — kv=513 now reaches the split arm over its 576-slot cache, which is the behaviour the fix exists to prove.

Rebased onto bccadbe54 (Merge pull request #432); the two commits that landed as #432/#434 dropped out of this diff.

Second commit (tests: reach the decode-split fallback above the cap, and add kv=65): the branch's own if (key_value_token_count > 2944) block had never executed, because no case passed kv past the cap — every caller used 512 or 513. It also asserted the wrong thing: above the cap a row keeps one launch per query row with the general kernel taking the node, not one launch total, and the arm there is loom_libs:ggml_flash_attention_f32_f16_wmma, not "anything but the split kernel". Fixed and made reachable by fa_decode_split.1.3008 (the smallest 64-multiple past the cap), added alongside fa_decode_split.1.65 — the shape engine#2494 blamed and which is legal for the split arm now.

Third commit ports the same fixture to tests/hrx-ops-test.cpp, replacing its power-of-two cache doubling (64, 128, 256 …) with the kernel's 64-token tile, which is what the matcher actually requires.

Full test-hrx-ops on this branch: 16 passed, 274 failed, 290 total, 674343 ms. Every one of the 274 is graph_compute: no HRX dispatch registry for target gfx1201 — this box cannot build the HIP add-on (__builtin_amdgcn_wmma_f32_16x16x16_f16_w32 needs wmma-256b-insts,wavefrontsize32, which gfx1201 lacks), so that total measures the absent add-on, not this diff. The gate number is 46 of 271 on gfx1151; see engine#2774.

Also carries, as separate commits

  • e9360b6 hrx: promote the installed-package targets to GLOBAL so the HRX unit tests link (hrx: promote the installed-package targets to GLOBAL so the HRX unit tests link #432). Without it a tree configured against the installed hrx package does not generate at all.
  • 6924f2b hrx: compile against the loomc C API that ships. loom-jit.cpp called loomc_link_index_builder_allocate / _free; the installed loomc exports _create / _release, so ggml-hrx did not compile and no HRX test binary could be built in a package-configured tree.

Both are defects independent of engine#2870 and could land first.

Not done here, and now known not to be needed

I had written that the flash_attention.{64..512}.2.65.1 group needs its padded tail masked out and the padded slots zeroed. That was wrong in purpose: those eight rows pass unchanged on a tree that builds the add-on —

strixhalo gfx1151, add-on built, filter "(fa_decode_split|qwen_flash_attention|65\.1|accumulator_range)"
test-hrx-ops summary: 24 passed, 0 failed, 0 known-fail, 1 unexpected-pass, 25 total
[PASS] flash_attention.448.2.65.1/....flash_attention_decode_split_f32_f16_wm  433 ms

They were only ever red in a tree with no add-on, where no amount of fixture padding helps. So there is no follow-up change to make here; see engine#2870.

bong-water-water-bong added 4 commits November 19, 2026 23:23
…d pin the fallback

The split-attention fixtures allocated K/V at exactly key_value_token_count, so
the kv=65 and kv=513 cases handed the matcher a cache it refuses by design
(engine#2494: key->ne[1] >= ceil(kv/64)*64). A real cache is allocated to the
tile, so the rig is now too, and the mask widens with it -- that is the length
the kernel is handed.

The rows the split arm cannot take (kv not a 64-token multiple, or past the
engine#679 cap of 2944) now assert the fallback explicitly instead of failing
on the split arm's transients: one launch per query row, none of the split
transients, and never the split kernel.

Ports the fix from tests/fa-kv-tile-capacity (llama.cpp#430) onto
1bit/hrx-vulkan-patched, whose exported matcher was already renamed, and adds
the fallback guard for the 2304/4096/16384 rows #430 leaves out.
…the split arm

The first version of the fallback guard sent every padded row down the
"not the split arm" branch, which the device rejected: kv=513 over a
tile-sized cache IS the split arm, and that is the point of the tile.

The mask keeps the graph's logical key length (it is what tells the matcher how
many keys are real), so mask, mask row bytes and the key_value_token_count
parameter stay at the token count; only the K/V storage is padded. The guard
now covers just the case #429 defines: past 2944 tokens the split dispatch is
not offered at all.

fa_decode_split on gfx1201: 5 passed, 0 failed (was 3 passed / 2 failed).
The >2944 block never ran: no case passed kv past the cap. kv=3008 is the
smallest 64-token multiple above it, so the padded storage is exactly the
shape the general matcher accepts and the split matcher declines; the block
now pins the general kernel by name instead of only "not the split one".

kv=65 is the shape engine#2494 blamed and is now legal for the split arm.
Both cases are plan-only: they check which kernel the scheduler picks.
Same fixture as test-hrx-ops: K/V storage at ceil(kv/64)*64, mask at the
logical length, capacity by the tile instead of power-of-two doubling. Its
kv513 rows now reach the split arm instead of the general kernel.

Two stale expectations in this suite kept the five rows red even for kv512,
where the allocation was already aligned: the Q8_1 alternate is registered
on the attention output while the row looked it up on the reshape that
aliases it, and the split kernel is Exact, as the untouched kv320 row
already shows. Both are plan-only rows.
@bong-water-water-bong
bong-water-water-bong merged commit 70d991d into 1bit/hrx-vulkan-patched Nov 20, 2026
@bong-water-water-bong
bong-water-water-bong deleted the corpus/fa-kv-tile-on-hrx branch November 20, 2026 03:36
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