Repository navigation
Conversation
The QSA prefill kernel took only GQA 12 (Qwen3.8-Flash-Next). Qwen4-35B-A3B has 16 query heads over 2 KV heads, so past the indexer budget every full-attention layer's selected-key attention fell back to the CPU. The kernel is templated on the GQA ratio: a group of 4 queries is 4*GQA rows, 3 WMMA tiles at GQA 12 (unchanged) and 2 at GQA 8. Assisted-by: Claude Code
With a q8_0 cache the selected-key probe failed (both QSA kernels took f16 K/V only), so every qwen4exp QSA layer built the masked top-k route: a [n_kv, n_tokens] mask and dense attention, which grows with the depth. - decode: the scalar kernel reads K/V rows as f16 or q8_0 (lane l of dim block d is element l of q8_0 block d). The WMMA kernel stays f16. - prefill: a q8_0 K or V is converted to contiguous f16 first, then attended by the f16 kernel. Assisted-by: Claude Code
Nathanw1014
approved these changes
Dec 4, 2026
Nathanw1014
left a comment
There was a problem hiding this comment.
Looks good, thanks. I read through the GQA templating, the q8_0 prefill conversion and the q8_0 decode lane mapping, and they check out.
Small, non-blocking notes:
qsa-prefill.cu:556-571: when only one of K/V is q8_0, the f16 one is also given fake contiguous strides anddata = nullptrin the recursive check, so its real stride and alignment checks are skipped. Rewriting only the quantized tensor would keep them.qsa-prefill.cu:255: thestatic_assertallows NT 1..8, butpart[NT][8][64]is too small for the 16 KiB output staging at NT = 1 (GQA 4). Only 8 and 12 are instantiated, so this is latent. Tightening the assert (or sizingpartas max(NT, 2)) would guard it.qsa-prefill.cu:661-680: q8_0 converts the whole cache to f16 per layer per ubatch. That's fine at pp2048. Small ubatches at deep context might feel it.- A
QSA_DECODE_MASKLESSq8_0 case at GQA 8 (Qwen4's decode shape) would be nice. The q8_0 decode cases are GQA 12/4 only.
This branch has not been deployed
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
Qwen4-35B-A3B (#343) loads and runs, but on HIP its prefill falls off a cliff past the QSA budget: pp2048 is 409 t/s at
128k depth against 3006 at depth 0. Two gaps in the HIP QSA kernels cause it, both specific to this model's shape and
cache type:
qsa_prefilltakes only GQA 12 (Qwen3.8-Flash-Next: 24 query heads over 2 KV heads). Qwen4-35B-A3Bhas 16 over 2. Once the cache holds more than
indexer_top_k + ratio - 1cells, every full-attention layer'sselected-key attention is rejected by ROCm0 and the scheduler runs it on the CPU (10 CPU splits per ubatch).
-ctk q8_0 -ctv q8_0the selected-key probe inllama_memory_hybrid_idxfails and every QSA layer builds the masked top-k route (a[n_kv, n_tokens]mask anddense attention), which grows with the depth.
What's in it
qsa_prefill: the attention kernel is templated on the GQA ratio. A group of 4 queries is4*GQArows: 3 WMMAtiles at GQA 12 (the existing code path) and 2 at GQA 8. The merge kernel and the 16-bit block masks are unchanged.
qsa_prefill: a q8_0 K or V is converted to contiguous f16 (ggml_get_to_fp16_nc_cuda), then attended by the f16kernel.
qsa_decode: the scalar kernel reads K/V rows as f16 or q8_0 (lanelof dim blockdis elementlof q8_0block
d). The WMMA kernel stays f16 / GQA 12.test-backend-ops: GQA 8 cases forQSA_PREFILLandQSA_PREFILL_MASKLESS(incl. 2048 queries over 131072 keys),and q8_0 K/V cases at GQA 8 and 12.
HIP only. Vulkan, CUDA and the llama/ graph code are not touched.
Measurements
The q8_0 master cell at 128k was not run; at 32k the q8_0 path on master is the masked route described above.
Correctness
test-backend-ops -b ROCm0:QSA_PREFILL32/32,QSA_PREFILL_MASKLESS31/31,QSA_DECODE92/92,QSA_DECODE_MASKLESS56/56,FLASH_ATTN_EXT4387/4387.tests/corpusfiles concatenated,-c 8192 -b 2048 -ub 2048(so most positions arepast the QSA budget). Reference: master at ub2048, which runs these layers on the CPU (f16 KV) or on the masked
route (q8_0 KV).
LLAMA_QSA_SELECTED_KEY=0), f16 KVThe PR's difference against master is the difference between GPU (f16 WMMA) and CPU attention: the GPU dense
masked route, which does not use the changed kernels, lands at the same KLD and top-1. PPL is equal within the error.
Not tested
test cases pass, but no model run.
--parallel > 1beyond the existing multi-stream prefill test case.AI usage: the changes, measurements and this description were produced by an AI agent (Claude Code) under my direction, on my box.
🤖 Generated with Claude Code
https://claude.ai/code/session_0177uRMCLjJEx8S8sE4dQeXo