Skip to content

ggml-hrx: Q2_0 weights (shared dequantizer, decode lanes, bit-exact GET_ROWS test) - #76

Closed
bong-water-water-bong wants to merge 3 commits into
1bit/hrx-nvfp4from
1bit/hrx-q2_0
Closed

bong-water-water-bong wants to merge 3 commits into
1bit/hrx-nvfp4from
1bit/hrx-q2_0

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Q2_0 weights (ggml type 42) on HRX0. Stacked on #75 (NVFP4), which touches the same dequantizer anchors; review and merge after it. Before this branch, HRX supported none of the Q2_0 cases in test-backend-ops.

Commits

  • 901a7829: Q2_0 in the shared dequantizer, HRX format code 42 (not a ggml type id; checked against common_mul_mat_format_config_value). The decoder is in our motifs/dequant_1bit.loom, value ((qs[j/4] >> 2(j%4)) & 3) - 1 times the f16 d. Row bytes are 18 per 64 values and tile bytes 72 per 256; both are set, per ggml-hrx: PrismML tile bytes for the low-token SwiGLU (PQ2_0 1.7B decode) #74. Input sizes must be multiples of 64.
  • 0d32570a: Q2_0 on the 16-value kquant decode lanes, reading 16-bit words (blocks are 18 bytes, 2-byte aligned).
  • c2a1beb9: tests/test-hrx-q2_0, GET_ROWS bit-exact against dequantize_row_q2_0. The f16 scales cover normal, subnormal, negative, zero and 65504, and every byte value appears in the codes.

Validation on this branch plus the GET_ROWS PR on top (97fcffe5), gfx1151, balanced power mode:

Check Result
test-hrx-q2_0 / test-hrx-nvfp4 / test-hrx-mxfp4 bit-exact
test-backend-ops Q2_0: MUL_MAT / MUL_MAT_ID / GET_ROWS 13 / 12 / 1 OK, 0 fail; the rest "not supported" (same broadcast shapes as q4_0)
test-backend-ops -b HRX0, full suite 1129/1129
sdkyuan/qwen3.8-27B-qat-q2_0-gguf (Apache-2.0, 8.15 GiB), HRX vs CPU, wikitext-2 8 x 512 KLD 0.00106, same top token 97.9%, PPL 8.296
Routing graph splits = 1, 65/65 layers on HRX0; decode on kquant.{mul_mat,swiglu,mul_mat_add}.decode_f32
pp512 / tg128 156 / 19.8 tok/s (tg samples 19.5-20.8; an earlier +/-6.5 run shared the box with a CPU job)

Prefill (156 tok/s) runs on the generic f16 WMMA kernels, as with NVFP4 in #75.

Not every file named "Q2_0" uses ggml's Q2_0. darkstarinitiative/AJAN-SIMIT-Ternary-Bonsai-Q2_0-GGUF fails to load on the CPU too (tensor 'blk.0.attn_k.weight' has offset 82516128, expected 87369536), so it was written with another fork's block layout. That is not an HRX gap.

Not for the release pin.

🤖 Generated with Claude Code

bong-water-water-bong and others added 3 commits October 2, 2026 19:20
Q2_0 (ggml type 42) is 64-value blocks of an f16 scale d and 16 bytes of 2-bit codes; value j is
((qs[j / 4] >> 2 (j % 4)) & 3) - 1 times d (dequantize_row_q2_0). Four aligned values are the four fields
of one byte. The decoder takes the value index k like Q1_0 and lives in our motifs/dequant_1bit.loom; row
bytes are 18 per 64 values and a 256-value tile is 72 bytes. Input sizes are multiples of 64.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Q2_0 lane of 16 values is four code bytes under one scale, so Q2_0 joins the 16-value lanes of
kquant_decode_f32: lane l reads block l / 4 (d at its first 16-bit word) and the two 16-bit words of qs
bytes 4 (l % 4)..+4 (blocks are 18 bytes, 2-byte aligned). 72 bytes per 256 values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on HRX

Eight rows of 256 values with f16 scales 1, 0.1, -1, the smallest subnormal, a negative subnormal, 0,
65504 and 2^-10, and every byte value in the codes. HRX's GET_ROWS must equal dequantize_row_q2_0 bit for
bit, on the HRX device with no scheduler, through the get_rows kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Author

Review (PR-Agent duty): approved, merging after Sunday's release (stacked on #75). Checked: HRX format 42; row bytes (K/64 x 18) and tile bytes (72 per 256 values) both present; the known-answer test covers subnormal, negative, zero and 65504 f16 scales. sdkyuan/qwen3.8-27B-qat-q2_0: KLD 0.00106 vs CPU, top-1 97.9%, one graph split, decode on the kquant lanes, tg128 19.8. NVFP4 and Q2_0 now also share the decode-stride test at widths that are not multiples of 256. Our full Apache header is on test-hrx-q2_0.cpp.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Kept: format support in the shared dequantizer / GET_ROWS is plumbing, not a new kernel (Q2_0 is the 2-bit format the ternary goal uses). Waits for the release hold like everything else; needs a rebase onto f95f2db before merge.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Superseded by the rebase onto e44c9d0, re-verified on HRX0: #99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant