Repository navigation
ggml-hrx: cap the decode-split flash-attention dispatch at the kernel's real capacity (engine#115) - #9
Merged
bong-water-water-bong merged 1 commit intoSep 26, 2026
Conversation
…'s real capacity engine#115: a decode step with a long enough KV cache (key_value_token_capacity > 2048, e.g. a ~3800+ token prompt) failed with "Compute error." / "Loom compilation failed ... select-templates cannot resolve template.apply against template family <ggml.flash_attention.decode_split.reduce_fused>: all_rejected". The dispatch matcher (match_decode_split_flash_attention_f32_f16) accepted any key_value_token_count up to 262144 (is_supported_decode_key_value_token_count), but the loom-libs kernel corpus's decode-split reduce ONLY has two template.def<@ggml.flash_attention.decode_split.reduce_fused> implementations: one for key_value_token_capacity 64-256, one for 257-2048. Nothing covers above 2048. The 2048 ceiling is a real limit, not an oversight: the cooperative reducer gives one subgroup lane per partial KV block (capped at 32) and its per-workgroup scratch buffer (scale_stage, alloca<workgroup> 4x32x2xf32) is sized for exactly 32 blocks x 64 tokens. So the matcher was offering a dispatch the kernel corpus cannot actually serve past 2048, and the kernel selector's "all_rejected" failed the whole decode. Fix: reject the match once the padded key_value_capacity exceeds 2048, matching the kernel's real coverage. This dispatch has priority 75 in the registry; the general flash_attention_f32_f16_wmma dispatch (priority 50, already correct for arbitrary key_value_token_count, just not split-parallelized) is registered right below it for the same op (GGML_OP_FLASH_ATTN_EXT) and takes over automatically once decode-split declines - no new kernel, no fallback to another backend, no scope beyond a dispatch-matcher bound. Verified end to end on Strix Halo (gfx1151), Qwen3-Coder-30B-A3B-Instruct- Q4_K_M, HRX0 alone and the engine#108 HRX0/Vulkan0 split: - The exact failing case (4718 prompt tokens, key_value_token_capacity 4864) now decodes correctly: a code word buried in the document is retrieved exactly right, on both configs. - 3587 tokens: same, correct. - 1470 tokens (below the 2048 boundary, still uses decode-split): unchanged, correct - no regression. - Short prompts and a 3-turn conversation (name + two pet names + a synthesized story): unchanged, correct, on both configs. Not done: which dispatch actually served the long-context cases above was not instrumented (GGML_HRX_LOG_DISPATCH would confirm flash_attention_f32_f16_wmma took over as expected) - inferred from the registry priority order and the fact that decode simply works now. Not measured: relative decode speed above 2048 tokens (the fallback kernel is not split-parallelized, so it is expected to be slower than decode-split, not faster or equal). Co-Authored-By: Claude Sonnet 5 <[email protected]>
bong-water-water-bong
merged commit Sep 26, 2026
fa1a456
into
1bit/hrx-vulkan-patched
10 of 24 checks passed
bong-water-water-bong
deleted the
fix/hrx-decode-split-fa-capacity-bound-clean
branch
October 12, 2026 01:34
bong-water-water-bong
pushed a commit
that referenced
this pull request
Nov 19, 2026
…ves (engine#679) The decode-split matcher admitted padded key-value capacity up to 32768, but the loom-libs reduce providers only cover 32 partial blocks (2048 tokens) with the cooperative reducer; 2049 and above is served by ggml.flash_attention.decode_split.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 with the two-file patch applied to the bench tree at 4df0f3e (the dispatch file is byte-identical between the base commit 17fc2a3 and 4df0f3e), Qwen3-4B-Q4_K_M, llama-bench -p 0 -n 128 -r 2 -fa on, split-on and general arms interleaved in one gpu-hold claim, tok/s split/general: d=2048 59.84 / 55.87 split +7.1% 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% The crossover is the cooperative provider's ceiling: the split dispatch only wins with capacity <= 2048 and loses on every multipass capacity measured. The general ggml_flash_attention_f32_f16_wmma is correct for arbitrary key_value_token_count (it already serves prefill), just not split-parallelized. Cap the matcher at that ceiling so capacities above 2048 fall through to the general dispatch, and add test-hrx-ops rows at kv=2048 (split still selected) and kv=4096/16384 (general selected) against the CPU reference: no committed case reached a capacity above the cooperative ceiling, so nothing exercised the multipass arm. The same bound was accepted before the multipass provider existed (#9, 2026-09-26); this re-applies it with the measurement and the depth tests that decision lacked. engine#679
bong-water-water-bong
pushed a commit
that referenced
this pull request
Nov 19, 2026
…ves (engine#679) The decode-split matcher admitted padded key-value capacity up to 32768, but the loom-libs reduce providers only cover 32 partial blocks (2048 tokens) with the cooperative reducer; 2049 and above is served by ggml.flash_attention.decode_split.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 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 2048, and the patched build reproduces it. Tok/s split/general: d=2048 59.84 / 55.87 split +7.1% 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% The crossover is the cooperative provider's ceiling: the split dispatch only wins with capacity <= 2048 and loses on every multipass capacity measured (4096/8192/16384). The general ggml_flash_attention_f32_f16_wmma is correct for arbitrary key_value_token_count (it already serves prefill), just not split-parallelized. Cap the matcher at that ceiling so capacities above 2048 fall through to the general dispatch, and add test-hrx-ops rows at kv=2048 (split still selected) and kv=4096/16384 (general selected) against the CPU reference: no committed case reached a capacity above the cooperative ceiling, so nothing exercised the multipass arm. The same bound was accepted before the multipass provider existed (#9, 2026-09-26); this re-applies it with the measurement and the depth tests that decision lacked. engine#679
bong-water-water-bong
pushed a commit
that referenced
this pull request
Nov 19, 2026
…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
added a commit
that referenced
this pull request
Nov 19, 2026
…e#679) (#429) 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 Co-authored-by: bong-water-water-bong <[email protected]>
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.
What
Fixes
1bit-MONSTER/engine#115: a decode step with a long enough KV cache (key_value_token_capacity > 2048, e.g. a ~3800+ token prompt) failed with:Cause
The dispatch matcher (
match_decode_split_flash_attention_f32_f16) accepted anykey_value_token_countup to 262144, but theloom-libskernel corpus's decode-split reduce has exactly twotemplate.def<@ggml.flash_attention.decode_split.reduce_fused>implementations - one for capacity 64-256, one for 257-2048. Nothing covers above 2048.The 2048 ceiling is a real limit, not an oversight: the cooperative reducer gives one subgroup lane to each partial KV block (capped at 32), and its per-workgroup scratch buffer is a fixed
4x32x2xf32allocation - sized for exactly 32 blocks x 64 tokens. The matcher was offering a dispatch the kernel corpus can't serve past that, and the kernel selector's "all_rejected" failed the whole decode instead of falling back.Fix
Reject the match once the padded
key_value_capacityexceeds 2048. This dispatch has priority 75 in the registry;flash_attention_f32_f16_wmma(priority 50, already correct for arbitrarykey_value_token_count, just not split-parallelized) is registered for the same op and takes over automatically once decode-split declines. No new kernel, no cross-backend fallback, no scope beyond a dispatch-matcher bound - I looked into a proper multi-pass reduction kernel first (see the issue) and this bounds fix is safer and sufficient: it makes existing capability reachable instead of adding new capability.Verified end to end (Strix Halo gfx1151,
Qwen3-Coder-30B-A3B-Instruct-Q4_K_M)key_value_token_capacity4864): now correct, on-dev HRX0alone and on theengine#108HRX0/Vulkan0split - a code word buried in the prompt is retrieved exactly right in both.Not done
GGML_HRX_LOG_DISPATCH=1would confirmflash_attention_f32_f16_wmmatook over) - inferred from the registry priority order plus the fact that decode now works correctly.engine#115for whoever wants that speed later.🤖 Generated with Claude Code