Repository navigation
ggml-hrx: NVFP4 prompt matmuls on the int8 q8_1 x4 WMMA kernel (pp512 107 -> 323) - #78
bong-water-water-bong wants to merge 4 commits into
Conversation
The q8_1 x4 kernel (ops/mul_mat_q5_k_q8_plane_wmma.loom) stages 64-value K chunks, which is exactly one NVFP4 block. motifs/nvfp4_q8_1_x4.loom stages it as signed E2M1 codes (kvalues_mxfp4, -12..12) and its four halved UE4M3 scales; NVFP4 has no minimum, so the correction slots carry the second 16-value scale of each K32 block. A K32 block holds two NVFP4 scale groups, so at weight format 43 each output tile keeps its two 16-wide int8 WMMA products apart and scales each by its own scale before the q8_1 activation scale (the other formats sum them in i32 under one K32 scale). The hooks in AMD's file are the format flag, signed staged weights, the staging branch and that per-tile select; the flag is a compile-time constant, so other formats compile as before (Qwen3-0.6B Q4_K_M and UD-Q4_K_XL perplexity on HRX0 identical to the digit, through the Q4_K, Q5_K / IQ4_XS and paired SwiGLU x4 kernels). Co-Authored-By: Claude Opus 5.5 <[email protected]>
common.mul_mat.nvfp4_q8_1_x4_prefill (dispatch-mul-mat-nvfp4.cpp, priority 300) claims NVFP4 MUL_MAT at 256..2048 tokens in multiples of 256, input sizes in multiples of 256 and output sizes in multiples of 64: the activations are quantized to q8_1 x4 once (common_prepare_q8_1_x4_input) and the kernel runs at weight format 43. NVFP4 prompts no longer take the generic f16 WMMA kernels (common.mul_mat.f32_f32_wmma, common.mul_mat_swiglu.f32_f32_wmma), so the f16 accumulation of engine #284 no longer applies to them. Qwen3.8-27B NVFP4 (cdiamond), balanced mode: pp512 107 -> 323 tok/s; KLD vs CPU 0.00462 -> 0.00423. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…P4 q8_1 x4 path Known answer: integer activations with |max| 127 in every K32 block (exact q8_1, d = 1) against raw NVFP4 blocks whose scales cycle through every UE4M3 byte; HRX must match an f64 reference from dequantize_row_nvfp4 to 1e-5 of sum |w x| per output (it is within 2.4e-7). A shared or swapped 16-value scale fails by orders of magnitude. Then quantized random weights against the CPU backend. Both must plan the q8_1 quantize + x4 kernel. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review (PR-Agent duty): the design and results are good; one change requested before merge (after Sunday's release either way). Good:
Change requested:
Don't copy AMD's kernel into our file to get around this; minimal hooks in theirs is the right shape. After the refactor, rerun the known-answer test, the Q4_K_M / UD-Q4_K_XL PPL identity check and the 27B pp512/KLD. |
…nel file Review on #78: the NVFP4 two-scale contraction and the staging gate move into motifs/nvfp4_q8_1_x4.loom (@ggml_nvfp4_x4_tile, @ggml_nvfp4_x4_stage). AMD's ops/mul_mat_q5_k_q8_plane_wmma.loom keeps the format flag, the signed-weight flag, one staging call in place of the lane comparison, and one helper call per contraction site (the original affine result is passed in and kept for other formats): 46 lines added, 22 removed against its pre-#78 text, down from 150 added. The helpers take only values, never calling back into the kernel file. Same results as before: known answer within 2.3e-7 of sum |w x|, CPU NMSE <= 1.5e-9, Qwen3-0.6B Q4_K_M and UD-Q4_K_XL perplexity identical, test-backend-ops 1129/1129, 27B NVFP4 KLD 0.004225 / PPL 6.651781 (identical), pp512 321 +/- 9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review addressed in 16a03aa: the NVFP4 contraction and staging logic now live in Reran, all the same as before: known answer within 2.3e-7 of sum |w x|; vs CPU NMSE <= 1.5e-9; Qwen3-0.6B Q4_K_M and UD-Q4_K_XL perplexity identical (through the Q4_K, Q5_K/IQ4_XS and paired SwiGLU x4 kernels); test-backend-ops 1129/1129; the other HRX tests pass; 27B NVFP4 KLD 0.004225 and PPL 6.651781 (identical), pp512 321 +/- 9, tg128 7.96. 🤖 Generated with Claude Code |
|
Change made in 16a03aa, approved. AMD's mul_mat_q5_k_q8_plane_wmma.loom is now down to +46/-22: the format and signed-weight flags, one staging call, and one helper call per contraction site that keeps the original affine result for every other format. The NVFP4 logic is in our motif (@ggml_nvfp4_x4_tile / @ggml_nvfp4_x4_stage), and none of AMD's kernel is copied. Reruns are identical (known answer, NMSE, other-format PPL, 1129/1129, 27B KLD 0.004225, pp512 321). I'll merge after Sunday's release, stacked after #75-#77. |
|
Closed under the 2026-10-03 direction: new GPU kernels are HIP in the private add-on, the public fork keeps plumbing and fixes. Q8_0 and MXFP4 prompt GEMMs already run on HIP there (hip.mul_mat_q8_0_prefill, the GEAK MXFP4/Q6_K GEMMs); Q2_0 / NVFP4 / Q4_0-Q5_1 prompt matmuls will be HIP kernels when a model needs them. The branch stays for reference. |
NVFP4 prompt matmuls on HRX's int8 q8_1 x4 WMMA kernel instead of the generic f16 WMMA path. Stacked on #77 (on #76, on #75).
NVFP4 prefill no longer takes the f16 WMMA kernels (
common.mul_mat.f32_f32_wmma,common.mul_mat_swiglu.f32_f32_wmma), so the #284 f16-accumulation fix can skip NVFP4.How
ops/mul_mat_q5_k_q8_plane_wmma.loom, exportggml_mul_mat_q5_k_iq4_xs_q8_1_x4_wmma_token256) stages 64-value K chunks, which is exactly one NVFP4 block. Ourmotifs/nvfp4_q8_1_x4.loomstages it as signed E2M1 codes (kvalues_mxfp4, -12..12, exact in i8) plus its four halved UE4M3 scales. NVFP4 has no minimum, so the kernel's correction slots hold the second 16-value scale of each K32 block.motifs/nvfp4_q8_1_x4.loom,dispatch-mul-mat-nvfp4.{h,cpp}, the test).common.mul_mat.nvfp4_q8_1_x4_prefill(priority 300) claims NVFP4 MUL_MAT when: tokens are 256..2048 in multiples of 256, K is a multiple of 256, output is a multiple of 64. Activations go through the existingcommon_prepare_q8_1_x4_input. Everything else stays on the current paths.Validation, gfx1151, balanced power mode:
dequantize_row_nvfp4; K 256-5120, 256-1024 tokensnvfp4_q8_1_x4_prefill, no NVFP4 onmul_mat(_swiglu).f32_f32_wmmaNot for the release pin.
🤖 Generated with Claude Code