Skip to content

cuda: gate (SwiGLU) fused PTQ1_0 mat-vec for 2-4 columns - #310

Open
sb32445 wants to merge 1 commit into
PrismML-Eng:prismfrom
sb32445:pr/ptq1-gate-up-fuse-mc
Open

sb32445 wants to merge 1 commit into
PrismML-Eng:prismfrom
sb32445:pr/ptq1-gate-up-fuse-mc

Conversation

@sb32445

@sb32445 sb32445 commented Oct 4, 2026 •

Copy link
Copy Markdown

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 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).

  • The fused path is allowed for the dedicated kernel (plain 2D, K a multiple of 128, shared memory within the limit; the graph check calls the same helper, 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.
  • The kernel applies all GLU ops prism fuses, including GGML_GLU_OP_SWIGLU_CLAMP (fusion.glu_limit), so the fusion check needs no op-specific refusal. The 2-4 column guard also requires dst->ne[2] == 1 && dst->ne[3] == 1, like the PT launcher.
  • In 24 of 64 FFN blocks of the Bonsai 2 verify graph the fusion was refused because ggml_cuda_check_fusion_memory_ranges saw the GLU output overlap src1. 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. ggml_cuda_try_fwht_q8 puts 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 prism f70247610: decode 114.21 -> 115.84 tok/s (median, +1.43 %, 95 % CI [+1.40, +1.45] %, 8 interleaved pairs; +0.99 % on 6447906bf). Perplexity at the default batch size is identical. The outputs are not identical to prism (see below).

Additional information

  • One commit, 5 files (+98/-11). g_fwht_q8_ctx is reset by a small scope guard after the graph evaluation.

  • Update since the last description: re-based from 6447906bf to f70247610 without 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_FUSION cases for gate fused PTQ1_0 mat-vec with 2 to 4 columns (SWIGLU, GEGLU, SWIGLU_OAI, SWIGLU_CLAMP). The full test-backend-ops test -b CUDA0 run 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 with llama-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 from prism with GGML_CUDA_DISABLE_FUSION=1 at the same -ub:

    -ub prism: mean KLD ↓ / 99 % ↓ / same top ↑ this branch: mean KLD ↓ / 99 % ↓ / same top ↑
    2 0.000807 / 0.004460 / 98.41 % 0.000000 / 0.000033 / 100 %
    3 0.000843 / 0.004827 / 98.26 % 0.000000 / 0.000034 / 100 %
    4 0.000843 / 0.004827 / 98.26 % 0.000000 / 0.000034 / 100 %

    ↓ 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 of prism causes that. Perplexity at -b 2048 -ub 2048 is identical (12.7657).

  • test-backend-ops does 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 prism and on this branch one MUL_MAT case 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 on prism, 3 of 25 on this branch). It depends on the random inputs and does not involve this change.

Test results

  • Hardware / software: RTX 4070 12 GB (AD104, cc 8.9), Linux 6.18, NVIDIA driver 620.73, CUDA 13.5, GCC 16.2; Release build, -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89.
  • Base: prism at f70247610.
  • Model: Ternary-Bonsai-2-27B (PTQ1_0) with a community MTP draft head (Q8_0), --spec-type draft-mtp --spec-draft-n-max 2, q4_0 K/V cache, one slot.
  • Method: separate builds of prism and the branch, 4 greedy prompts x 256 tokens, alternating runs, 8 pairs, 95 % bootstrap interval; run-to-run noise about 0.04 %.
  • Not tested: other GPUs, more than 4 columns (they keep the old path), HIP, models other than PTQ1_0.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: The patches were developed with Claude Code (Anthropic's coding agent): it wrote the code, the measurement scripts and the first drafts of the commit messages and PR texts. I decided what to work on (which kernels and host paths to optimise, based on profiles of my own decode setup). The measurements and checks listed in the PR texts were run in the Claude Code sessions; I did not re-run them independently. I will maintain the changes. Commits where Claude Code was used carry a Co-Authored-By trailer.

🤖 Generated with Claude Code

@sb32445 sb32445 changed the title cuda: use the transposing concat kernel on all GPUs, not only on GB10 cuda: gate (SwiGLU) fused PTQ1_0 mat-vec for 2-4 columns Oct 4, 2026
sb32445 added a commit to sb32445/llama.cpp that referenced this pull request Oct 20, 2026
…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]>
sb32445 added a commit to sb32445/llama.cpp that referenced this pull request Oct 20, 2026
…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]>
sb32445 added a commit to sb32445/llama.cpp that referenced this pull request Oct 23, 2026
…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]>
sb32445 added a commit to sb32445/llama.cpp that referenced this pull request Oct 23, 2026
…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 bri-prism left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

sb32445 added a commit to sb32445/llama.cpp that referenced this pull request Oct 27, 2026
…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]>
sb32445 added a commit to sb32445/llama.cpp that referenced this pull request Oct 27, 2026
…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]>
@sb32445
sb32445 force-pushed the pr/ptq1-gate-up-fuse-mc branch from 791eb61 to 869bc93 Compare October 27, 2026 19:49
@sb32445

sb32445 commented Oct 27, 2026

Copy link
Copy Markdown
Author

Rebased on current prism (c96baf4ab) and squashed to one commit (869bc93a0). The ptq1_0_pt_smem_bytes build error is fixed, the test cases are now part of the PR, the environment switches are gone. MUL_MAT_VEC_FUSION 546/546 on CUDA0 (RTX 4070), decode +1.02 % (CI [+0.96, +1.08] %), outputs identical. The PR description is updated. Ready for the H200 re-run whenever convenient.

@sb32445

sb32445 commented Nov 2, 2026

Copy link
Copy Markdown
Author

Rebased on current prism (5628c7338), still one commit (b416432d1). Two changes against the previous version: the conflict with the new get_mmvq_mmid_max_batch assert is resolved, and the fusion is now refused for SWIGLU_CLAMP at more than one column. prism fuses that GLU op now, the 2-4 column kernel does not implement it, and MUL_MAT_VEC_FUSION glu_op=6 failed at 2 and 4 columns before the guard. MUL_MAT_VEC_FUSION is 1632/1632 on this branch (1624 on prism), MUL_MAT 2943/2943, perplexity identical.

Decode against plain prism 5628c7338: 116.22 -> 117.34 tok/s (median, +0.96 %; mean +0.88 %, CI [+0.70, +1.00] %, 8 pairs). One correction to the PR text: the outputs are not identical in all runs any more. One of four greedy prompts differs and the draft acceptance moves from 73.5 to 72.6 %. I measured the KL (llama-perplexity -ub 2/3/4, so that every batch runs through the 2-4 column kernel): the branch against prism has mean KLD 0.00084 and the same top token in 98.3 % of the positions; the branch against prism with GGML_CUDA_DISABLE_FUSION=1 is at KLD 0.000000 (max 0.000048), top-1 100 %. So the branch matches the plain unfused computation, and prism's default path for 2-4 columns is the one that moved by rounding since c96baf4ab. I did not find which commit does that. Updated numbers are in the PR description.

@sb32445

sb32445 commented Nov 16, 2026

Copy link
Copy Markdown
Author

Rebased on current prism (6447906bf, was 5628c7338); still one commit (6da36cc14), no conflicts and no change to the patch.

Re-measured against plain prism 6447906bf (RTX 4070, Bonsai 2 27B PTQ1_0 + MTP head, n-max 2, q4_0 K/V, 8 interleaved pairs): decode 115.19 -> 116.31 tok/s, +0.99 % (95 % CI [+0.97, +1.02] %; was +0.96 %), draft acceptance 73.5 -> 72.6 %. KL divergence at -ub 4 (16 x 512 tokens): mean 0.000841 ± 0.000017, same top token 98.26 %, the same as before; the German prompt still differs in the greedy outputs. Full test-backend-ops test -b CUDA0: 20734/20734.

The description has the new numbers.

@bri-prism bri-prism left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The SWIGLU_CLAMP refusal in ggml_cuda_should_fuse_mul_mat is broader than intended. That helper is also used by ggml_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 in mul_mat_vec_ptq1_0_pt (ggml_cuda_op_swiglu_clamp_single with fusion.glu_limit) and drop the guard. That also covers the 1-column PT path, which currently falls into the default: branch for that op.
  2. ggml_cuda_mmvq_ptq1_0_can_fuse_mc checks 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.
  3. 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.
  4. Small things: please add GEGLU and SWIGLU_OAI cases at 2-4 columns since the kernel handles them, and move the g_fwht_q8_ctx declaration 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.

@sb32445
sb32445 force-pushed the pr/ptq1-gate-up-fuse-mc branch from 6da36cc to 553d23b Compare November 26, 2026 12:43
@sb32445

sb32445 commented Nov 26, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed review. Rebased onto current prism (f70247610, no conflicts) and squashed again to one commit (553d23bdc):

  1. SWIGLU_CLAMP: the guard in ggml_cuda_should_fuse_mul_mat is gone. mul_mat_vec_ptq1_0_pt handles GGML_GLU_OP_SWIGLU_CLAMP with ggml_cuda_op_swiglu_clamp_single(gate_value, result, fusion.glu_limit) in both epilogues (warp path and per-thread path), so the 1-column PT path no longer falls into default: for that op either.

  2. dst channels: ggml_cuda_mmvq_ptq1_0_can_fuse_mc now takes dst and also requires dst->ne[2] == 1 && dst->ne[3] == 1, the same as the PT launcher. The graph check and the assert in ggml_cuda_mul_mat_vec_q call it with dst.

  3. Build and KLD on the new base. Builds cleanly. Three-way check with llama-perplexity -b 512 -ub N, 16 x 512 tokens of a German text, base logits from prism with GGML_CUDA_DISABLE_FUSION=1 at the same -ub:

    -ub prism: mean KLD ↓ / 99 % ↓ / same top ↑ this branch: mean KLD ↓ / 99 % ↓ / same top ↑
    2 0.000807 / 0.004460 / 98.41 % 0.000000 / 0.000033 / 100 %
    3 0.000843 / 0.004827 / 98.26 % 0.000000 / 0.000034 / 100 %
    4 0.000843 / 0.004827 / 98.26 % 0.000000 / 0.000034 / 100 %

    ↓ less is better, ↑ more is better. So the branch is the closer one: it matches the unfused computation (max KLD 0.000054), while prism's default path at 2-4 columns differs by about 0.0008. I have not isolated which part of prism's path causes that.

  4. GEGLU, SWIGLU_OAI and SWIGLU_CLAMP cases at 2, 3 and 4 columns are added, and g_fwht_q8_ctx sits above the comment, which now belongs to its function again.

Full test-backend-ops test -b CUDA0: 21647/21647 passed. Decode against plain prism f70247610 on the RTX 4070 (Bonsai 2 27B PTQ1_0 + MTP head, n-max 2, q4_0 K/V, 8 interleaved pairs): 114.21 -> 115.84 tok/s, +1.43 % (95 % CI [+1.40, +1.45] %), draft acceptance 72.1 -> 72.2 %; the German prompt still gives a different greedy text than prism. Perplexity at -b 2048 -ub 2048 identical (12.7657).

As you said, this and #314 touch the same spots; I will rebase whichever lands second. The description is updated.

@bri-prism bri-prism left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this covers everything from my last pass:

  1. SWIGLU_CLAMP is handled in both PT epilogues and the guard in ggml_cuda_should_fuse_mul_mat is gone, so the MMQ fusion check is batch-size independent again.
  2. ggml_cuda_mmvq_ptq1_0_can_fuse_mc now checks dst's channels and samples, so the graph check and the launcher assert use the same rule.
  3. 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.
  4. 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.

@bri-prism

Copy link
Copy Markdown
Collaborator

#314 is merged, so this now conflicts in the PT launcher assert and ggml-cuda.cu as expected. Could you rebase onto current prism? I'll merge it once it's clean.

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]>
@sb32445
sb32445 force-pushed the pr/ptq1-gate-up-fuse-mc branch from 553d23b to 15337ae Compare November 26, 2026 21:13
@sb32445

sb32445 commented Nov 26, 2026

Copy link
Copy Markdown
Author

Rebased onto current prism (ce40e8137, with #314 merged); still one commit (15337ae0f). The only conflict was in ggml-cuda.cu, where the L2 hint helper from #314 and the q8 rows registry from this PR were added at the same place; both are kept. The PT launcher assert merged without a conflict (ncols <= 4 for the fused path, with the #314 prefetch arguments). git range-diff shows no other change to the patch.

Re-checked on the RTX 4070 against plain prism ce40e8137 (Bonsai 2 27B PTQ1_0 + MTP head, n-max 2, q4_0 K/V):

  • decode, 8 interleaved pairs: 116.93 -> 118.67 tok/s (medians), +1.49 % (95 % CI [+1.34, +1.73] %), draft acceptance 72.1 -> 72.2 %; the German prompt still differs in the greedy outputs, as before;
  • KL divergence against prism with GGML_CUDA_DISABLE_FUSION=1 (16 x 512 tokens): this branch 0.000000 / same top token 100 % at -ub 2 and -ub 4; prism's default path 0.000807 / 98.41 % and 0.000843 / 98.26 %, the same as in the three-way table;
  • perplexity at -b 2048 -ub 2048: 12.7657 for both.

Full test-backend-ops test -b CUDA0: 21646/21647. The failing case was MUL_MAT iq1_s m=16 n=1 (ERR 0.00062); it passed 5 of 5 reruns on both builds, and this PR does not touch iq1_s. In a full -o MUL_MAT rerun a pq2_0 m=1 case failed instead; that one is flaky on plain prism too: 20 interleaved runs of -o MUL_MAT -p type_a=pq2_0 fail one case in 3 of 20 on ce40e8137 and in 3 of 20 on this branch (m=1, n=1 or 2, ERR 0.0007 to 0.011).

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.

2 participants