Skip to content

hrx: K-quant decode kernels for 2-8 tokens (MTP / speculative verify) - #46

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-kquant-tokens
Sep 30, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-kquant-tokens

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Adds K-quant decode kernels for batches of 2–8 tokens, the size of MTP and speculative verify steps. Before this, those steps fell off the one-token K-quant kernels onto AMD's low-token and prefill WMMA kernels.

Changes

ops/kquant_decode_f32.loom:

  • New kernels ggml_kquant_swiglu_decode_tokens_f32 and ggml_kquant_mul_mat_decode_tokens_f32. The token count (2–8) is fixed at compile time.
  • Each lane dequantizes its 16 weights once per block and applies them to every token.
    • The per-format "lane weights" functions are derived from the one-token ones: they return the weights and the positions of their runs.
    • Activation loads are 16, 8 or 4 wide depending on the format.
  • The reference kernels now loop over tokens.
  • Five 3-token check.cases cover all formats. All twelve cases pass under the access sanitizer.

dispatch-kquant-decode.cpp:

  • Matches MUL_MATs with 1–8 tokens. The common matcher's decode form only admits one token.
  • Projection + residual ADD is now also registered at priority 185, above common.mul_mat_postops.f32_f32_wmma (180), which was taking multi-token projections through the prefill WMMA kernel.

Results

Qwen3.8-27B UD-Q4_K_XL + MTP head (n3, p-min 0.75), HRX0, llama-server:

Before After
Decode, code / prose / translate prompts 20.1 / 16.4 / 17.6 tok/s 22.5 / 17.7 / 19.0 tok/s
Draft acceptance 97–98 / 88 / 79% unchanged
GPU busy for the same request 9134 ms 8123 ms
Plain decode, same prompts 11.9 / 12.0 / 12.5 12.1 / 12.2 / 12.7

Vulkan with MTP does 34.6 / 24.3 / 24.5 on the same prompts, so HRX is at 65–78%. A 4-token verify step still costs about 1.7× a 1-token step, because the f32 multiply-adds on every token dominate. The next step is int8 activations, the way Vulkan's matrix-vector path does it.

Other models (llama-bench tg128 with the new projection+add matcher on vs off, idle GPU): Qwen3-0.6B 327.6 vs 325.9, Qwen3-Coder-30B-A3B 89.4–90.4 vs 90.3, ZAYA1-8B 94.3.

test-backend-ops -o MUL_MAT -b HRX0 passes, including the n = 1–6 cases for all these weight types.

🤖 Generated with Claude Code

Speculative decoding verifies 2-4 tokens per step; those batches fell off the
one-token K-quant kernels onto AMD's low-token and prefill WMMA kernels.

- ops/kquant_decode_f32.loom: ggml_kquant_swiglu_decode_tokens_f32 and
  ggml_kquant_mul_mat_decode_tokens_f32 (token count 2..8, compile-time).
  Each lane dequantizes its 16 weights once per block (per-format "lane
  weights" functions derived from the one-token ones: the weights and the
  positions of their runs) and applies them to every token; x loads are
  16/8/4 wide by format. Reference kernels loop over tokens; five 3-token
  check.cases (all formats covered), all twelve cases pass with the access
  sanitizer.
- dispatch-kquant-decode.cpp: matches 1..8-token MUL_MATs (the common
  matcher's decode form only admits one token); projection + residual ADD
  also registered at 185, above common.mul_mat_postops.f32_f32_wmma (180),
  which took the multi-token projections through the prefill WMMA kernel.

Qwen3.8-27B UD-Q4_K_XL + MTP head (n3, p-min 0.75), HRX0, llama-server:
20.1/16.4/17.6 -> 22.5/17.7/19.0 tok/s (code/prose/translate prompts; draft
acceptance unchanged 97-98/88/79%); GPU busy for the same request 9134 ->
8123 ms. Plain decode 11.9/12.0/12.5 -> 12.1/12.2/12.7. test-backend-ops -o
MUL_MAT -b HRX0 passes (n = 1..6 cases for all these types).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the ggml label Sep 29, 2026
@bong-water-water-bong
bong-water-water-bong merged commit dad19ad into 1bit/hrx-vulkan-patched Sep 30, 2026
10 of 24 checks passed
bong-water-water-bong added a commit that referenced this pull request Nov 1, 2026
… (silent stale grid) (#168)

The recipe said "list the parameters that change the grid" without saying what a miss costs,
and a miss is not an error: launch_fn runs once per executable cache entry, the key holds only
the workload parameters, so an unlisted parameter read by the launch function freezes the first
case's grid for every later case and the kernel quietly covers less than it was asked to.

Written from the V4.1 indexer gate (gpu-kernels #46), where n_stream was left out:
test-backend-ops -o LIGHTNING_INDEXER -b HRX0 gave 4/12 - all ns=1 cases green, all ns=4 cases
wrong by one stream plane (inf mismatch: HRX0=0.943650 CPU=-inf; ERR = 2.909230024) - while the
same kernel driven straight through hipModuleLaunchKernel is correct at 4 streams to 3.9e-03.
That is why the standalone harness missed it and the suite did not.
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-kquant-tokens branch November 12, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant