Repository navigation
qwen4exp : maskless block selection with a quantized K/V cache - #271
Conversation
The block selection asked for an f16 K and V cache, and the probe op used f16 tensors whatever the cache held. The probe now also runs with the cache K/V types and the gate drops the f16 test, so a backend whose QSA kernels take the quantized op runs the maskless path; a backend that refuses it (HIP today, which reads f16 K/V only) keeps the masked top-k. The log names the cache types and why a cache stays masked. An f16 cache takes the same route as before. Assisted-by: Claude Opus 5.5
dzannotti
left a comment
There was a problem hiding this comment.
Verdict
This looks good to merge. With a q8_0 K/V cache, Vulkan now takes the maskless selected-key route. The f16 route and ROCm stay byte-identical to master, and the q8_0 output stays inside the noise floor. It needs one maintainer approval because it changes the attention route for every qwen4exp user on Vulkan with a quantized cache.
Direction
Accept. The prefill gain on long contexts is large and real. The change is 2 fork-only files with a small gate. This gate is the one to keep. The {1, 513} query-width probe from the closed #219 is worth adding to it (ask 2). Draft #276 rewrites the same gate, so it will need a rebase after this lands.
Asks
- Should fix.
src/llama-memory-hybrid-idx.cpp:128-137: withLLAMA_QSA_SELECTED_KEY=0, the log says "masked top-k (K/V cache q8_0/q8_0: no selected-key kernels for this type)". The kernels exist; the variable turned them off. Please log the override as the reason (for example "forced by LLAMA_QSA_SELECTED_KEY"), and also say so when=1forces the path on. - Should fix.
src/llama-memory-hybrid-idx.cpp:54: the typed probe asks only for 1 query. Today this is safe, because the Vulkan check does not depend on the query count and HIP refuses quantized K/V at every width. But HIP has a decode kernel (1..512 queries) and a prefill kernel (>= 128 queries, GQA 12). If one of them gets quantized K/V support and the other does not, a 1-query probe passes and prefill silently runs attention on the CPU. Please probe the typed op at 1 and 513 queries, as #219 did. Keep the f16 probe as it is, so that the f16 route does not change. - Should fix. The PR description says the PR "alone changes nothing on Vulkan". That is no longer true, because the Vulkan kernels are on master now. Please update it, and say that
LLAMA_QSA_SELECTED_KEY=1with a quantized cache on ROCm now runs the attention op on the CPU (correct output, but prefill about 45% slower in our short test). Before this PR, the graph gate kept that case masked.
Nits: src/models/qwen4exp.cpp:1099 is one 185-column line inside a wrapped comment block, and "single stream" at :1097 is stale (split streams are allowed).
Correctness
PASS on Vulkan and ROCm (target checks). We compared master with the PR merged into master on a qwen4exp model:
- f32 final logits and prompt token IDs: byte-identical on all four corpora for f16 K/V (Vulkan and ROCm), for q8_0 K/V on ROCm (HIP_LAUNCH_BLOCKING unset and =1), and for q8_0 on Vulkan with
LLAMA_QSA_SELECTED_KEY=0. - Vulkan q8_0, maskless (PR) against masked (master), both scored against f16 K/V: Mean KLD differs by -0.0002 to +0.0003 on the four corpora at -c 4096. The noise floor is 0.002-0.006. The long case (-c 16384) gives 0.002357 on both sides.
- Greedy decode: stable A/A, byte-identical for f16 on both backends and for q8_0 on ROCm. On Vulkan q8_0, the PR's output on one corpus now matches the f16 output exactly, and master's output does not.
- Two sequences per batch (llama-perplexity -c 4096 -b 8192): f16 gives the same PPL on master and the PR on both backends, and so does q8_0 on ROCm. On Vulkan, q8_0 goes from 7.1097 to 7.1038.
- test-llama-archs and test-llama-context pass on both sides. Ubatch 512, 2048 and 8192 with q8_0 run with no abort and no extra graph splits.
- Not run: the full test-backend-ops suites and ctest (the PR changes no ggml code).
Performance
Vulkan, q8_0 K/V, llama-bench, 2 rounds alternated, -r 3, mean t/s. f16 K/V and ROCm are unchanged (within 0.2%).
| test | master | PR | spread (max stddev) | change |
|---|---|---|---|---|
| pp2048 d0 | 1138.1 | 1109.0 | 34 | -2.6% (noise, same code at d0) |
| pp2048 d8192 | 709.2 | 1038.3 | 8 | +46.4% |
| pp2048 d12000 | 671.9 | 1031.3 | 12 | +53.5% |
| pp2048 d32768 | 459.4 | 999.9 | 14 | +117.7% |
| pp2048 d64000 | 368.1 | 956.2 | 9 | +159.8% |
| pp8192 d0 (ub 8192) | 878.2 | 1112.0 | 10 | +26.6% |
| tg32 d32768 | 27.10 | 28.67 | 0.6 | +5.8% |
| tg128 d0 | 31.60 | 31.73 | 0.4 | +0.4% |
Verification
Strix Halo (gfx1151), Vulkan (RADV) and ROCm. We tested the PR merged into master 093c552 (the PR was 44 commits behind; the merge was clean) against master. The model was a qwen4exp TQ2_0 GGUF, not the UD-Q4_K_XL from the description, so the absolute t/s differ from yours.
Not tested
The PR's exact model file, the full test-backend-ops suites, ctest, and multi-sequence greedy decode.
Thank you for the clean, well-scoped change.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
- Ubuntu 26.04.1 LTS, kernel 7.0.0-43-generic, Strix Halo (Radeon 8060S, gfx1151), 128 GB unified memory.
- ROCm 10.1, hipconfig 7.16.26385, AMD clang 24.0.0git d6f6cb69.
- Mesa RADV 26.0.8 (KHR_coopmat). cmake 4.2.3, gcc 15.2.0, Ninja.
Compared
- master tip (base): 093c552
- PR head: 1d5bb5a
- PR merged into master (head side, local, not pushed): 01871fbc8cefc053fe889c448523b2d9ab6c281e, clean merge
- merge base: 62a3f41, 44 commits behind master
- The merged diff has the same lines as the PR diff.
Build
Identical flags for both trees:
cmake -S <tree> -B <tree>/build-vk -DCMAKE_BUILD_TYPE=Release -G Ninja -DGGML_VULKAN=ON -DGGML_HIP=OFF
cmake -S <tree> -B <tree>/build-hip -DCMAKE_BUILD_TYPE=Release -G Ninja -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R)
cmake --build <tree>/build-<be> -j --target test-backend-ops test-llama-archs test-llama-context llama-perplexity llama-tokenize llama-bench llama-debug llama-completion llama-cli [test-vk-exact]
Models
- Target: agentionai/Qwen3.8-Flash-Next-Gyro-GGUF,
Qwen3.8-Flash-Next-Gyro-M-TQ2_0.gguf, sha256 7aa36d15131d255179ab6c87fa9c9f81a0b541fc9e81e959d4c3e29eb20feb5f. Arch qwen4exp, 48 layers, 12 QSA layers (compress ratio 4), n_head 24, n_head_kv 2 (GQA 12), head dim 256, indexer top_k 2048. Every run used-lm none -lzm on-direct. - test-llama-context: Qwen2.5-1.5B-Instruct
qwen2.5-1.5b-instruct-q4_k_m.gguf, sha256 6a1a2eb6d15622bf3c96857206351ba97e1af16c30d7a74ee38970e434e9407e. - Corpora (base tree): code dec1127a... (11089 tokens), numeric d9f08d94... (12952), prose c90398f2... (12386), structured c21947b3... (8682).
Commands
# route and logits, per backend x side x KV (f16, q8_0), plus head q8_0 with LLAMA_QSA_SELECTED_KEY=0; ROCm with HIP_LAUNCH_BLOCKING unset and =1
llama-debug -m <model> -f correctness-<t>.txt -c 16384 -b 16384 -ub 512 -ngl 99 -fa on -ctk <kv> -ctv <kv> -lm none -lzm on-direct --save-logits --logits-output-dir <dir>
cmp <base>/llamacpp-*.bin <head>/llamacpp-*.bin # logits and tokens bins
# KLD, reference = master with f16 K/V
llama-perplexity -m <model> -f <corpus> -c C -b C -ub 2048 -ngl 99 -fa on -ctk f16 -ctv f16 -lm none -lzm on-direct --kl-divergence-base ref.kld
llama-perplexity -m <model> -c C -b C -ub 2048 -ngl 99 -fa on -ctk <kv> -ctv <kv> -lm none -lzm on-direct --kl-divergence-base ref.kld --kl-divergence
# C = 2048 and 4096 per corpus; long: 4 corpora joined, -c 16384 -b 512 -ub 512; floor = master f16 at another ubatch
# wide ubatch
llama-perplexity -m <model> -f <joined> -c 8192 -b 8192 -ub 8192 --chunks 2 -ngl 99 -fa on -ctk q8_0 -ctv q8_0 -lm none -lzm on-direct
# greedy decode, master twice, then the PR
llama-completion -m <model> -f <corpus> -n 256 --temp 0 --seed 1 -no-cnv --ignore-eos -ngl 99 -fa on -c 16384 -ctk <kv> -ctv <kv> -lm none -lzm on-direct
# ROCm, forced path
LLAMA_QSA_SELECTED_KEY=1 llama-completion -m <model> -f <prose, first 11000 bytes> -n 32 -c 4096 -ub 512 -ngl 99 -fa on -ctk q8_0 -ctv q8_0 -lm none -lzm on-direct
# speed, one process per cell, round 1 master then PR, round 2 PR then master
llama-bench -m <model> -fa 1 -ngl 99 -r 3 -ctk <kv> -ctv <kv> -lm none -lzm on-direct -o jsonl -p 2048 -n 0 -b 2048 -ub 2048 -d 0,8192,32768
llama-bench ... -p 8192 -n 0 -b 8192 -ub 8192 -d 0
llama-bench ... -p 0 -n 128 -d 0,8192
llama-bench ... -p 0 -n 32 -d 32768
llama-bench ... -ctk q8_0 -ctv q8_0 -p 2048 -n 0 -b 2048 -ub 2048 -d 12000,64000 # order master, PR, PR, master
llama-bench ... -ctk f16 -ctv f16 -p 2048 -n 0 -b 2048 -ub 2048 -d 64000 # master, PR
# two sequences per batch, per backend x side x K/V
llama-perplexity -m <model> -f correctness-prose.txt -c 4096 -b 8192 -ub 2048 -ngl 99 -fa on -ctk <kv> -ctv <kv> -lm none -lzm on-direct
test-llama-archs -a qwen4exp ; test-llama-context -m <qwen2.5-1.5b> ; test-vk-exact
Results
Route (the "QSA attention:" log line) and graph splits:
| backend | side | K/V | logged route | route that ran | splits ub 512 / 2048 / 8192 |
|---|---|---|---|---|---|
| Vulkan | master | f16 | selected-key | maskless | 2 / 2 / - |
| Vulkan | PR | f16 | selected-key, f16/f16 | maskless | 2 / 2 / - |
| Vulkan | master | q8_0 | selected-key (wrong: the graph gate demanded f16) | masked | 2 / 2 / 3 |
| Vulkan | PR | q8_0 | selected-key, q8_0/q8_0 | maskless | 2 / 2 / 3 |
| Vulkan | PR | q8_0, SELECTED_KEY=0 | masked, "no selected-key kernels for this type" (wrong reason) | masked | 2 / - / - |
| ROCm | master | f16 | selected-key | maskless | 2 / 2 / - |
| ROCm | PR | f16 | selected-key, f16/f16 | maskless | 2 / 2 / - |
| ROCm | master | q8_0 | selected-key (wrong, as on Vulkan) | masked | 2 / 2 / - |
| ROCm | PR | q8_0 | masked, "no selected-key kernels for this type" | masked | 2 / 2 / - |
| ROCm | PR | q8_0, SELECTED_KEY=1 | selected-key, q8_0/q8_0 | maskless, attention on CPU | 26 / - / - |
f32 logits (llama-debug, -c 16384 -ub 512, whole corpora):
| comparison | prose | code | structured | numeric |
|---|---|---|---|---|
| Vulkan f16, master vs PR | identical | identical | identical | identical |
| Vulkan q8_0, master vs PR with SELECTED_KEY=0 | identical | identical | identical | identical |
| Vulkan q8_0, master (masked) vs PR (maskless), last-position max abs / KLD | 0.72 / 2.1e-4 | 0.66 / 2.7e-4 | 0.72 / 5.7e-3 | 1.59 / 3.2e-2 |
| ROCm f16, master vs PR, HLB unset and =1 | identical | identical | identical | identical |
| ROCm q8_0, master vs PR, HLB unset and =1 | identical | identical | identical | identical |
Token IDs are the same in every pair. A second full ROCm pass gave the same result for all 24 pairs.
KLD (Vulkan, reference master f16 K/V; Mean KLD / same top p %):
| case | floor | master q8_0 (masked) | PR q8_0 (maskless) | gate 2 x floor + 1e-4 |
|---|---|---|---|---|
| c4096 prose | 0.004740 / 96.53 | 0.004897 / 96.47 | 0.005160 / 96.29 | 0.009580 |
| c4096 code | 0.002017 / 99.05 | 0.002736 / 98.97 | 0.002534 / 99.02 | 0.004134 |
| c4096 structured | 0.005800 / 98.85 | 0.005744 / 98.73 | 0.005773 / 98.63 | 0.011700 |
| c4096 numeric | 0.003352 / 99.06 | 0.004916 / 98.97 | 0.005198 / 98.80 | 0.006804 |
| long, -c 16384 -ub 512 | 0.002304 / 98.72 | 0.002357 / 98.68 | 0.002357 / 98.80 | 0.004708 |
- At -c 2048 the PR's path does not run (block selection needs n_kv > top_k + ratio - 1 = 2051), so master and the PR give the same numbers there.
- PR f16 against the reference: Mean KLD 0.000000 everywhere.
- PPL ratio is within 0.997-1.004 in every case. There are no nan/inf values.
- Wide ubatch q8_0 (-ub 8192): master PPL 3.7553, PR 3.7497, both finish with no assert.
Greedy decode, 256 tokens:
| backend / K/V | corpus | master A/A | master vs PR |
|---|---|---|---|
| Vulkan f16 | prose, code | same | identical |
| Vulkan q8_0 | prose | same | differs at generated byte 23; the PR output equals the f16 output |
| Vulkan q8_0 | code | same | identical |
| ROCm f16 | prose | same | identical |
| ROCm q8_0 | prose | same | identical |
ROCm with LLAMA_QSA_SELECTED_KEY=1 and q8_0: master stays masked (pp 723.5 t/s, tg 23.30 t/s). The PR runs the attention op on the CPU (pp 399.0 and 354.1 t/s, tg 19.24 t/s), with no abort and coherent output.
Unit tests: test-llama-archs qwen4exp passes on both backends and both sides. test-llama-context 12 pass / 3 skip on both. test-vk-exact has the same 11 failing checks on master and on the PR (pre-existing, not related).
Correctness
| check | method | result |
|---|---|---|
| test-llama-archs (qwen4exp) | both backends, both sides | pass |
| test-llama-context | Qwen2.5-1.5B, both backends | pass (12/0), same on both sides |
| f32 logit parity, 4 corpora | llama-debug + cmp | f16 identical on both backends; ROCm q8_0 identical; Vulkan q8_0 identical with the override set to 0 |
| prompt token IDs | tokens bin cmp | identical |
| KLD/PPL short | llama-perplexity -c 2048 and -c 4096, 4 corpora | pass, inside the floor |
| KLD/PPL long | 4 corpora joined, -c 16384 | pass, equal |
| two sequences per batch | llama-perplexity -c 4096 -b 8192, prose | f16 equal PPL on both backends, ROCm q8_0 equal; Vulkan q8_0 7.1097 -> 7.1038 |
| greedy decode with A/A | llama-completion -n 256 | A/A stable; f16 and ROCm identical |
| ROCm HIP_LAUNCH_BLOCKING unset and =1 | llama-debug parity | identical in both settings |
| both backends | Vulkan and ROCm | done |
| full test-backend-ops, ctest | - | not run: no ggml change |
Performance
Raw avg_ts +- stddev_ts (Vulkan):
| K/V | test | master r1 | master r2 | PR r1 | PR r2 |
|---|---|---|---|---|---|
| f16 | pp2048 d0 | 1126.35+-29.00 | 1112.94+-38.49 | 1122.08+-31.62 | 1121.07+-24.80 |
| f16 | pp2048 d32768 | 1020.43+-2.50 | 1013.94+-1.55 | 1018.31+-0.64 | 1011.65+-5.68 |
| f16 | tg128 d0 | 31.91+-0.32 | 31.90+-0.35 | 31.95+-0.33 | 31.94+-0.32 |
| q8_0 | pp2048 d0 | 1163.99+-29.26 | 1112.19+-34.47 | 1112.29+-31.25 | 1105.76+-27.02 |
| q8_0 | pp2048 d8192 | 716.20+-7.93 | 702.11+-7.34 | 1038.57+-0.56 | 1038.01+-3.19 |
| q8_0 | pp2048 d32768 | 461.21+-12.12 | 457.49+-9.30 | 998.66+-7.17 | 1001.05+-14.40 |
| q8_0 | pp8192 d0 | 878.24+-1.93 | 878.13+-10.44 | 1112.02+-7.01 | 1111.99+-3.98 |
| q8_0 | pp2048 d12000 | 672.88+-11.67 | 670.87+-11.55 | 1034.13+-3.68 | 1028.37+-3.74 |
| q8_0 | pp2048 d64000 | 368.42+-9.37 | 367.74+-9.10 | 957.24+-2.30 | 955.18+-1.73 |
| f16 | pp2048 d64000 | 969.46+-4.90 | - | 968.42+-5.34 | - |
| q8_0 | tg128 d0 | 31.48+-0.31 | 31.73+-0.35 | 31.73+-0.38 | 31.73+-0.34 |
| q8_0 | tg128 d8192 | 29.75+-0.02 | 28.42+-0.09 | 28.67+-0.40 | 28.71+-0.50 |
| q8_0 | tg32 d32768 | 27.11+-0.21 | 27.09+-0.24 | 28.39+-0.62 | 28.94+-0.23 |
- q8_0 pp2048 d0: both sides run the same dense code at d0. The -2.6% comes from one high master round and is inside the summed stddev.
- q8_0 tg128 d8192: the two master rounds differ by 4.6%, and the PR is between them.
ROCm, 1 round, -r 3, pp2048 d0: f16 1111.41+-21.92 (master) and 1110.73+-20.45 (PR). q8_0 1085.26+-18.69 (master) and 1086.73+-21.41 (PR).
Findings in full
- Should fix,
src/llama-memory-hybrid-idx.cpp:128-137. With the override at 0 and working kernels, the PR prints "masked top-k (K/V cache q8_0/q8_0: no selected-key kernels for this type)", and the same text for f16. With the override at 1 and no kernels, it prints "selected-key kernels" and does not say that the path was forced. Suggestion: set aforcedflag in the getenv branch and print "(forced by LLAMA_QSA_SELECTED_KEY)" in both directions. - Should fix,
src/llama-memory-hybrid-idx.cpp:48-60and:123. The typed probe usesqwith 1 query. The Vulkanflash_attn_selsupport check does not depend on the query count. It accepts f16, q8_0, q4_0, q4_1, q5_0, q5_1 and iq4_nl at every width, K and V checked separately, and refuses bf16 and f32. HIPqsa_decodetakes f16 with 1..512 queries, andqsa_prefilltakes f16 with >= 128 queries and GQA 12. So the 1-query probe is right on master today. If a backend adds quantized K/V at decode width only, prefill ubatches above 512 then go to CPU attention without a warning. Loop the typed probe over n_q in {1, 513} when the cache is not f16. Do not change the f16 probe: on HIP with a GQA other than 12 that would move f16 decode to the masked route. That f16 case (master already sends prefill above 512 to the CPU for GQA != 12) is older than this PR, and the target model is GQA 12. - Should fix (description). "This PR alone changes nothing on Vulkan" was true before the Vulkan kernels landed. Before this PR,
LLAMA_QSA_SELECTED_KEY=1with a quantized cache stayed masked, because the graph gate still required f16. Now it builds the maskless op. ROCm refuses that op, and the scheduler runs it on the CPU (measured above: correct output, slower). Please document this. - Nit,
src/models/qwen4exp.cpp:1097-1099. Line 1099 is about 185 columns in a block that is otherwise wrapped. "single stream" is stale, because the scalar gate allows split streams with >= 128 queries per stream. - Inherited from the Vulkan kernel change, not from this PR: the Vulkan prefill dequantizes the whole K/V view to f16 and asserts
<= maxStorageBufferRangeat compute time (ggml-vulkan.cpparound 10716). The support check does not test this. It cannot trigger with 2 KV heads (about 8 MiB per view at 8192 keys). A model with many KV heads at a depth near 1M keys could reach it. This extra memory is also not counted when buffers are reserved. - Removing
type_k/type_vfromqwen4exp_use_block_selectionis safe. Both callers (graph reuse at :1280 and graph build at :1448) read the sameselected_key_attn, which is now type-aware and fixed per context. - Overlap: #219 (closed) had the same gate hunks, plus the {1, 513} probe. Draft #276 rewrites this gate and will need a rebase after this PR lands.
Claims
| claim | result |
|---|---|
| Vulkan q8_0 takes the maskless route | reproduced (log line; master equals PR with the override at 0, byte for byte) |
| q8_0 pp2048 d32768 +137% | reproduced in direction: +117.7% (different model and Mesa) |
| q8_0 pp8192 +35% | reproduced in direction: +26.6% |
| q8_0 tg d32768 +3.6% | reproduced: +5.8% (tg32) |
| q8_0 pp2048 d0 and tg128 d0 unchanged | reproduced, within noise |
| f16 unchanged, byte-identical logits on the 4 corpora | reproduced on the full model, -c 16384, Vulkan and ROCm, plus decode |
| q8_0 maskless KLD equal to masked | reproduced within noise on all 4 corpora and the long case |
| LLAMA_QSA_SELECTED_KEY=0 still turns it off | reproduced (the log reason is wrong, ask 1) |
| ROCm refuses the quantized op, nothing changes there | reproduced: masked on both sides, logits and decode byte-identical |
| test-backend-ops 44187/44187 | not tested (no ggml change in this PR) |
Not tested
- The UD-Q4_K_XL file from the description (not downloaded).
- The full test-backend-ops suites and ctest -L main (the PR changes no ggml code).
- llama-bench at -r 5 (we ran -r 3 with 2 rounds; f16 at d64000 had 1 round).
- Multi-sequence greedy decode with -np > 1 (two-sequence batches were covered by llama-perplexity).
- ROCm decode with HIP_LAUNCH_BLOCKING=1 (the logit parity covers =1).
The rewrite rebased onto master 1dd4c92, plus the TE-rows mask fix (f54eb9f). The master commits past b620b0d (#225, #249, #254, #271, #282, #288) touch no HIP file and the fix touches only src/ and tests/, so the baseline should hold; this commit is the regeneration that checks it. Pinned image rocm/dev-ubuntu-26.04@sha256:4f5ed1bf..., git archive of f54eb9f (the head before this commit), the two build steps of hip-quality-check.yml in a clean build directory (scripts/qsa-validation/harness/w13/vgpr_in_image.sh of the evidence branch, unchanged): - -Werror -Wno-tautological-compare build: rc 0; 18 warnings, none fatal under the CI flags (the same 18 as on the previous base); - test_vgpr_check.py: 21 tests OK; - EXPORT_METRICS On build: rc 0, 167 *.lto.s. Checker against the committed baseline: PASS, 6824 kernels across 162 TUs, 0 VGPR-spilling symbols, 11 SGPR-spilling symbols, all 11 bounded by baseline entries (3 sgpr_lane_spill, 8 sgpr_lane_spill_slower). Regeneration with scripts/hip/README.md's python, verbatim: minimum_kernel_count 6824 -> 6824, TUs 162 -> 162, copies 7164 -> 7164, no TU count changed. Only source_revision moves, 6805faa -> f54eb9f (and three TU keys move in the file's key order, values unchanged); the file equals the previous regeneration (7e7c75b) except for source_revision. Checker against the regenerated baseline: PASS. The compiler string is the image's (AMD clang 24.0.0git d6f6cb691863). The regeneration python and the checker ran on the host, reading the image's assembly, as in W13. Assisted-by: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LzX5gGXu1HutDf5C55PuKJ
REBASE3.md: rebase onto b620b0d (#272 conflict, its regression test) and verification. PROOF-final3.md: remaining coverage gates (M1, M2, M5, M6, AT-O at ub512/1024, Q1-C, Q3, Q4, Q8, Q11, P1, P4, Vulkan decode). REBASE4.md: rebase onto 1dd4c92 (#271 deleted with the maskless path, #225/#249/#254 kept), the M5 multi-slot reserve fix and its verification. Assisted-by: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LzX5gGXu1HutDf5C55PuKJ
The rewrite rebased onto master 1dd4c92, plus the TE-rows mask fix (f54eb9f). The master commits past b620b0d (#225, #249, #254, #271, #282, #288) touch no HIP file and the fix touches only src/ and tests/, so the baseline should hold; this commit is the regeneration that checks it. Pinned image rocm/dev-ubuntu-26.04@sha256:4f5ed1bf..., git archive of f54eb9f (the head before this commit), the two build steps of hip-quality-check.yml in a clean build directory (scripts/qsa-validation/harness/w13/vgpr_in_image.sh of the evidence branch, unchanged): - -Werror -Wno-tautological-compare build: rc 0; 18 warnings, none fatal under the CI flags (the same 18 as on the previous base); - test_vgpr_check.py: 21 tests OK; - EXPORT_METRICS On build: rc 0, 167 *.lto.s. Checker against the committed baseline: PASS, 6824 kernels across 162 TUs, 0 VGPR-spilling symbols, 11 SGPR-spilling symbols, all 11 bounded by baseline entries (3 sgpr_lane_spill, 8 sgpr_lane_spill_slower). Regeneration with scripts/hip/README.md's python, verbatim: minimum_kernel_count 6824 -> 6824, TUs 162 -> 162, copies 7164 -> 7164, no TU count changed. Only source_revision moves, 6805faa -> f54eb9f (and three TU keys move in the file's key order, values unchanged); the file equals the previous regeneration (7e7c75b) except for source_revision. Checker against the regenerated baseline: PASS. The compiler string is the image's (AMD clang 24.0.0git d6f6cb691863). The regeneration python and the checker ran on the host, reading the image's assembly, as in W13. Assisted-by: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LzX5gGXu1HutDf5C55PuKJ
The qwen4exp block selection asked for an f16 K and V cache, and its probe op used f16 tensors whatever the cache held. With
-ctk q8_0 -ctv q8_0every layer therefore stayed on the masked top-k route, even on a backend whose selected-key kernels take a quantized cache. This lets the backend decide.There is no new switch;
LLAMA_QSA_SELECTED_KEY=0still turns the maskless path off. An f16 cache takes the same route as before.Strix Halo (gfx1151, RADV, Mesa 26.2.4, platform_profile balanced, 128 GB), Qwen3.8-Flash-Next UD-Q4_K_XL,
-ngl 99 -fa 1 -lm none -lzm on-direct, pp2048-ub 2048, pp8192-ub 8192, master 62a3f41 against master plus this PR and the Vulkan quantized-K/V PR (this PR alone changes nothing on Vulkan, whose kernels refuse the op without it), one llama-bench process of-r 3per cell, 4 cells per build in ABBA order (mean +- spread of the cell means):The full test-backend-ops suite on the combined tree gives 44187/44187 (master 43840/43840). With q8_0 K/V the path census shows the selected-key dequant and gather dispatches (FA_SEL_KV_DEQUANT, FA_SEL_KV_GATHER); master and an f16 cache show none.
An f16 cache gives byte-identical logits to master on all four tests/corpus files (8-layer cut,
-c 4096 -b/-ub 2048,cmp). With q8_0 K/V the maskless path matches the masked one: KLD against the f16 cache 0.000110 vs 0.000113 (8-layer cut, prose), and on the full model 0.007807 vs 0.007835 (wikitext-2,-c 16384, 2 chunks).Written with Claude, tested by me.