Repository navigation
ggml-hrx: run prompt flash attention above 2048 query rows as query chunks (engine #390) - #120
Merged
bong-water-water-bong merged 1 commit intoOct 21, 2026
Conversation
…hunks (engine #390) The Loom prompt kernel ggml_flash_attention_f32_f16_wmma launches at most 2048 query rows, so the matcher refused larger batches and FLASH_ATTN_EXT went to the CPU: Qwen3.8-27B UD-Q4_K_XL llama-bench pp4096 at -ub 4096 ran at 6.5 tok/s. The matcher now takes up to kUbatchMaxTokens and emits ceil(T / 2048) equal chunks of query rows; each chunk binds its rows of Q, mask, gate and output and all of K and V. New files dispatch-query-chunks.{h,cpp} (ours); two call sites in dispatch-flash-attention.cpp. GGML_HRX_QUERY_CHUNK_TOKENS=<n> forces smaller chunks (test switch). Measured on strixhalo gfx1151, performance mode, with gpu-kernels 1bit/prefill-large-m: 27B pp4096 -ub 4096 6.5 -> 588.5 tok/s (pp2048 -ub 4096 590.1). 27B llama-perplexity -c 4096 --chunks 2 against the base build at -ub 2048: new -ub 2048 mean KLD 0.000000, same top 99.976%; with GGML_HRX_QUERY_CHUNK_TOKENS=1024 identical; =700 (chunks not 16-row aligned) mean KLD 0.000071, max 0.0023. New -ub 4096 vs that base: mean KLD 0.00194, max 0.232, same top 97.9%, PPL 6.7089 vs 6.7183. Explained (2026-10-21): the difference is not in attention. At up to 2048 tokens the gate/up SwiGLU of the Q5_K/IQ4_XS layers runs common.mul_mat_swiglu_q5_projection.symmetric_i4_q8_plane, which quantizes the activations to symmetric int4; its matcher stops at 2048 tokens, so -ub 4096 takes the exact f16 HIP dense SwiGLU. With that matcher disabled at -ub 2048 (GGML_HRX_DISABLE_DISPATCH=symmetric_i4) the KLD against -ub 4096 is 0.000003 (max 0.00086, PPL 6.7097 vs 6.7089); disabling only the q8_1 SwiGLU leaves it at 0.001946. So -ub 4096 is the more accurate of the two. Co-Authored-By: Claude Opus 5.5 <[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.
The Loom prompt kernel ggml_flash_attention_f32_f16_wmma launches at most 2048
query rows, so the matcher refused larger batches and FLASH_ATTN_EXT went to the
CPU: Qwen3.8-27B UD-Q4_K_XL llama-bench pp4096 at -ub 4096 ran at 6.5 tok/s.
The matcher now takes up to kUbatchMaxTokens and emits ceil(T / 2048) equal
chunks of query rows; each chunk binds its rows of Q, mask, gate and output and
all of K and V. New files dispatch-query-chunks.{h,cpp} (ours); two call sites
in dispatch-flash-attention.cpp. GGML_HRX_QUERY_CHUNK_TOKENS= forces smaller
chunks (test switch).
Measured on strixhalo gfx1151, performance mode, with gpu-kernels
1bit/prefill-large-m: 27B pp4096 -ub 4096 6.5 -> 588.5 tok/s (pp2048 -ub 4096 590.1).
27B llama-perplexity -c 4096 --chunks 2 against the base build at -ub 2048:
new -ub 2048 mean KLD 0.000000, same top 99.976%; with GGML_HRX_QUERY_CHUNK_TOKENS=1024
identical; =700 (chunks not 16-row aligned) mean KLD 0.000071, max 0.0023.
New -ub 4096 vs that base: mean KLD 0.00194, max 0.232, same top 97.9%,
PPL 6.7089 vs 6.7183. Explained (2026-10-21): the difference is not in attention.
At up to 2048 tokens the gate/up SwiGLU of the Q5_K/IQ4_XS layers runs
common.mul_mat_swiglu_q5_projection.symmetric_i4_q8_plane, which quantizes the activations
to symmetric int4; its matcher stops at 2048 tokens, so -ub 4096 takes the exact f16 HIP
dense SwiGLU. With that matcher disabled at -ub 2048 (GGML_HRX_DISABLE_DISPATCH=symmetric_i4)
the KLD against -ub 4096 is 0.000003 (max 0.00086, PPL 6.7097 vs 6.7089); disabling only
the q8_1 SwiGLU leaves it at 0.001946. So -ub 4096 is the more accurate of the two.
Rebased on 5dcf662 (the earlier branch 1bit/fa-prompt-query-chunks carried three commits that have since landed). Our code is in new files (dispatch-query-chunks.{h,cpp}); the hooks are two call sites in dispatch-flash-attention.cpp and the CMake list.
🤖 Generated with Claude Code