Repository navigation
Conversation
… GQA ratio 6 With a GQA ratio of 6 (Bonsai 2 27B and Qwen3.5: 24 Q heads on 4 KV heads) the dispatcher picks ncols2 = 8, so two of the eight head slots of every MMA tile are padding, which is 25 % of the MMA work of the attention kernel. For many query tokens (Q->ne[1] >= 64, prompt processing) ncols2 = 2 computes without padding and the repeated K/V loads cost less than the saved MMA work. Decode and MTP verify (few tokens) keep ncols2 = 8; in a first trial without the token threshold decode lost 12 % at 32k depth and 26 % at 96k. RTX 4070, Ternary-Bonsai-2-27B PTQ1_0 + MTP head, q4_0 K/V, base prism c96baf4, this commit alone: llama-bench pp2048 (-ub 512, 2 runs each, A B B A) 1363.1 -> 1361.3 tok/s at depth 0 (-0.1 %), 960.7 -> 1027.7 at depth 32768 (+7.0 %), 576.8 -> 661.7 at depth 98304 (+14.7 %); llama-server prefill of 114688 tokens 157.4 -> 143.2 s (-9.0 %). Decode kernels are unchanged: MTP decode in 8 interleaved A/B pairs 115.97 -> 115.98 tok/s (+0.00 %, CI [-0.04, +0.03] %), outputs identical. Batches below 64 tokens are bit-identical; large batches change by float rounding: KL divergence against the previous kernel 0.00077 (16x512) and 0.00071 (4096 tokens per batch), perplexity 14.5263 against 14.5316. tests: flash attention cases for GQA ratio 6 with head size 256, 1 to 512 query tokens, f16/q8_0/q4_0 K/V (FLASH_ATTN_EXT 4401/4401 on CUDA0). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
sb32445
force-pushed
the
pr/fattn-gqa6-prefill
branch
from
October 27, 2026 19:09
979e2bd to
de1ed8b
Compare
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.
Overview
With a GQA ratio of 6 (Bonsai 2 27B and Qwen3.5: 24 Q heads on 4 KV heads) the MMA flash attention dispatcher picks
ncols2 = 8, so two of the eight head slots of every MMA tile are padding (25 % of the MMA work of the attention kernel). For prompt batches (Q->ne[1] >= 64)ncols2 = 2computes without padding, and the repeated K/V loads cost less than the saved MMA work. Decode and MTP verify (few tokens) keepncols2 = 8; without the token threshold decode lost 12 % at 32k depth and 26 % at 96k, so the threshold matters.RTX 4070, Bonsai 2 27B PTQ1_0 + MTP head, q4_0 K/V:
llama-benchpp2048 (-ub 512) +7.0 % at depth 32768 and +14.7 % at depth 98304,llama-serverprefill of 114688 tokens 157.4 -> 143.2 s (-9.0 %). Depth 0 and decode are unchanged.Additional information
fattn.cu(oneifbefore the existinggqa_ratio > 4branch) plus 54 newFLASH_ATTN_EXTtest cases (head size 256, GQA ratio 6, 1 to 512 query tokens, f16/q8_0/q4_0 K/V).Q->ne[1] >= 64are affected; every other model/shape takes the old path.Test results
-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89.prismatc96baf4ab, this commit only (separate builds of base and patch, build 10827 / 10828).llama-bench -p 2048 -n 0 -ub 512 -d 0,32768,98304 -r 2, two runs per build in the order base, patch, patch, base):(tok/s, mean of two runs; run-to-run spread ≤ 0.6 %.)
llama-server, MTPn-max 2, 114688-token prompt): 157.4 -> 143.2 s (-9.0 %); at 32k 30.2 -> 29.1 s.--spec-draft-n-max 2, 4 greedy prompts x 256 tokens, 8 interleaved A/B pairs, paired difference with 95 % bootstrap interval): 115.97 -> 115.98 tok/s, +0.00 % (CI [-0.04, +0.03] %), outputs identical, acceptance 74.0 % in both.test-backend-ops test -b CUDA0 -o FLASH_ATTN_EXT: 4401/4401 passed (4347 existing + 54 new);-o MUL_MAT: 1669/1669.Requirements
🤖 Generated with Claude Code