Skip to content

cuda: opt-in chunked MMA GDN prefill, enabled on Hopper (GGML_CUDA_GDN_MMA=1) - #387

Merged
bri-prism merged 1 commit into
prismfrom
gdn-chunked-mma-sm90
Oct 24, 2026
Merged

bri-prism merged 1 commit into
prismfrom
gdn-chunked-mma-sm90

Conversation

@bri-prism

Copy link
Copy Markdown
Collaborator

What

An opt-in chunked tensor-core prefill kernel for GATED_DELTA_NET on CUDA, enabled on Hopper: GGML_CUDA_GDN_MMA=1. Default off, so nothing changes unless the variable is set.

This is a port of ggml-org#29353 (am17an; the kernel comes from QVAC fabric, initial idea by lukdmine; MIT), taken through Cary Palmer's backport onto this fork. The backport adds three things to upstream:

  • Raw gates: they are activated into temporaries, using the formulas of the recurrent kernel's RAW path.
  • Fused state gather: the live state rows are copied to a contiguous s0 first.
  • K > 1 snapshot split: for one sequence, the MMA kernel runs the first n - K tokens into a temporary state, and the recurrent kernel runs the last K from it, writing the snapshot slots exactly as before.

Changes against the backport:

  • Hopper: cc 900 is added to the accepted architectures. Upstream only gates GA10x / Ada / Blackwell / GB10. The kernel is mma.sync BF16 and runs unchanged on sm_90.
  • Opt-in: the path is opt-in on every device (GGML_CUDA_GDN_MMA=1), like GGML_CUDA_GDN_L8, until defaults are measured per device family.

Why

Models: three quantized hybrid gated-delta-net targets (small, mid, large; low-bit weights). On H200 at the current tip, the recurrent GDN kernel is a large share of prefill GPU time. nsys, llama-bench, -fa 1, default -b 2048 -ub 512:

model pp512 pp4096 pp16384 pp32768
small 44% 44% 43% 42%
mid 27% 27% 26% 25%
large 17% 17% 16% 16%

With the chunked kernel, GDN time at pp16384 drops from 850 to 210 ms on the mid model (4.0x) and from 1863 to 530 ms on the large model (3.5x), summed over two prefills.

Results (H200, sm_90)

Prefill tok/s. ABBA on the same binary, env toggle only, llama-bench -r 3 per arm, mean of the two arms each:

model pp off on change
small 512 20198 26974 +34%
small 4096 23529 33520 +42%
small 32768 22253 31205 +40%
mid 512 9190 10971 +19%
mid 4096 9996 12369 +24%
mid 16384 9757 12063 +24%
mid 32768 9469 11497 +21%
large 512 2843 3215 +13%
large 4096 2921 3320 +14%
large 16384 2831 3086 +9%
large 32768 2646 2992 +13%

The small-model pp16384 "off" arm drifted 21% between A1 and A4, so it is left out. Drift on the other rows is 0.1-1.4%.

Accuracy. The kernel is not bit-exact (BF16 hi/lo split products, FP32 state). Measured with llama-perplexity --kl-divergence on the mid model, wikitext-2, base = the recurrent kernel:

mean KLD same top-1 PPL ratio
4k ctx (8 chunks), MMA on 0.00029 99.12% 1.0015
4k ctx, reference: tip with -ub 1024 instead of 512 0.00027 99.13% 1.0016
32k ctx (2 chunks), MMA on 0.00019 99.30% 1.0005
32k ctx, reference: tip with -ub 1024 0.00023 99.22% 1.0029
this branch, MMA off (both lengths) 0.000000 99.99-100% (identical logits up to the base's storage rounding)

The KLD is the same size as an ordinary micro-batch change. Upstream reported 0.00046 on its own models.

Long context, 64k. llama-server, mid model, 3 tasks x 2 reps, plain and MTP (K = 3 snapshots):

  • Correctness: answers are scored correct in every arm (code-edit and verbatim quote).
  • Determinism: each arm is deterministic across reps.
  • Divergence: output tokens diverge from the recurrent kernel after 270-371 tokens on two prose tasks (59 tokens on one with MTP). The answers are still correct.
  • Prefill at 64k: 8.7k to 10.4k tok/s plain (+20%), and 6.1k to 7.1k tok/s with MTP (+15%). The MTP case exercises the n - K / K split.

Tests. test-backend-ops -o GATED_DELTA_NET -b CUDA0: 72/72 pass with the path on and 72/72 with it off. The tip passes 56/56; this PR adds 16 MMA-shaped cases, which include raw gates, K > 1, rows mode, tails and several sequences. The failure set is unchanged (empty).

How

  • New files: ggml-cuda/gated-delta-net-mma.{cu,cuh}, the upstream kernel plus the backport's architecture check, with Hopper added.
  • gated_delta_net.cu: dispatches to the MMA kernel when the variable is set and at least 64 tokens go to MMA. It also handles raw-gate activation, the state gather and the K > 1 split. Otherwise it falls back to the recurrent kernel unchanged.
  • mma.cuh: swizzled ldmatrix loads and an 8-row ldmatrix_trans, from upstream. The existing 16-row path is unchanged.
  • Engagement logging: one WARN line logs when the chunked path first engages, and one logs when a prefill-sized op skips it.

Not covered:

  • Making the path default-on.
  • Other architectures beyond what upstream and the backport measured.
  • A single sequence with K > 1 and fewer than 64 MMA tokens; that case stays on the recurrent kernel.

…N_MMA=1)

Port of the chunked tensor-core GATED_DELTA_NET prefill kernel from
ggml-org#29353 (am17an; kernel from QVAC fabric, initial idea by
lukdmine; MIT), via Cary Palmer's backport onto this fork, which adds raw-gate
activation, the fused state gather and the K > 1 snapshot split: with
rollback snapshots (one sequence) the MMA kernel runs the first n - K tokens
and the recurrent kernel the last K, which write the snapshot slots as before.

Changes against the backport: Hopper (cc 900) is added to the accepted
architectures (upstream gates on GA10x/Ada/Blackwell/GB10 only; the kernel is
mma.sync BF16 and runs unchanged on sm_90), and the path is opt-in on every
device: GGML_CUDA_GDN_MMA=1. Default off, so default behaviour is unchanged
(bit-identical logits, KLD 0 vs this tip).

Not bit-exact (BF16 hi/lo split products, FP32 state). H200, mid-size quantized hybrid
gated-delta-net model, wikitext-2, KLD vs the recurrent kernel: 4k ctx 0.00029, 32k ctx 0.00019 -- the
same as running the current tip with -ub 1024 instead of 512 (0.00027/0.00023).

Co-authored-by: Cary Palmer <[email protected]>
@bri-prism
bri-prism merged commit 16cedb2 into prism Oct 24, 2026
7 of 8 checks passed
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