Repository navigation
cuda: opt-in chunked MMA GDN prefill, enabled on Hopper (GGML_CUDA_GDN_MMA=1) - #387
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An opt-in chunked tensor-core prefill kernel for
GATED_DELTA_NETon 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:
Changes against the backport:
mma.syncBF16 and runs unchanged on sm_90.GGML_CUDA_GDN_MMA=1), likeGGML_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: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 3per arm, mean of the two arms each: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-divergenceon the mid model, wikitext-2, base = the recurrent kernel:-ub 1024instead of 512-ub 1024The 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):
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
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: swizzledldmatrixloads and an 8-rowldmatrix_trans, from upstream. The existing 16-row path is unchanged.Not covered: