Repository navigation
CUDA: fuse the short convolution chain with its state store and residual - #411
danielhanchen wants to merge 4 commits into
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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: Speed (tg128 45.1 and pp512 1612 with all fusions on; without the three PRs tg128 37.9, pp512 1515):
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):
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 ( |
…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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QBjnvFeJ4P7Jp71oC6pzWf
…ore and residual (unslothai#411, commit 7e633d6)" This reverts commit e4799c7, reversing changes made to 5a6da34.
…re (2026-11-27) 8 reverts (pins ggml-org#402/ggml-org#411/ggml-org#412/ggml-org#414, biais indexé GPU et CPU, noyau tile rdna3 47fa88c/1d51ca3ef) puis merge --no-ff de b12801 (f6127ef). Banc r21 contre mix-b12723-r2 : Inkling tg +14 à +18 %, Gemma 4 prefill +8 %, Qwen3.6 décodage -7.3 % à 64k de profondeur (retrait de 47fa88c), perte acceptée par le propriétaire en attendant le report des chargeurs q8_0/q4_0 sur ggml-org#32901. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mix/wip-b12801: (89 commits) mix: MIX.md — banc r21 de la base b12801 contre mix-b12723-r2 : Inkling tg +14 à +18 %, Gemma 4 prefill +8 %, Qwen3.6 décodage -7.3 % à 64k (retrait de 47fa88c, report non minimal sur ggml-org#32901) ; reste décision et accord du propriétaire mix: MIX.md — b12801 posée (f6127ef) : 8 couches marquées RETIRÉ (pins ggml-org#402/ggml-org#411/ggml-org#412/ggml-org#414, biais indexé GPU et CPU, noyau tile rdna3 47fa88c/1d51ca3ef), build vert, test-backend-ops 22658/22658 ; reste banc vs mix-b12723-r2 et accord du propriétaire Revert "cuda : read q8_0/q4_0 K/V directly in the tile FA kernel on RDNA3" Revert "cuda : larger K/V staging for the head size 256 two-column tile kernel on RDNA" Revert "pr: biais indexé CUDA/HIP + graphe Inkling 2 (ggml-org#32740 GPU retiré, commit 9cd1953 inversé ; ggml-org#32899, commit aa74da8)" Revert "mix: ggml-cpu : accepter FLASH_ATTN_EXT avec biais indexé (calque à nous ; lève le refus ajouté par ggml-org#32740, commit 2392423)" Revert "pin: CUDA: fuse the SiTU gate of the MoE experts (unslothai#402, commit 0bfd204)" Revert "pin: CUDA: fuse the short convolution chain with its state store and residual (unslothai#411, commit 7e633d6)" Revert "pin: CUDA: fuse tanh-mul-add/sub, router weight normalization and add + rms_norm chains (unslothai#412, commit 874c88c)" Revert "pin: CUDA: fuse the depth mix (stack concat, scores, softmax, mix) into one kernel (unslothai#414, commit f766457)" mix: MIX.md — base b12801 choisie (2a33525) ; décisions du propriétaire : biais indexé et fusions Inkling 2 pris de l'amont (ggml-org#33063/ggml-org#33053, ggml-org#33060), retrait de nos calques 8fcc3e0 et b92222d et des pins ggml-org#402/ggml-org#411/ggml-org#412/ggml-org#414 ggml/CUDA+HIP: Flash Attention with indexed bias (ggml-org#33063) opencl: add MoE int8 bin kernel host side changes for Adreno A850 (ggml-org#33069) ci: relax spec dec acceptance length floor (ggml-org#33127) tests : relax the DEPTH_MIX tolerance to the mul_mat one (ggml-org#33141) ui: install the demo harness before the app's type check in CI (ggml-org#33145) ui: fix the phone model sheet's search field and reasoning row (ggml-org#33144) ui: NVFP4 as 4-bit in Discover, model details inside Search (ggml-org#33120) ui: move the demo harness to ui/lib/demo and render videos on the Llama brand (ggml-org#33125) CUDA: fuse the Inkling 2 short conv, depth mix, loop controller, L2 clip and situ chains (ggml-org#33060) ...
With the recurrent states read in place (7b74cb9), past is a view of the conv state cell that the CPY store writes. The overlap check between the store and past declined every decode chain. The kernel reads all of past before its single store, one thread per channel and sequence, so the exact alias with the same strides is safe; any other overlap is still declined. Adds CONV_CHAIN_FUSE cases where past is the state cell.
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:
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)
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)
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.
Recurrent states read in place (upstream 7b74cb9, b12816 and later)
Since b12816
build_rsreturns a view of the state cache, sopastis the same memory as the conv state cell the CPY store writes. The overlap check between the store andpastthen declined every decode chain (GGML_CUDA_CONV_CHAIN_DEBUG shows conv-chain.cu:363 on every one), and the dynamic-tap convs, which only this fusion handles, went back to the separate kernels. The kernel reads all ofpastbefore its single store, one thread per channel and sequence, so the commit on top acceptspastwhen it is exactly the stored cell with the same strides; every other overlap is still declined. CONV_CHAIN_FUSE gets 18 cases wherepastis the state cell (14 fuse, the 4 above 32 tokens keep the separate ops), 62/62 on its own base and in the pin set.On the round G pin set (b12823), Inkling-2-Mini decode is back to 32
conv_chain_f32launches per 64-token run, the same as on b12810, and PPL / KLD are string-equal with KLD 0 against b12823 with 7b74cb9 reverted.