Skip to content

hrx: K-quant / IQ4 / Q8_0 decode projections in GGUF block layout - #42

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

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

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Decode (token count 1) projections for Q4_K, Q5_K, Q6_K, IQ4_NL, IQ4_XS and Q8_0 weights, read straight from their GGUF blocks with f32 activations. There is no repack and no activation quantization. All code is in our own files; the hookups are one include and one call in dispatch-common.cpp, plus CMake and manifest entries.

  • ops/kquant_decode_f32.loom has two kernels:
    • ggml_kquant_swiglu_decode_f32: the FFN gate/up pair fused with SwiGLU.
    • ggml_kquant_mul_mat_decode_f32: a projection with an optional following residual ADD.
    • Layout: one wave64 per row, 16 lanes per 256-value block, 8-byte weight loads.
    • IQ4 table values are read across lanes. A 16-entry vector.table.lookup lowers to 15 v_cndmask per byte on gfx11, which made IQ4_XS compute-bound: 1492 instructions per step, down to 584 with no selects; IQ4_XS pairs went from 108 to 206 GB/s.
    • Includes a scalar reference kernel and six check.cases covering every format, both kernels and a half-full last workgroup. All pass under --sanitizer=access on gfx1151.
  • dispatch-kquant-decode.cpp holds the matchers:
    • SwiGLU pairs at priority 305, below the int4 lowrow path.
    • Projections at 85, above only the generic common.mul_mat f32 matchers (80/70/60).

Mixed-quant GGUFs (Unsloth UD-Q4_K_XL) pair these types freely per layer. Before this change they took the generic kernels, which dequantize 4 values at a time.

Results (gfx1151)

Decode, tg128, interleaved with Vulkan (weekly build), thermal guard on:

Model HRX before HRX after Vulkan Ratio
Qwen3.8-27B UD-Q4_K_XL 9.0–9.45 11.60 12.49 92.9%
ZAYA1-8B Q4_K_M ~90 92.68 93 —
Qwen3-0.6B Q4_K_M 320.8 326.6 357 91.4%
Qwen3-Coder-30B-A3B Q4_K_M 90.5 90.4–90.7 93.7 96.6% (unchanged)

27B decode token (profiled): 104.7 ms busy before, 89.4 ms after.

  • FFN gate/up pairs: 105–176 GB/s before, 197–222 GB/s after.
  • Projections: about 210–224 GB/s.
  • Still on other paths: one IQ3_S ffn_down (2.8 ms), three Q3_K FFN pairs, and the small ssm_alpha/ssm_beta projections, which are latency-bound at about 16 µs each.

Accuracy, wikitext -c 128 --chunks 4 with -ub 1 (every token decode-shaped):

Model This PR HRX before CPU
27B 7.1550 7.1547 7.1475
ZAYA1-8B 34.13 33.46 34.90

The ZAYA figures are all within ±9.1. The before path used q8 activations for Q4_K; this one keeps f32.

test-backend-ops -o MUL_MAT -b HRX0: all cases pass (2/2 backends).

Thermals: the 27B HRX run peaks at 90–93 °C on this box (Vulkan: 67 °C); one of the two HRX rounds was stopped by the 93 °C guard.

🤖 Generated with Claude Code

One-token (decode) projections on Q4_K, Q5_K, Q6_K, IQ4_NL, IQ4_XS and
Q8_0 weights, read straight from their GGUF blocks with f32 activations
(no repack, no activation quantization), in our own files:

- ops/kquant_decode_f32.loom: ggml_kquant_swiglu_decode_f32 (FFN gate/up
  pair fused with SwiGLU) and ggml_kquant_mul_mat_decode_f32 (projection
  with an optional residual ADD). One wave64 per row, 16 lanes per
  256-value block, 8-byte weight loads. IQ4 table values are read across
  lanes (lane c of each 16-lane group holds kvalues_iq4nl[c]): a 16-entry
  vector.table.lookup lowers to 15 v_cndmask per byte on gfx11 and made
  IQ4_XS compute-bound (108 GB/s). Scalar reference kernel and six
  check.cases (every format, both kernels, a half-full last workgroup).
- dispatch-kquant-decode.cpp: matchers at token count 1. SwiGLU pairs at
  priority 305 (below the int4 lowrow path); projections at 85, above only
  the generic common.mul_mat f32 matchers.

Mixed-quant models (Unsloth UD-Q4_K_XL) pair these types freely per layer
and previously took the generic dequantize-4-values dot kernels.

Qwen3.8-27B UD-Q4_K_XL, HRX0 (gfx1151), decode token 104.7 -> 89.4 ms busy;
FFN gate/up pairs 105-176 -> 197-222 GB/s, projections ~210-224 GB/s.
Results in the PR description.

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 ade79d4 into 1bit/hrx-vulkan-patched Sep 29, 2026
10 of 24 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-kquant-decode 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