Repository navigation
hrx: cap the decode-split FA just below its measured crossover (engine#679) - #429
Merged
bong-water-water-bong merged 1 commit intoNov 19, 2026
Conversation
…e#679) The decode-split matcher admitted padded key-value capacity up to 32768. The loom-libs `reduce_fused` providers only cover 32 partial blocks (2048 tokens) with the cooperative reducer; everything above runs `reduce_completed.multipass`, which folds the per-head partials with one workgroup per KV head and a serial per-lane block loop. That arm costs more the longer the context, and on gfx1151 it overtakes the general `ggml_flash_attention_f32_f16_wmma` at a measured crossover of ~2.9-3.0k tokens, while it is faster below that. Measured on gfx1151 with the existing unpatched 4df0f3e build (the dispatch file is byte-identical between that commit and this branch's base 17fc2a3), Qwen3-4B-Q4_K_M, llama-bench -p 0 -n 128 -r 2 -fa on, split-on and "registration disabled" arms interleaved in one gpu-hold claim (disabling the registration is exactly the fall-through the cap produces above its bound); tok/s split/general: d=2048 59.84 / 55.87 split +7.1% d=2304 57.44 / 53.63 split +7.1% d=3072 49.10 / 49.43 parity d=3584 45.50 / 46.78 split -2.7% d=4096 40.66 / 43.96 split -7.5% d=8192 22.25 / 31.78 split -30% d=16384 10.41 / 20.02 split -48% Cap the matcher at 46 blocks (2944 tokens), just below that crossover, so a longer decode falls through to the general dispatch that is correct for arbitrary key_value_token_count (it already serves prefill) - just not split-parallelized. The same bound was accepted before the multipass provider existed (#9, 2026-09-26); this re-applies it at the measured crossover instead of the provider ceiling, with the measurement and the depth tests that decision lacked. Add four test-hrx-ops CPU-reference rows for query=1: kv=2048 (cooperative reducer), kv=2304 (the multipass arm the cap keeps), and kv=4096/16384 (the general kernel above the cap). All are capacity-64-aligned, so engine#2494's storage guard does not decline them for the wrong reason. No committed case reached a capacity above the cooperative ceiling before this. The crossover is shape-dependent (one reducer workgroup per KV head) and this bound is measured on an 8-KV-head shape; a parallel reducer or a shape-aware bound is the follow-up. engine#679
bong-water-water-bong
pushed a commit
that referenced
this pull request
Nov 20, 2026
…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).
bong-water-water-bong
pushed a commit
that referenced
this pull request
Nov 20, 2026
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs engine#679 (not
Fixes: this bounds a dispatch; the 18.8k headline row is not re-measured - see Not claimed).What
common.flash_attention_decode_split_next_q8(priority 75) is offered for a 1-query decode FLASH_ATTN_EXT whenever the padded KV capacity is <= 32768. But the loom-libsreduce_fusedproviders only serve 32 partial KV blocks = 2048 tokens with the cooperative reducer; everything above that runsreduce_completed.multipass, which folds the per-head partials with one workgroup per KV head and a serial per-lane block loop.Measured on gfx1151 that multipass arm is faster than the general
ggml_flash_attention_f32_f16_wmmaup to ~2.3k tokens, ties at ~3.1k, and loses from ~3.5k up (down to -48 % at 16k). This caps the matcher at 2944 tokens (46 blocks), just below the measured crossover, so a longer decode falls through to the general dispatch (priority 50), which is correct for arbitrarykey_value_token_count- it already serves prefill - just not split-parallelized.Measured
Qwen3-4B-Q4_K_M, gfx1151, llama-bench
-p 0 -n 128 -r 2 -fa on, split-on (A) and registration-disabled (B,GGML_HRX_DISABLE_DISPATCH=common.flash_attention_decode_split_next_q8) arms interleaved in one gpu-hold claim, second pass in reverse order. Disabling the registration is exactly the fall-through this cap produces above its bound:Within-arm sd <= 0.64 tok/s on the 0-16k rows; the 2,304-3,584 probe rows have sd <= 1.26 tok/s (two samples). The crossover is ~2.9-3.0k tokens, not the 2048 cooperative ceiling: the multipass arm is still faster at 2304 (+7 %), ties at 3072, and loses from 3584 up. The cap is set at 46 blocks = 2944 tokens, just below that crossover. (The llama-bench
-d 2048row is a capacity-2112 point, i.e. already multipass - it is why both "2k" and "2.3k" show the same +7 %.)Patched build, one binary, cap-active (A) vs the matcher disabled (B),
-r 3:-r 3, same claim/window, final binarylibggml-hrx.so.071da9653... (the patch), frozen references alongside. The rest of the acceptance depths on the same final binary, same protocol: d=0 A 75.84/B 74.76 (1.015; at d=0 the two kernels are speed-equivalent - the split arm is only taken below the cap), d=8192 A 31.57/B 31.41 (1.005, both general) and d=16384 A 19.72/B 20.06 (0.983, both general, within 2-sd drift). The cap picks the faster-or-equal arm at every measured depth (0, 2048, 2304, 3072, 4096, 8192, 16384).Dispatch/provenance: the B arms (registration absent) log only
common.flash_attention_f32_f16_wmma; the A arms log both kernels at every depth (including above the cap), so the per-process log alone does not name the timed graph's kernel - the A/B convergence above the cap and the gap below it are what show the fall-through. The patched binary is the 4df0f3e bench tree with this branch's two files applied; 4df0f3e differs from the branch base 17fc2a3 only in non-FA files (dispatch-mul-mat.cpp, the mul_mat corpus, tests), so the FA path under test is the branch's.Deep retrieval at ~17.7k tokens (17,744-token prompt, needle at 65 % depth, greedy,
-n 128): needle FOUND on both arms - the kept general path retrieves it, and the frozen split/multipass arm retrieves it too. This is a behavioural check only; no logit/top-k comparison was done. The same runs' decode rates were 18.44 tok/s (patched, general) vs 9.43 tok/s (frozen, multipass), the same ~2x gap the bench shows at depth; both arms are the same binary, model and prompt with only the registration differing, and the frozen arm's 17,744 keys are inside its 32768 bound while the patched arm's are above the 2944 cap.Greedy corroboration on the frozen unpatched pair at a 13,866-token prompt: deterministic 38-token greedy output diverges between the two kernels at generated id 20 (identical first 20/38 ids) and is identical at short context; A-vs-A repeats are identical. This is a behavioural difference, not a correctness verdict - no logit/top-k comparison was done. The correctness evidence is the CPU-reference rows below.
Tests
Four new
test-hrx-opsCPU-reference rows for query=1 (tolerance 5e-2 vs the harness's reference):flash_attention.128.1.2048...next_q8- cooperative reducer, the last capacity below which the split dispatch is first-class; expects the split kernel.flash_attention.128.1.2304...next_q8- the multipass arm the cap keeps for the 2048-2944 band; expects the split kernel.flash_attention.128.1.4096...wmmaand...16384...wmma- above the cap; expect the general kernel.All are capacity-64-aligned, so engine#2494's storage guard (
key/value storage >= padded capacity) does not decline them for the wrong reason. No committed case reached a capacity above the cooperative ceiling before this, so nothing exercised the multipass arm. Device run on the patched build: 6 passed, 0 failed for--test-filter flash_attention.128.1- the four new rows plus the two pre-existing 128.x rows, including kv=2304 (multipass) PASS. A broadflash_attentionrun on the patched build (34 cases; the final binary also adds the kv=2304 row, which passes in the 6-row gate) and on the frozen unpatched binary (31 cases) has the identical 11-name failure set (11 pre-existing, 0 patch-induced) - they are engine#2870-shaped stale split expectations for kv=65/4 rows that the merged ggml-org#2494 storage guard now declines.Why a cap and not a kernel fix
reduce_completed.multipassis a correctness fallback, not a tuned path, and the corpus also ships a two-dispatch parallel produce/reduce variant that no dispatcher references. Fixing/using that is a bigger change and a different PR. This patch bounds the split dispatch at the crossover the data shows, which is also the bound it had before the multipass provider existed (#9, 2026-09-26, at the 2048 cooperative ceiling); #13 raised it and a later merge (f2099e9b7) accidentally restored 32768, leaving the contradictory comment this patch also fixes.Not claimed
reduce_completed.multipass; if a future corpus sync drops that provider (as51e538fa0found once after an AMD sync), those capacities hit the engine#115all_rejectedhard failure instead of falling back. The kv=2304 row is the tripwire, andhw-gatedoes not runtest-hrx-opsby default.llama-benchtimes only; correctness is the op-level CPU reference plus a deep retrieval check. Greedy text at depth differs between the two kernels (deterministic, identical at short context) - a behavioural difference, not a correctness verdict.Qwen3-Coder-30B-A3Barm faulted the device (HSA_STATUS_ERROR_MEMORY_FAULT-> gfxhub page fault -> abort) before producing a number and was not retried, so the crossover is measured on one shape only.Follow-ups (separate)
docs/hrx.md: the decode-split section's "as fast or faster" table and its ctx-2100 rows describe the pre-multipass dispatch; update to the capped behaviour.