Repository navigation
CUDA: fuse the Inkling 2 short conv, depth mix, loop controller, L2 clip and situ chains - #33060
Merged
Merged
Conversation
am17an
marked this pull request as ready for review
November 25, 2026 18:30
Contributor
Author
|
@ServeurpersoCom I guess you're going to do similar changes to metal. I think we should find a way to do this fusions out of the box for any new model. For CUDA, nvrtc is an option and for Metal you can just build a shader on the fly. |
Contributor
Author
|
@ggml-org/ggml-cuda would appreciate a speedy review of this one. |
ngxson
approved these changes
Nov 26, 2026
Closed
1 task done
mbednarek360
pushed a commit
to mbednarek360/llama.cpp
that referenced
this pull request
Nov 26, 2026
Matches commit 1 of ggml-org#33060 so the short conv, taps, residual add and tau ops are consecutive for backend fusion.
am17an
force-pushed
the
aman/cuda-inkling2-fusions
branch
from
November 26, 2026 14:38
89478df to
5e8f72c
Compare
CISC
approved these changes
Nov 26, 2026
Contributor
|
Fix CI #33141 |
Member
|
@am17an CI is failing after this. |
Contributor
1 task
Contributor
|
The Decode speed (tg128, two rounds, 0 foreign processes):
|
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.
Overview
Decoding Inkling 2 Mini on CUDA launches about 5.7k kernels per token, most of them small ops on rows of
n_embd. This PR fuses five op chains of the Inkling 2 graph:convolve(), 192 per token):CONCATof the conv state and the input, the state store (CPYof the last columns, orSET_ROWSof the rollback windows whenn_rs_seq > 0),SSM_CONV, the input-dependent taps of the full-attention K/V convs, theADDof the input,SCALE, and the residualADDafter the attention and FFN output convs -> one kernelmix(), 120 per token):RMS_NORMofcur,CONCATwith the normalized stack, the scores against the queries,SOFT_MAX, the transposed copy of the states and the weighted sum -> one kernelcontrol(), 96 per token):CONCAT,RMS_NORM, the rank-64 down projection, the gain and forget projections,TANHand the combine -> two kernels, for batches of up to 8 tokensclip(), 144 per token):MULby the per-channel scale,L2_NORM,SCALEand theMULbytau-> one kernel (a variant ofl2_norm_f32innorm.cu)gate_up-> one kernelThe first commit only changes the order of the conv ops in the Inkling 2 graph (
ggml_build_forward_expandof the taps input, the conv result, the residual adds andtau), so each chain is consecutive and can be matched. The values do not change.The short conv kernel walks the tokens of a sequence with the last K columns in registers. The allocator usually runs the
ADDandSCALEin place over the conv input, so the fused output often aliases its input; this is safe when one thread has the whole sequence (decode and verify batches), and other overlaps are rejected.Additional information
Inkling 2 Mini IQ4_NL, RTX PRO 6000 Blackwell,
llama-bench -fa 1 -r 3, 3 interleaved rounds of master (2d5b3dd) and this PR:On the previous base (244640b): pp2 +37 to +43%, pp8 +34 to +40%, pp4096 +11 to +13%.
llama-perplexity -c 512 --chunks 16on wikitext-2 against master:-ub 256against master at the default ubatch is 0.00225-c 128 -ub 1 --chunks 4): mean KLD 0.0020, about half of it from the loop controllerSITU,L2_CLIP,SHORT_CONV(CPY and rollback-slot stores, taps, residual, K = 2..8, one token per thread and the sequential path),DEPTH_MIX(1/3/4 queries, 1..12 stack rows, the norm computed before the mix) andLOOP_CTRLcases pass on CUDA, and each of them runs the fused kernel.test-llama-archspasses forinkling2andinkling2_loop.Requirements