Skip to content

CUDA: fuse the short convolution chain with its state store and residual - #411

Open
danielhanchen wants to merge 1 commit into
base/upstream-418fe97b5from
inkperf4-up-conv
Open

danielhanchen wants to merge 1 commit into
base/upstream-418fe97b5from
inkperf4-up-conv

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Pin for the prebuilt: upstream b12602 (418fe97) plus this one commit. Base branch base/upstream-418fe97b5.

What it changes

Inkling 2 runs a causal short convolution on k, v, the attention output and the FFN output of every layer: CONCAT(past, transpose(cur)), the conv state store (a CPY of the tail, or the DSpark rollback SET_ROWS with its ARANGE / SCALE / CAST slot order), SSM_CONV, optional dynamic taps (CONT, then MUL and ADD per lag), ADD(cur, out) and SCALE. That is up to 16 kernels per conv, 4 convs per layer visit. The matcher in ggml-cuda.cu runs the chain as one kernel per sequence and channel (conv-chain.cu) with the rounding of the separate ops:

  • the conv taps are an FFMA chain in tap order, as in ssm_conv_f32
  • every MUL and ADD of the dynamic taps rounds on its own (__fmul_rn / __fadd_rn)
  • the SCALE is contracted like scale_f32
  • inputs are held in registers, so the output may alias cur

Up to 32 tokens per sequence (decode, batched decode, speculative verify); longer ubatches keep the separate kernels. GGML_CUDA_DISABLE_SHORT_CONV_FUSION=1 turns it off. test-backend-ops gets CONV_CHAIN_FUSE (44 cases: 1-32 tokens, 1-4 sequences, with and without dynamic taps, CPY and rollback SET_ROWS stores, prefill unfused).

Evidence (B200, one exclusive card, load-gated runs)

  • Inkling-2-Mini decode: 192 conv_chain_f32 per token replace about 950 kernels.
  • With the other decode pins, tg128 UD-Q8_K_XL 86.3 -> 112.0 (+30%); this pin's share (the set with only it switched off): -13.1% on UD-Q8_K_XL, -11.5% on UD-Q4_K_XL.
  • KLD against the pin set (UD-IQ1_S, UD-Q4_K_XL, UD-Q8_K_XL, Mainline_Support UD-IQ1_S; prefill, -ub 1/4/8, dense 4K): PPL string equal, mean KLD 0, top-1 100%. DSpark accepted / drafted counts and greedy output identical.

Other NVIDIA GPUs (Colab T4, L4, A100-40GB, RTX PRO 6000 Blackwell Server; one card each, built from b12628 plus #399 plus the decode pins)

GPU (cc) file pp512 with it off tg128 with it off
T4 (7.5) UD-IQ1_S -0.9% -6.6%
L4 (8.9) UD-IQ1_S -0.3% -5.8%
L4 (8.9) UD-Q4_K_XL -0.5% -4.9%
A100 (8.0) UD-IQ1_S +0.0% -11.8%
A100 (8.0) UD-Q4_K_XL +0.0% -10.6%
A100 (8.0) UD-Q8_K_XL +0.0% -10.2%
RTX PRO 6000 (12.0) UD-IQ1_S +0.3% -9.7%
RTX PRO 6000 (12.0) UD-Q4_K_XL +0.0% -9.2%
RTX PRO 6000 (12.0) UD-Q8_K_XL +0.0% -8.2%
  • The fusion gives 5-12% at batch-1 decode on every GPU and leaves prefill unchanged (it declines above 32 tokens).

Needs the node order of the Inkling 2 graph from the #386 fold (inputs expanded before the conv, the conv result right after it); without it the matcher declines and nothing changes.

One kernel per sequence and channel for CONCAT(past, transpose(cur)), the
conv state store (CPY of the tail, or the rollback SET_ROWS with its
ARANGE/SCALE/CAST slot order), SSM_CONV, the optional dynamic taps
(CONT, then MUL and ADD per lag), ADD(cur, out) and SCALE. Up to 32
tokens per sequence; longer ubatches keep the separate kernels.

The arithmetic follows the separate kernels: the conv taps are contracted
in tap order like ssm_conv_f32, every MUL and ADD rounds on its own, and
the scale is contracted like scale_f32. Inputs are kept in registers, so
the output may alias cur.

Kill switch: GGML_CUDA_DISABLE_SHORT_CONV_FUSION=1.
Test: CONV_CHAIN_FUSE.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T02:26:27.545735Z 7e633d6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@paleluna82-del

Copy link
Copy Markdown

Tested #411, #412 and #414 together on AMD: R9700 (gfx1201, RDNA4), ROCm 7.2.4, Inkling-2-Mini UD-Q4_K_M, q8_0 KV. The three PRs are cherry-picked on top of #386 + #406. The only conflict was in tests/test-backend-ops.cpp between #412 and #414, resolved by keeping both.

Tests: CONV_CHAIN_FUSE 44/44, TANH_MUL_ADDSUB_FUSE 36/36, ROW_NORM_DIV_FUSE 25/25, ADD_RMS_NORM_FUSE 15/15, DEPTH_MIX_FUSE 115/115 (ROCm0 vs CPU).

Speed (tg128 45.1 and pp512 1612 with all fusions on; without the three PRs tg128 37.9, pp512 1515):

disabled pp512 tg128
none 1612 45.1
SHORT_CONV (#411) 1603 40.8
TANH_MUL_ADDSUB (#412) 1580 43.2
ROW_NORM_DIV (#412) 1599 44.4
DEPTH_MIX (#414) 1494 43.8

Output vs the same build without the three PRs (wikitext-2, -c 512, one fusion enabled at a time; the A/A floor here is KLD 0, max 6e-5):

enabled ubatch 16 notes
all off 0.000000
SHORT_CONV only 0.0031 (max 2.14) ubatch 1 / 4 / 32: 0.0014 / 0.0016 / 0.0020, top-1 ~98%; ubatch 512: 0 (not taken)
TANH_MUL_ADDSUB only 0.0007 (max 0.046)
ROW_NORM_DIV only 0.000000
ADD_RMS_NORM only 0.000000 not taken on AMD (cc >= 10.0 NVIDIA only)
DEPTH_MIX only 0.000000

So on HIP the depth mix and row-norm fusions are bit-exact. The short-conv fusion (#411) and the tanh fusion (#412) are not: the difference is rounding-level for this looped model, but not zero. For the short conv, a bit-exact HIP version is possible. In the version I dropped from #406, the kernel kept the unfused accumulation order (sumf += x[j]*w[j] over the window from 0, then sumf += b, then (res + sumf)*scale) and gave KLD 0 at ubatch 16 and with 4 sequences per ubatch. That suggests #411's kernel sums or contracts in a different order. In case it helps for the "exact" claim on non-NVIDIA backends.

erokhins pushed a commit to JetBrains-Hardware/llama.cpp that referenced this pull request Nov 24, 2026
abeloin added a commit to abeloin/llama.cpp-mix that referenced this pull request Nov 24, 2026
…residual (unslothai#411, commit 7e633d6)

Merge --no-ff du commit épinglé par unsloth (scripts/unsloth/pr-set.json).
Couche 2, liste A (banc/notes/couche2-unsloth-liste-2026-11-24.md côté
notes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QBjnvFeJ4P7Jp71oC6pzWf

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants