Repository navigation
Conversation
…olumns ktrain patch 0005 (first commit of PR PrismML-Eng#310): lets ggml_cuda_should_fuse_mul_mat_vec_q and ggml_cuda_mul_mat_vec_q accept the gate/up fusion for 2..4 columns when the dedicated PTQ1_0 kernel can take it (ggml_cuda_mmvq_ptq1_0_can_fuse_mc: plain 2D, K multiple of 128, shared memory within the limit). Merged with upstream's new MoE assert on the batch size. Patch 0006 (GLU output overlapping the q8 rows) is not included: it depends on prism's signed-FWHT + q8 quantizer graph fusion (ggml_cuda_try_fwht_q8), which this branch does not have yet. test-backend-ops ptq1_0: MUL_MAT 178/178, MUL_MAT_ID 85/85, MUL_MAT_VEC_FUSION 2/2; mtp_bench: all 8 output hashes identical to the commit before. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…output overlaps the q8 rows ktrain patch 0006 (PR PrismML-Eng#310, second part), applied as the net diff of pr/ptq1-gate-up-fuse-mc after 0005 (the GGML_CUDA_FWHT_GLU_POOL switch is not carried over): a gate/up pair that the mat-vec fuses with its SwiGLU writes the GLU output while other CTAs still read the q8 rows; when the allocator put the GLU output over that buffer, the fused FWHT quantizer now writes the rows to a pool block (out_aliases_in), and the fusion memory-range check ignores overlaps with inputs whose q8 rows live in a pool block (thread-local registry pointer, reset after each graph). Needs the signed-FWHT + q8 fusion of the previous commit. mtp_bench output hashes identical to the commit before. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…olumns ktrain patch 0005 (first commit of PR PrismML-Eng#310): lets ggml_cuda_should_fuse_mul_mat_vec_q and ggml_cuda_mul_mat_vec_q accept the gate/up fusion for 2..4 columns when the dedicated PTQ1_0 kernel can take it (ggml_cuda_mmvq_ptq1_0_can_fuse_mc: plain 2D, K multiple of 128, shared memory within the limit). Merged with upstream's new MoE assert on the batch size. Patch 0006 (GLU output overlapping the q8 rows) is not included: it depends on prism's signed-FWHT + q8 quantizer graph fusion (ggml_cuda_try_fwht_q8), which this branch does not have yet. test-backend-ops ptq1_0: MUL_MAT 178/178, MUL_MAT_ID 85/85, MUL_MAT_VEC_FUSION 2/2; mtp_bench: all 8 output hashes identical to the commit before. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…output overlaps the q8 rows ktrain patch 0006 (PR PrismML-Eng#310, second part), applied as the net diff of pr/ptq1-gate-up-fuse-mc after 0005 (the GGML_CUDA_FWHT_GLU_POOL switch is not carried over): a gate/up pair that the mat-vec fuses with its SwiGLU writes the GLU output while other CTAs still read the q8 rows; when the allocator put the GLU output over that buffer, the fused FWHT quantizer now writes the rows to a pool block (out_aliases_in), and the fusion memory-range check ignores overlaps with inputs whose q8 rows live in a pool block (thread-local registry pointer, reset after each graph). Needs the signed-FWHT + q8 fusion of the previous commit. mtp_bench output hashes identical to the commit before. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bri-prism
left a comment
There was a problem hiding this comment.
Agent review: posted by the maintainer's coding agent at their request.
This needs a rebase. Against current prism (73bfe6c), the CUDA build fails:
ggml/src/ggml-cuda/mmvq.cu(1602): error: too few arguments in function call
const size_t smem = ptq1_0_pt_smem_bytes((int) (src0->ne[0] / 128), ncols_dst, (int) src0->ne[1], true);
ptq1_0_pt_smem_bytes has gained a parameter on prism since this branch was cut, and the test-backend-ops hunk no longer applies either. I'll re-run the H200 A/B (test-backend-ops MUL_MAT_VEC_FUSION, greedy identity, 2-4-column decode) once it's rebased.
…olumns ktrain patch 0005 (first commit of PR PrismML-Eng#310): lets ggml_cuda_should_fuse_mul_mat_vec_q and ggml_cuda_mul_mat_vec_q accept the gate/up fusion for 2..4 columns when the dedicated PTQ1_0 kernel can take it (ggml_cuda_mmvq_ptq1_0_can_fuse_mc: plain 2D, K multiple of 128, shared memory within the limit). Merged with upstream's new MoE assert on the batch size. Patch 0006 (GLU output overlapping the q8 rows) is not included: it depends on prism's signed-FWHT + q8 quantizer graph fusion (ggml_cuda_try_fwht_q8), which this branch does not have yet. test-backend-ops ptq1_0: MUL_MAT 178/178, MUL_MAT_ID 85/85, MUL_MAT_VEC_FUSION 2/2; mtp_bench: all 8 output hashes identical to the commit before. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…output overlaps the q8 rows ktrain patch 0006 (PR PrismML-Eng#310, second part), applied as the net diff of pr/ptq1-gate-up-fuse-mc after 0005 (the GGML_CUDA_FWHT_GLU_POOL switch is not carried over): a gate/up pair that the mat-vec fuses with its SwiGLU writes the GLU output while other CTAs still read the q8 rows; when the allocator put the GLU output over that buffer, the fused FWHT quantizer now writes the rows to a pool block (out_aliases_in), and the fusion memory-range check ignores overlaps with inputs whose q8 rows live in a pool block (thread-local registry pointer, reset after each graph). Needs the signed-FWHT + q8 fusion of the previous commit. mtp_bench output hashes identical to the commit before. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…mML-Eng#314 open Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pn9UL41f3M8tRbqcHXFuB8
791eb61 to
869bc93
Compare
|
Rebased on current |
…mML-Eng#314 open Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pn9UL41f3M8tRbqcHXFuB8
869bc93 to
b416432
Compare
|
Rebased on current Decode against plain |
b416432 to
6da36cc
Compare
|
Rebased on current Re-measured against plain The description has the new numbers. |
…mML-Eng#314 open Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pn9UL41f3M8tRbqcHXFuB8
bri-prism
left a comment
There was a problem hiding this comment.
Thanks for the rebases. The ptq1_0_pt_smem_bytes build break is fixed and the 2-4 column test cases are in, so my earlier points are covered. A few things before I re-run on H200:
- The SWIGLU_CLAMP refusal in
ggml_cuda_should_fuse_mul_matis broader than intended. That helper is also used byggml_cuda_mul_mat_q_fusion_matches, so the guard turns off the MMQ gate/up/GLU fusion for SWIGLU_CLAMP at every prompt width and for every quant type. It also makes that check depend on ne[1], and graph_optimize relies on it being batch-size independent. The simplest fix is probably to add the SWIGLU_CLAMP case to the two GLU switches inmul_mat_vec_ptq1_0_pt(ggml_cuda_op_swiglu_clamp_singlewithfusion.glu_limit) and drop the guard. That also covers the 1-column PT path, which currently falls into thedefault:branch for that op. ggml_cuda_mmvq_ptq1_0_can_fuse_mcchecks src0's ne[2]/ne[3], but the PT switch bails on dst's channel/sample counts. A broadcast 2D weight with a batched src1 would pass the graph check and then hit the "fusion only supported for ncols_dst=1" assert in the generic path. Checking dst->ne[2] == 1 && dst->ne[3] == 1 there would keep guard and launch in sync.- prism has moved again (GGML_CUDA_FWHT_MMQ landed in
ggml_cuda_try_fwht_q8, right next to your look-ahead). Please rebase and confirm the build. Since the outputs differ slightly from prism at -ub 2..4, could you also repeat the three-way KLD check (branch, prism, prism with GGML_CUDA_DISABLE_FUSION=1) on the new base? That will tell us which path is the closer one. - Small things: please add GEGLU and SWIGLU_OAI cases at 2-4 columns since the kernel handles them, and move the
g_fwht_q8_ctxdeclaration above the "returns whether the write (out) nodes..." comment so the comment stays with its function.
FYI, this will conflict trivially with #314 (both touch the fusion assert in the PT launcher and insert code at the same spot in ggml-cuda.cu). Whichever lands second needs a quick rebase.
6da36cc to
553d23b
Compare
|
Thanks for the detailed review. Rebased onto current
Full As you said, this and #314 touch the same spots; I will rebase whichever lands second. The description is updated. |
bri-prism
left a comment
There was a problem hiding this comment.
Thanks, this covers everything from my last pass:
- SWIGLU_CLAMP is handled in both PT epilogues and the guard in
ggml_cuda_should_fuse_mul_matis gone, so the MMQ fusion check is batch-size independent again. ggml_cuda_mmvq_ptq1_0_can_fuse_mcnow checks dst's channels and samples, so the graph check and the launcher assert use the same rule.- The three-way KLD table is useful. The branch matching the unfused computation at -ub 2..4 while prism's default path sits around 8e-4 is a good sign for this change. Prism's own gap at 2..4 columns is worth a separate look, but it doesn't need to block this.
- The GEGLU / SWIGLU_OAI / SWIGLU_CLAMP cases at 2..4 columns and the moved comment look good.
I also read through the q8 rows aliasing look-ahead and the g_fwht_q8_ctx skip in the memory range check. With the pointer cleared outside graph evaluation, the check stays conservative anywhere else, which is what I'd want.
Approving. Whichever of this and #314 lands second will need the small rebase you mentioned.
|
#314 is merged, so this now conflicts in the PT launcher assert and ggml-cuda.cu as expected. Could you rebase onto current |
The dedicated PTQ1_0 kernel (mul_mat_vec_ptq1_0_pt) is templated for fusion with any column count, but the graph check, an assert in ggml_cuda_mul_mat_vec_q and the launcher only allowed ncols_dst == 1. So gate + up + SwiGLU ran as three kernels in every FFN block of a 2-4 token verify step (speculative decoding, small batches). Allow the fused path for the dedicated kernel (plain 2D, K multiple of 128, shared memory within the limit; the graph check calls the same helper, ggml_cuda_mmvq_ptq1_0_can_fuse_mc, which uses the per-cc rows_per_item rule of the launcher so guard and launch agree on the shared memory). With more than one column the bias tensors have to be contiguous because the kernel indexes the bias like dst. Other types keep the one-column rule. ggml_cuda_check_fusion_memory_ranges refused the fusion in 24 of 64 FFN blocks of the Bonsai 2 verify graph: the GLU output overlaps src1, the Hadamard transform output, because ggml-alloc hands it the block that src1 released. The overlap is real when the q8_1 rows written by ggml_cuda_try_fwht_q8 live in that buffer, so the check was right. Now ggml_cuda_try_fwht_q8 puts the rows into a pool block when a following GLU of a consumer pair overlaps the buffer (the mechanism it already has for out_aliases_in), and the fusion memory check ignores an overlap with an input whose q8 rows are registered in a pool block (g_fwht_q8_ctx, reset by a scope guard after the graph evaluation). All 64 FFN blocks fuse. RTX 4070, Bonsai 2 27B PTQ1_0 + MTP head (n-max 2), q4_0 K/V, greedy, 4 prompts x 256 tokens, 8 interleaved A/B pairs, base prism c96baf4: decode 115.98 -> 117.16 tok/s (+1.02 %, 95 % CI [+0.96, +1.08] %), outputs identical in all runs, acceptance 74.0 % in both. Measured earlier with environment switches on an older base: the fusion alone +1.01 %, keeping it over the overlap another +0.33 %. Removing the whole change from the full patch stack costs 0.65 % at depth 0 and 0.37 % at 114688 tokens. tests: gate fused PTQ1_0 mat-vec cases with 2 to 4 columns in MUL_MAT_VEC_FUSION (538 -> 546 cases, all pass on CUDA0 together with MUL_MAT 1669, SWIGLU 24, RMS_NORM 51). SWIGLU_CLAMP: mul_mat_vec_ptq1_0_pt applies GGML_GLU_OP_SWIGLU_CLAMP (fusion.glu_limit) in both epilogues, so the fusion check needs no op-specific refusal (ggml_cuda_should_fuse_mul_mat is shared with the MMQ fusion check and stays batch-size independent). ggml_cuda_mmvq_ptq1_0_can_fuse_mc(src0, dst) also requires dst->ne[2] == 1 and dst->ne[3] == 1, like the PT launcher. tests: GEGLU, SWIGLU_OAI and SWIGLU_CLAMP cases at 2-4 columns. Rebased on prism f702476. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
553d23b to
15337ae
Compare
|
Rebased onto current Re-checked on the RTX 4070 against plain
Full |
Overview
The dedicated PTQ1_0 kernel (
mul_mat_vec_ptq1_0_pt) is templated for gate + up + SwiGLU fusion with any column count, but the graph check, an assert inggml_cuda_mul_mat_vec_qand the launcher only allowedncols_dst == 1. So gate + up + SwiGLU ran as three kernels in every FFN block of a 2-4 token verify step (speculative decoding, small batches).ggml_cuda_mmvq_ptq1_0_can_fuse_mc, so guard and launch agree). With more than one column the bias tensors have to be contiguous. Other types keep the one-column rule.prismfuses, includingGGML_GLU_OP_SWIGLU_CLAMP(fusion.glu_limit), so the fusion check needs no op-specific refusal. The 2-4 column guard also requiresdst->ne[2] == 1 && dst->ne[3] == 1, like the PT launcher.ggml_cuda_check_fusion_memory_rangessaw the GLU output overlapsrc1. The overlap is real when the q8_1 rows written byggml_cuda_try_fwht_q8live in that buffer, so the check was right.ggml_cuda_try_fwht_q8puts the rows into a pool block when a following GLU of a consumer pair overlaps the buffer, and the check ignores an overlap with an input whose q8 rows are registered in a pool block. All 64 FFN blocks fuse.RTX 4070, Bonsai 2 27B PTQ1_0 + MTP head (n-max 2), q4_0 K/V, against plain
prismf70247610: decode 114.21 -> 115.84 tok/s (median, +1.43 %, 95 % CI [+1.40, +1.45] %, 8 interleaved pairs; +0.99 % on6447906bf). Perplexity at the default batch size is identical. The outputs are not identical toprism(see below).Additional information
One commit, 5 files (+98/-11).
g_fwht_q8_ctxis reset by a small scope guard after the graph evaluation.Update since the last description: re-based from
6447906bftof70247610without conflicts and the review points of 2026-11-25 addressed (SWIGLU_CLAMP in the kernel instead of the guard, dst channel check, more test cases, three-way KLD below); numbers re-measured on the new base.Tests: new
MUL_MAT_VEC_FUSIONcases for gate fused PTQ1_0 mat-vec with 2 to 4 columns (SWIGLU, GEGLU, SWIGLU_OAI, SWIGLU_CLAMP). The fulltest-backend-ops test -b CUDA0run on this branch: 21647/21647 passed.Outputs and KL. Greedy text of 4 prompts x 256 tokens: the German prompt differs from
prism(the same in all runs), draft acceptance 72.1 -> 72.2 %. Three-way KL divergence withllama-perplexity -b 512 -ub N(so every batch runs through the 2-4 column kernel), 16 x 512 tokens of a German text, base logits fromprismwithGGML_CUDA_DISABLE_FUSION=1at the same-ub:-ubprism: mean KLD ↓ / 99 % ↓ / same top ↑↓ less is better, ↑ more is better. The branch matches the unfused computation (max KLD 0.000054);
prism's default path at 2-4 columns differs from it by about 0.0008. I did not isolate which part ofprismcauses that. Perplexity at-b 2048 -ub 2048is identical (12.7657).test-backend-opsdoes not cover the buffer aliasing handled by the pool block (it depends on how ggml-alloc places the tensors of a real graph); for that I rely on the full-model outputs and the KL above.Measured on one Ada GPU and one model family. HIP: the helper returns false there.
On
prismand on this branch oneMUL_MATcase fails now and then (pq2_0, m=1, n=1, k=1024, ERR 0.0006 to 0.0013 against 0.0005; 4 of 25 repeated runs onprism, 3 of 25 on this branch). It depends on the random inputs and does not involve this change.Test results
-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89.prismatf70247610.--spec-type draft-mtp --spec-draft-n-max 2, q4_0 K/V cache, one slot.prismand the branch, 4 greedy prompts x 256 tokens, alternating runs, 8 pairs, 95 % bootstrap interval; run-to-run noise about 0.04 %.Requirements
🤖 Generated with Claude Code