Skip to content

ggml-hrx: NVFP4 weights (shared dequantizer, decode lanes, bit-exact GET_ROWS test) [rebased] - #98

Merged
bong-water-water-bong merged 4 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-nvfp4-rb
Oct 9, 2026
Merged

bong-water-water-bong merged 4 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-nvfp4-rb

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Rebase of #75 onto the current tip e44c9d0 (AMD's corpus taken wholesale on 6 Oct). All four patches applied with no textual conflict; git range-diff shows every commit unchanged. The tip has no NVFP4 handling of its own and HRX format code 43 is still free, so nothing was dropped.

Verified on strixhalo 2026-10-09 (power mode performance, hrx-system 98d05d94, built with the engine's HRX configuration, every GPU step under box.lock):

  • test-hrx-nvfp4: bit-exact (16 rows x 256 values, all scale bytes), 3 of 3 runs; test-hrx-decode-stride 108 cases, 0 failures; test-hrx-mxfp4 bit-exact.
  • test-backend-ops -b HRX0: GET_ROWS 26/26 x3, MUL_MAT 334/334 x3 (the NVFP4 "not supported" cases are identical to the PR's own suite log).
  • Paris: Qwen3-0.6B-NVFP4 3 identical runs; Qwen3.8-27B-iMatrix-NVFP4-MTP "Paris." 2 runs. One graph split; NVFP4 runs on the kquant decode lanes.
  • KLD vs CPU: 0.6B 0.001539 (PR: 0.00321); 27B 0.001526 (PR: 0.0042).
  • llama-bench 27B NVFP4: pp512 115.6, tg128 9.14 (PR: 107 / 8.45).

Full test-backend-ops at the stack tip: 27 of 28 runs 1141/1141; the one failure (MUL_MAT f32 m=1 n=1 k=2048, common.mul_mat.f32_f32_decode) also occurs on the unmodified base (1 in 40 MUL_MAT runs), so it is pre-existing and reported separately.

Supersedes #75.

🤖 Generated with Claude Code

bong-water-water-bong and others added 4 commits October 9, 2026 02:38
NVFP4 (ggml type 40) is 64-value blocks of four UE4M3 scales, one per 16 values, and 32 bytes of E2M1
codes. The shared dequantizer walks 32-value blocks, so a block is half of an NVFP4 block: row bytes are
18 per 32 values and a 256-value tile is 144 bytes (both set, see #74). The decoder in dequant_1bit.loom
reuses the MXFP4 code table and nibble unpacking; the scale is ggml_ue4m3_to_fp32 built from its f32
bits, exact for every byte (0x7F reads as 0, bit 7 is ignored).

The HRX format code is 43, not the ggml type id: HRX format 40 is Q4_0. Input sizes are multiples of 64.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An NVFP4 scale group is 16 consecutive values, so NVFP4 joins packed ternary, TQ1_0, TQ2_0 and MXFP4 on
the 16-value lanes of kquant_decode_f32: lane l reads block l / 4, sub-block l % 4 (scale d[s], codes
qs[8 s..8 s + 7], low nibbles first). 144 bytes per 256 values. Decode projections, SwiGLU pairs and
projection + residual ADD on NVFP4 weights now take the kquant decode kernels instead of the generic path.

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

Sixteen rows of 256 values hold all 256 UE4M3 scale bytes and every E2M1 code in both nibbles. GET_ROWS
on HRX must equal ggml's dequantize_row_nvfp4 bit for bit (every NVFP4 value is exact in f32), on the
HRX device with no scheduler, and the dispatch plan must contain the get_rows kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…2880 and 2048, from one token

The NVFP4 format admits input sizes that are a multiple of 64, the kquant decode lanes only multiples of
256. At 320, 1152 and 2880 one token takes the generic ggml_mul_mat_f32_f32_decode_wave64, 2..8 tokens
ggml_mul_mat_f32_f32_wmma and MUL_MAT_ID ggml_mul_mat_id_decode_f32_wave64; at 2048 the kquant lanes.
All 36 NVFP4 cases match the CPU backend (normalized MSE about 1e-5); 108 cases, 0 failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant