Skip to content

hrx: cap the decode-split FA just below its measured crossover (engine#679) - #429

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/i679-decode-split-capacity
Nov 19, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/i679-decode-split-capacity

Conversation

@bong-water-water-bong

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

Copy link
Copy Markdown

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-libs reduce_fused providers only serve 32 partial KV blocks = 2048 tokens with the cooperative reducer; everything above that runs reduce_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_wmma up 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 arbitrary key_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:

d A split tok/s B general tok/s A/B
0 75.79 75.51 1.004
2048 59.84 55.87 1.071
2304 57.44 (rev 58.33) 53.63 (rev 53.95) 1.071
3072 49.10 (rev 49.64) 49.43 (rev 49.57) 0.993 (rev 1.001)
3584 45.50 (rev 45.03) 46.78 (rev 46.22) 0.973
4096 40.66 (rev 41.44) 43.96 (rev 43.92) 0.925
8192 22.25 31.78 0.700
16384 10.41 (rev 10.06) 20.02 (rev 19.98) 0.52

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 2048 row 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:

d A cap-active B matcher disabled A/B what it shows
2048 59.51 (sd 1.19) 55.60 (sd 0.55) 1.070 cap keeps split; matches the frozen split reference 59.17
2304 58.13 (sd 1.14) 53.85 (sd 0.32) 1.080 cap keeps the multipass arm in the 2048-2944 band
3072 49.25 (sd 0.68) 49.67 (sd 0.09) 0.992 above the cap, both are the general kernel
4096 43.88 (sd 0.55) 44.20 (sd 0.58) 0.993 above the cap, both are the general kernel

-r 3, same claim/window, final binary libggml-hrx.so.0 71da9653... (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-ops CPU-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...wmma and ...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 broad flash_attention run 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.multipass is 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

  • The mechanism of the multipass slowdown: measured as cost, not profiled.
  • The engine#679 headline row (Qwen3.8-Flash-Next at 18.8k) is not re-measured here; this is a dispatch-policy change measured on a dense-attention probe.
  • The 2048-2944 band still runs the multipass arm, and the crossover is shape-dependent (the reducer gets one workgroup per KV head): 2944 is measured on an 8-KV-head shape, not derived per model. A parallel reducer (the corpus ships an unused two-dispatch produce/reduce variant) or a shape-aware bound is the follow-up.
  • Not independent of the corpus: the kept 2049-2944 band is served by reduce_completed.multipass; if a future corpus sync drops that provider (as 51e538fa0 found once after an AMD sync), those capacities hit the engine#115 all_rejected hard failure instead of falling back. The kv=2304 row is the tripwire, and hw-gate does not run test-hrx-ops by default.
  • No model-level logit A/B at depth: llama-bench times 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.
  • Not measured on a second shape: the frozen Qwen3-Coder-30B-A3B arm 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)

  • engine pin bump to the merge commit.
  • engine 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.
  • engine#2870's 13 test-expectation rows (same file, different lines, unaffected by this cap - all their capacities are <= 1024).

…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
bong-water-water-bong merged commit f2c91cc into 1bit/hrx-vulkan-patched Nov 19, 2026
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/i679-decode-split-capacity branch November 19, 2026 06:34
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).
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