Skip to content

tests: size the flash-attention K/V at the kernel's 64-token tile (engine#2870) - #430

Closed
bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
tests/fa-kv-tile-capacity
Closed

bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
tests/fa-kv-tile-capacity

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

The split-attention rows 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:387 declines unless key->ne[1] >= ceil(kv/64)*64 — the padded capacity engine#2494 introduced after the kv65 page faults.

A real cache is allocated to the tile, so the rig is now too. The mask widens with it, and the two kernel-facing expectations move to the capacity, because that is the length the kernel is handed.

Evidence

fa_decode_split.4.513 on gfx1201 (GGML_HRX_GTT_RESERVE_MB=1024, IREE_HAL_AMDGPU_LIBHSA_PATH from the SDK):

  • before: PROBE2870 dispatches=1 on loom_libs:ggml_flash_attention_f32_f16_wmma, then requirement failed: plan.dispatches.size() == query_token_count
  • after: rc 0 — one dispatch per query row on ggml_flash_attention_decode_split_f32_f16_wmma_next_q8
  • fa_decode_split.4.513.true.96.64.1: rc 0
  • qwen_flash_attention still schedules ggml_flash_attention_f32_f16_wmma: that case passes use_common_dispatch=true on purpose.

Not done here

The flash_attention.{64,128,192,256,320,384,448,512}.2.65.1 group goes through run_common_flash_attention_cpu_reference_case, which compares numbers. Padding there also needs the padded mask tail masked out (and the padded K/V slots zeroed) or the comparison reads uninitialised memory; that is a second change and is not in this PR.

…gine#2870)

The split-attention rows allocated K/V at exactly key_value_token_count, so the
case for kv=65 or kv=513 handed the matcher a cache it refuses by design:
dispatch-flash-attention.cpp:387 declines unless key->ne[1] >= ceil(kv/64)*64,
the padded capacity engine#2494 introduced after the kv65 page faults.

A real cache is allocated to the tile, so the rig now is too. The mask widens
with it, and the two kernel-facing expectations move to the capacity, because
that is the length the kernel is handed.

fa_decode_split.4.513 goes from 1 dispatch on the general wmma kernel to one
dispatch per query row on ggml_flash_attention_decode_split_f32_f16_wmma_next_q8,
which is what the row asserts.
@bong-water-water-bong

Copy link
Copy Markdown
Author

Closing in favour of #433, which fixes the same two failing rows the other way round.

The substantive difference: this PR pads K/V and the mask together, so the fixture ends up with capacity == token_count. That is the shape the engine deliberately does not produce. dispatch-flash-attention.cpp:358 derives the token count from the mask (key_value_token_count = mask->ne[0]) and :356 derives the capacity from the storage, precisely so that a real decode with a partially filled cache (storage = 64-aligned capacity, mask = n_past) is the case under test. Padding the mask erases that distinction and additionally lets the kernel attend over the pad slots.

#433 keeps the mask logical and pads only the storage, which is the production shape, and it asserts key_value_token_capacity == 576 against key_value_token_count == 513 so the partially-filled case is explicitly covered. Its body also no longer claims the 5/5 result proves the engine#2494 binding-overrun class is gone — these are plan-only cases and never launch a kernel.

Two things from this PR are still worth keeping and are being carried into #433: the second suite tests/hrx-ops-test.cpp has the same unpadded fixture at :1556-1559 and runs the same cases, and a kv=65 case (the shape the ggml-org#2494 page fault actually came from) is worth adding now that it is legal.

bong-water-water-bong pushed a commit that referenced this pull request Nov 20, 2026
…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.
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