Repository navigation
[w2] fa-decode-quant-kv: v_perm dequant, opt-in KV split cap and tile GQA padding for quantized decode - #173
Merged
Merged
Conversation
…nd tile GQA padding for quantized decode - flash_attn_load_tile_quant: on HIP the half path (8 values per chunk) puts the bytes under 0x64 with v_perm and subtracts the offset, the values are bit-identical to the int8 -> half -> * d path - GGML_CUDA_FA_DECODE_SPLIT_CAP=<n> (opt-in): at most n blocks per CU for RDNA3 decode (nb <= 8) with quantized K/V - GGML_CUDA_FA_TILE_GQA_PAD=1 (opt-in): GQA 3 -> 4 and 5/6/7 -> 8 in the direct quantized K/V tile path, padded Q columns are zeroed and their dst/meta/sink accesses skipped; the tile kernel derives head0 from gridDim.z at run time - test-backend-ops: eval cases nb 1..8 with GQA 3/6/7 (q8_0, q4_0, q8_0-q4_0, D256/512, sinks) and perf cases nb=1 at 32k/96k Assisted-by: Claude Sonnet 5.5
Owner
Author
|
Reverted from master on 2026-12-04 (w2 build crashed Qwen4-single at >20k ctx; no measured gain). Commit preserved on branch archive/w2-25f0def; will be re-landed individually after GPU validation. |
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 / why
Decode attention with q8_0/q4_0 K/V on RDNA3 (Gemma, Qwen3.8, Qwen4 with dense attention) goes through the direct-dequant tile kernel (
flash_attn_tile, nb <= 8, D256/D512). About 450 VALU per KV tile went to dequantization, and GQA 6 (Qwen3.8: 24 heads / 4 KV heads) launched 3 blocks per KV head that each dequantize the whole head. Three changes:flash_attn_load_tile_quantuses the variant F body fromkern-survey-variants-A-F.patch(hunks 1-2 only, no streamk hunk): bytes placed under 0x64 withggml_hip_perm, offset subtracted, scaled by d. Same values as int8 -> half ->* d. Only the dequant body is touched (the row index / oob part is left alone for qwen4-qsa-sparse-fa).GGML_CUDA_FA_DECODE_SPLIT_CAP=<n>(opt-in). Inlaunch_fattn's parallel-blocks branch: RDNA3_0,Q->ne[1] <= 8, quantized K or V, not sparse:parallel_blocks = min(parallel_blocks, n*nsm / ntiles_dst). Unset keeps today's behaviour. Changes the combine order slightly. Note it only has an effect when the current selection exceeds n blocks per CU in total (e.g. cap 1, or many-tile launches), so tonight's sweep also tells whether 2/4 matter at all.GGML_CUDA_FA_TILE_GQA_PAD=1(opt-in).launch_fattn_tile_switch_ncols2: for quantized K/V and nb <= 8, GQA 3 -> ncols2 4, GQA 5/6/7 -> ncols2 8 (existing instances, no new template). The tile kernel now derivessequence/head_kv/head0fromgridDim.zandgqa_ratioat run time (identical values whengqa % ncols2 == 0), zeroes padded Q columns, and skips their Q read, sink read, dst and meta writes. Model check (GGUF headers): Qwen3.8 24/4 = GQA 6 (benefits), Gemma 32/16 and 32/4, MiniCPM5 32/2 = GQA 16 (f16 path), Qwen4 16/2 = GQA 8 (already aligned), Nemotron-Bolt 8/2 = GQA 4.Not done: the D512 "V is a view of K, keep the dequantized K tile in LDS" stretch (needs LDS/occupancy measurement on the GPU first). The Inkling D128 bias route was skipped as planned (GGUF no longer on disk).
Expected gain (estimate, not measured)
Scout estimate: tg +4-7% at 32k and +12-25% at 90-96k for q8_0 K/V models. Static ISA (below) supports roughly -25% VALU on the decode instances.
Compile / static checks (no GPU used)
fattn.cu.o,fattn-tile-instance-f16-f16-dkq256-dv256.cu.o,...dkq512-dv512.cu.o. CPU build oftest-backend-opsclean; the new perf case runs on the CPU backend.Summed over all 34 quantized instances of the file: VALU 153937 -> 127624 (-17%), v_bfe 8736 -> 102, v_cvt_f16 9093 -> 453, v_mov_b16 8569 -> 60. VGPR counts drop or stay equal on the decode instances (e.g. <1,2> q8_0/q4_0 228 -> 186). Spills: pre-existing spills in the large-ncols instances (<32,1>, <4,8>, <8,4>) are unchanged or removed, except two <4,8> q8_0-q4_0 / <8,4> q8_0-q4_0 mixed instances going from 14-15 to 17-18 spilled VGPRs and <16,2> q4_0 getting 3 spilled VGPRs (unused: direct path only runs for nb <= 8, <16,2> is a 32-column prompt tile on the converted-f16 path).
Switches
GGML_CUDA_FA_DECODE_SPLIT_CAP=<n>(opt-in, numerics change slightly).GGML_CUDA_FA_TILE_GQA_PAD=1(opt-in).Files
ggml/src/ggml-cuda/fattn-common.cuh,ggml/src/ggml-cuda/fattn-tile.cuh,tests/test-backend-ops.cpp(eval: nb 1..8 with GQA 3/6/7, D256/512, q8_0, q4_0, q8_0-q4_0, sinks, 1 KV head, 2 sequences; perf: nb=1 at kv 32768 / 98304, GQA 6/8/2, in commented[w2 fa-decode-quant-kv]blocks).Risks
flash_attn_load_tile_quantandfattn-tile.cuh(kernel head0/sequence lines).GPU validation tonight (NOT YET RUN)
Preamble (P) from the wave plan.
Assisted-by: Claude Sonnet 5.5