Repository navigation
cuda: batch the rollback conv-state snapshot copies into one launch (+2.6% DFlash2 decode, exact) - #379
Merged
Conversation
The recurrent rollback writes one conv-state snapshot per slot (build_conv_state: K = n_rs_seq + 1 CPY nodes of a [3, 8192] window per GDN layer per step), each a launch-bound ~2.8 us copy. A run of F32 -> F32 CPY nodes that share shape and strides (only the data pointers differ), with only view nodes in between and no destination overlapping a later source or destination, now runs as one kernel with up to 32 pointer pairs. GGML_CUDA_BATCHED_CPY=0 restores one launch per copy. Bit-exact (a copy). New test CPY_SNAPSHOTS covers the pattern, including n_tokens < K (clamped, repeated windows) and runs longer than 32. H200, Ternary-Bonsai-2-9B PQ2_0-MTP, llama-server, identical tokens: DFlash2 depth 15 +2.5..+2.7%, MTP depth 3 +0.6%, no speculation +-0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRQc3TQpn72qBxrUn5vKqo
This was referenced Oct 23, 2026
bri-prism
added a commit
that referenced
this pull request
Oct 24, 2026
… mat-vecs (GGML_CUDA_GDN_FUSION=1), +5-10% decode on H200 (stacked on #379) (#383) Opt-in (GGML_CUDA_GDN_FUSION=1) exact fusion of the GDN decode conv chain into one kernel: conv-state get_rows, concat, state write-back, ssm_conv + silu, and the q/k L2 norm. The ssm_alpha/ssm_beta single-column mat-vecs run as one paired mmvf launch. Bit-exact: greedy tokens and top-k logprobs are identical with it on and off, including MTP. On H200: decode +5-10% (2B to 27B) and 9B +7.2%, with 90-240 fewer kernels per token. Default off. The fusion matcher's design follows the launch-bubble analysis behind Hazy Research's megakernel work.
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
With speculative decoding,
build_conv_statewrites one conv-state snapshot per rollback slot: K =n_rs_seq+ 1CPYnodes of a[3, 8192]window per GDN layer per step. Each one is a launch-bound copy of about 2.8 µs. On the 9B with DFlash2 at depth 15, nsys counts about 255k of these copies, 7.5% of GPU time.The CUDA backend now runs such a group of copies as one kernel, with up to 32 pointer pairs. A group qualifies when:
CPYnodes with only view nodes between them;GGML_CUDA_BATCHED_CPY=0restores one launch per copy.The batch performs the same copies, so the output is bit-identical. Graph-level changes would be harder: the snapshot windows overlap and have descending slot order, so they can't be expressed as a single ggml view.
Validation
All runs are on an H200 with CUDA 12.8 and a Release sm_90 build, at prism
73bfe6ccplus this patch.Correctness
CPY_SNAPSHOTS: 10/10 with and without the fusion. It covers 8192 and 37 channels,n_tokens< K (clamped, repeated windows) and runs longer than 32.CPY: 252/252.End to end: Ternary-Bonsai-2-9B PQ2_0-MTP-Q8_0 on llama-server, 4 prompts × 128 greedy tokens, 2 rounds, same binary with the env switch on and off. Generated tokens are identical in every mode.
The gain grows with
n_rs_seqand with launch overhead, so GPUs where launches cost relatively more should gain more. I only measured H200.Requirements
🤖 Generated with Claude Code
https://claude.ai/code/session_01PRQc3TQpn72qBxrUn5vKqo