Skip to content

cuda : fused Gated DeltaNet decode chain at 2-8 tokens with the speculative rollback store (gfx1151) - #294

Closed
neavra wants to merge 1 commit into
halo-box:sync/upstream-2026-11-15-e574a17b0from
nbitslabs:pr/gdn-decode-rollback
Closed

neavra wants to merge 1 commit into
halo-box:sync/upstream-2026-11-15-e574a17b0from
nbitslabs:pr/gdn-decode-rollback

Conversation

@neavra

@neavra neavra commented Nov 17, 2026 •

Copy link
Copy Markdown

Overview

Based on the #293 sync tip (1ab579a) and targeting that branch so the diff shows only this commit; to be retargeted to master once #293 merges.

HIP / gfx1151 (Strix Halo). The fused Gated DeltaNet decode step (ggml_cuda_try_gdn_decode_fusion, from #150)
matches a single-token graph that writes the conv state in place. llama-server does not emit that graph when it
serves with a draft: a 2-8 token verify step keeps rollback snapshots, so the conv state goes through the SET_ROWS
store form (ARANGE -> SCALE -> cast -> SET_ROWS over the K slots). That form never matched, at any row count, so in
serving every Gated DeltaNet layer ran the unfused conv, norm, gate and delta-net kernels on every verify step. On
Qwen3.8-Flash-Next (36 GDN layers) that is about 450 launches per 4-token pass that the fusion was meant to remove,
invisible to llama-bench, which emits the in-place form and fuses.

This PR teaches the matcher the rollback store form at 2-8 tokens and runs the chain for all tokens in one launch,
writing the K rollback slots the unfused graph would write (slot s holds the window that starts at column
n_tokens - s). The fused kernel spells softplus as log1pf(expf(x)) like the unfused op, so the fused path produces
the same bits as the chain it replaces.

  • GGML_CUDA_FUSE_GDN_DECODE_T=0 restores the unfused chain.
  • The single-token rollback form keeps the existing path; GGML_CUDA_FUSE_GDN_DECODE_T1=1 widens the match to one token
    (left off by default until verified on a model end to end).
  • AMD only: the fusion is taken on RDNA3.5 like the existing one. The CUDA build is untested here (no NVIDIA hardware);
    the new code is ordinary CUDA C++ next to the existing matcher.

Scope: ggml-cuda.cu (matcher), gated_delta_net.cu/.cuh (the rollback-slot store in the fused kernel),
tests/test-backend-ops.cpp (rollback-chain cases at 2-8 tokens with a single-token sequential reference; the test-mode
context gets a per-test tensor budget because the reference builds n_tokens + 1 chains).

Duplicate check

Measurements

Device:     Ryzen AI Max+ 395 / GMKtec EVO-X2 (Radeon 8060S, gfx1151)
Memory:     128 GB LPDDR5X-8000
Power:      balanced profile, governor powersave / EPP balance_performance
Kernel:     7.2.13-200.fc44.x86_64 (Fedora 44), amdgpu.gttsize=126976 ttm.pages_limit=32505856
Backend:    ROCm 7.1.1 (rocm-hip-devel-7.1.1-3.fc44, hipcc clang 20.0.0.rocm)
Build:      -DGGML_HIP=ON -DGPU_TARGETS=gfx1151 -DGGML_NATIVE=ON -DCMAKE_BUILD_TYPE=Release, ccache
Base:       1ab579ab6 (#293 sync tip); PR head ad7020706 = base + this one commit
Model:      Qwen3.8-Flash-Next UD-IQ4_XS (dense repacked Q8_0), MTP draft shared-Q8_0

Both arms built the same way in the same session, run in the order base, PR, PR, base with the box's six services
stopped for the window.

llama-bench -fa on -ctk f16 -ctv f16 -b 2048 -ub 1024 -p 1,2,4,8 -n 32 -r 5, t/s per run (llama-bench emits the
in-place form, so the new match is not taken here; the numbers show the change is neutral where it does not fire):

test base PR
pp1 25.41 ± 1.57 / 25.80 ± 1.33 25.85 ± 1.33 / 25.87 ± 1.32
pp2 43.04 ± 3.77 / 45.21 ± 0.51 45.35 ± 0.46 / 45.38 ± 0.52
pp4 73.49 ± 0.54 / 75.28 ± 0.49 74.63 ± 0.51 / 74.85 ± 0.53
pp8 93.10 ± 0.91 / 86.51 ± 18.66 90.91 ± 1.47 / 91.25 ± 1.53
tg32 27.40 ± 0.09 / 27.45 ± 0.60 27.75 ± 0.03 / 27.76 ± 0.03

llama-server (-c 16384 -b 1024 -ub 1024 -fa on), three 8k-token prompts (code, prose, agentic), 256 generated
tokens, greedy. 4-row: --spec-type draft-mtp --spec-draft-n-max 3, two cells per arm, two repetitions per cell; 1-row:
plain decode, two cells per arm. Decode t/s, min-max over the cells (mean in brackets):

prompt base 4-row PR 4-row base 1-row PR 1-row
code-8k 37.0-41.4 (40.2) 40.4-42.7 (42.1) 25.2-25.5 (25.3) 25.3-25.4 (25.4)
prose-8k 36.3-37.5 (37.2) 37.7-38.8 (38.5) 24.6-25.4 (25.0) 25.3-25.4 (25.4)
agentic-8k 36.2-37.6 (37.1) 37.4-38.8 (38.4) 24.3-25.3 (24.8) 25.2-25.4 (25.3)

4-row decode +3.5 to +4.7 % on the means; 1-row unchanged (the match starts at 2 tokens). Prompt processing of the 8k
prompts is unchanged (8.4-8.7 s both arms). The first repetition of the first cell after the service stop reads low on
both arms (cold caches); it is included in the ranges above.

Output streams: the greedy token stream of every cell is identical to base, per prompt, at 1 and 4 rows (same stream
hash across all four arms); draft acceptance is unchanged.

Per-op profile of the 4-token verify graph (8538 nodes; GGML_CUDA_OP_PROF=1 GGML_CUDA_DISABLE_GRAPHS=1, 64 tokens
on the prose prompt): 63.9 ms over 2299 launches -> 60.4 ms over 1844 launches. The unfused conv, norm, gate and
delta-net kernels of the 36 GDN layers leave the profile and the fused step appears once per layer (it is accounted
under the chain's CONCAT node: 1.0 ms -> 2.2 ms).

Tests

test-backend-ops test -b ROCm0 on the PR head: 45212/45212 passed (the full suite, including the new rollback-chain
cases and the existing GDN cases).

Written with Claude, tested by me.

🤖 Generated with Claude Code

…lative rollback store (gfx1151)

The fused GDN decode step (ggml_cuda_try_gdn_decode_fusion) only matched a single-token
graph that stores the conv state in place. llama-server verifies MTP drafts with 2-8 tokens
per step and keeps rollback snapshots, so the GDN chain was emitted with the SET_ROWS store
form (ARANGE -> SCALE -> cast -> SET_ROWS over K slots) at every row count, and no layer
ever fused in serving: every verify step ran the unfused conv, norm, gate and delta-net
kernels, about 430 launches per 4-token pass on Qwen3.8-Flash-Next.

The matcher now recognises the rollback store form at 2-8 tokens and runs the chain in one
launch for all tokens, writing the K rollback slots the unfused graph would write (slot s
holds the window that starts at column n_tokens - s). The softplus in the fused kernel is
spelled log1pf(expf(x)) like the unfused op, so the fused path is bit-identical to the chain
it replaces. The single-token rollback form is left to the existing path by default
(GGML_CUDA_FUSE_GDN_DECODE_T1=1 widens the match to 1 token);
GGML_CUDA_FUSE_GDN_DECODE_T=0 restores the unfused chain.

tests: test-backend-ops builds the rollback chains contiguously, with a single-token
sequential reference, and gives the test-mode context a per-test tensor budget.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants