Repository navigation
cuda : fused Gated DeltaNet decode chain at 2-8 tokens with the speculative rollback store (AMD) - #297
Conversation
dzannotti
left a comment
There was a problem hiding this comment.
Verdict
Changes requested. The fused verify path is exact and faster in our tests, but the PR adds a test harness abort (test-backend-ops test -o GATED_DELTA_NET) and two env knobs that the repo has moved away from.
Direction
Accept after work. This brings back the multi-token decode fusion that the SET_ROWS rollback store had turned off in serving, and the output does not change. The asks below are cleanup, not a redesign.
Asks
- Blocking.
ggml/src/ggml-cuda/ggml-cuda.cu:4380-4394,:4447,:4571andtests/test-backend-ops.cpp:7701-7720: please removeGGML_CUDA_FUSE_GDN_DECODE_TandGGML_CUDA_FUSE_GDN_DECODE_T1. fdf4ac7 removed this kind of A/B switch, andGGML_CUDA_DISABLE_FUSIONalready gives the unfused chain. T1 enables a path that nobody has verified on a model, the tests force it on withsetenv, and the value stays set for every later test in the process. Keep the 1-token rollback form unfused (if (n_tokens == 1) return 0;). Enabling it can be a later PR with model numbers. - Blocking.
tests/test-backend-ops.cpp:20979-20981:test_case_selectedbuilds every case in a 128-tensor context until the first-omatch. The new ident-2 cases need more, sotest-backend-ops test -o GATED_DELTA_NETaborts on head withggml.c:1955: GGML_ASSERT(obj_new) failedon every backend (base passes). The same happens for every op whose first case comes after:19198. CI does not use-o, so it stays green. Our suggestion is to delete the ident-2 cases (:7610,:7739,:19198): without T1 they repeat what ident 1 checks withmax_err 0. Then revertmax_tensors()(:1421,:1541). If you keep them, size every 128-tensor context bymax_tensors()(:1806,:1873,:2023,:2057,:20981). - Should fix. Some comments are stale.
gated_delta_net.cu:2031still saysn_tokens == 1.:2039says the result is bit-identical to the unfused graph, which is not true for the per-slot CPY form (logf(1 + expf(x))against the unfusedlog1pf(expf(x))).test-backend-ops.cpp:7588names qwen3.5, but the match does not fire on qwen35 (that model reads the state in place). The matcher doc comment atggml-cuda.cu:4374-4379now sits above the env helpers. AGENTS.md also asks for comments of 1-2 lines. - Should fix. Please re-indent the token loop body (
gated_delta_net.cu:2081-2261) and the CPYelsebranch of the matcher (ggml-cuda.cu:4604-4635). This code exists only in the fork, so the change does not add merge cost. - Should fix. Add an
Assisted-by:trailer to the commit (AGENTS.md, AI disclosure).
Nits, optional: test-backend-ops.cpp:7784 ggml_is_view_op(t->op) || is redundant. The gate is any AMD GPU, not only gfx1151. #296 is an issue, not a PR.
Correctness
PASS on ROCm, PASS on Vulkan for the smoke scope (the PR does not change Vulkan code). Server greedy runs with an MTP draft at --spec-draft-n-max 1, 3 and 7 (verify widths 2, 4 and 8, with rejected drafts) gave the same text, all 128 per-token top-5 probabilities and the same acceptance on master, on this PR, on this PR with the match turned off, and with HIP_LAUNCH_BLOCKING=1. A kernel trace showed that the fused kernel runs on head (35 of 36 GDN layers per verify graph; layer 0 does not fuse in plain decode either). We found these byte-identical between master and the PR: f32 final logits and prompt tokens on all four corpora, .kld and PPL short and long, 256-token greedy decode, and plain decode probabilities. The full ROCm test-backend-ops passed (56948/56948 on master, 56966/56966 on head) with HIP_LAUNCH_BLOCKING unset and =1. The new cases pass on Vulkan too. The -Werror build passed, and the VGPR gate shows no new spills (fused kernel 44 -> 70 VGPRs, no scratch).
Performance
Decode with MTP draft (--spec-draft-n-max 3, 128 tokens, 2 rounds, alternated), tok/s:
| prompt tokens | master | PR | gain |
|---|---|---|---|
| 319 | 31.66 / 31.56 | 32.37 / 32.13 | +2.0 % |
| 9068 | 32.73 / 32.72 | 33.37 / 33.41 | +2.0 % |
| 28387 | 48.67 / 48.48 | 49.57 / 49.63 | +2.1 % |
| 59946 | 40.63 / 40.54 | 41.56 / 41.45 | +2.3 % |
TTFT and acceptance are the same. The ranges do not overlap. We used a different quant from yours, so +2 % here against your +3.5 to +4.7 % is plausible. llama-bench (PP2048 at depths 0 to 64000, tg128, pp1/2/4/8) is neutral within stddev.
Verification
Strix Halo (gfx1151). We tested the PR merged into master 4032d8f (16 commits behind, clean merge) against master. Master then moved to 9a237d6. The PR still merges clean there, and the new commit does not touch these files or the GDN decode graph.
Not tested
NVIDIA CUDA, your UD-IQ4_XS model and Q8_0 draft, the full Vulkan suite, and verify graphs with more than one sequence (these do not fuse, by design).
Thank you for the careful write-up and the exact fused path.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
Linux 7.0.0 (Ubuntu), governor powersave. ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb691863. Mesa RADV 26.0.8 (Radeon 8060S). cmake 4.2.3, Ninja, gcc 15.2.0.
Compared
- Master tip: 4032d8f (base side).
- PR head: 90b3054.
- Merge base: f5e7a5d, 16 commits behind 4032d8f.
- Head side: local merge 275be099a (head into 4032d8f, no conflicts).
- Master later moved to 9a237d6 (#299:
src/llama-context.*,src/llama-memory-hybrid-idx.*, graph reservation only). The merge is still clean and the files do not overlap, so the results stand.
Build
HIP: cmake -G Ninja -S <tree> -B <tree>/build-hip -DCMAKE_BUILD_TYPE=Release -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R)
Vulkan: cmake -G Ninja -S <tree> -B <tree>/build-vk -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON -DGGML_HIP=OFF
-Werror (head): HIP line + -DCMAKE_HIP_FLAGS="-Werror -Wno-tautological-compare"
Metrics (both): HIP line + -DGGML_HIP_EXPORT_METRICS=On -DCMAKE_HIP_FLAGS="", target ggml-hip
Models
- Target (qwen4exp): Qwen3.8-Flash-Next Gyro-M TQ2_0, sha256 7aa36d15131d255179ab6c87fa9c9f81a0b541fc9e81e959d4c3e29eb20feb5f, run with
-lm none -lzm on-direct. - MTP draft: unsloth/Qwen3.8-Flash-Next-GGUF
MTP/mtp-Qwen3.8-Flash-Next-shared-Q4_K_M.gguf, sha256 f521868a9e143718bef513772f6e04d9642551e362cf2439636d2abdbd149dfc. - Control (qwen35, built-in MTP head): Qwen3.8-27B-UD-Q4_K_XL, sha256 3f227079003add2511437e5b1e94812e363385225bf6a9b47b0054a72bc8b01e.
- Corpora (tests/corpus): code dec1127a, numeric d9f08d94, prose c90398f2, structured c21947b3.
Commands
# ops
test-backend-ops test -b ROCm0 -o GATED_DELTA_NET,SSM_CONV,CONCAT,SET_ROWS,GDN_DECODE_ROLLBACK (HIP_LAUNCH_BLOCKING unset and =1)
test-backend-ops test -b ROCm0 -o <op> (one op per run: GATED_DELTA_NET, SSM_CONV, CONCAT, SET_ROWS, GDN_DECODE_ROLLBACK)
test-backend-ops test -b Vulkan0 -o GATED_DELTA_NET,SSM_CONV,CONCAT,SET_ROWS,GDN_DECODE_ROLLBACK
test-backend-ops test -b ROCm0 -j 4 (HIP_LAUNCH_BLOCKING unset and =1)
test-backend-ops support -b ROCm0 ; test-backend-ops grad -b CPU [-o ADD|SSM_CONV|GATED_DELTA_NET]
ctest --test-dir <build> -L main -E 'test-opt|test-llama-archs'
test-llama-archs -b ROCm0 -a 'qwen35|qwen35moe|qwen4exp'
ctest -R 'spec-mtp-pcum|draft-vocab|test-qwen4exp-mtp-cache-only' ; test-mtp-draft-vocab -m <27B>
# model parity (target model, -ngl 99 -fa on -ctk f16 -ctv f16)
llama-debug -m <model> -f correctness-<t>.txt -c 16384 -b 16384 -ub 512 --save-logits --logits-output-dir <dir> (HLB unset and =1), cmp logits + tokens
llama-perplexity -c 2048 -b 2048 -ub 2048 --kl-divergence-base <side>.kld ; head --kl-divergence vs base
llama-perplexity on the four corpora joined, -c 16384 -b 512 -ub 512
llama-completion -n 256 --temp 0 --seed 1 -no-cnv --ignore-eos -c 16384 (base x2, head x2)
# server, -c 16384 -b 2048 -ub 2048 -np 1 [-md <draft> -ngld 99 --spec-type draft-mtp --spec-draft-n-max 1|3|7]
POST /completion {"n_predict":128,"temperature":0,"n_probs":5,"cache_prompt":false,"seed":1,"ignore_eos":true}, prompts = first 6000 chars of each corpus
arms: master, PR, PR GGML_CUDA_FUSE_GDN_DECODE_T=0, PR GGML_CUDA_FUSE_GDN_DECODE_T1=1, master HLB=1, PR HLB=1, PR T=0 HLB=1
fusion proof: GGML_CUDA_OP_PROF=1 GGML_CUDA_DISABLE_GRAPHS=1 per verify graph; rocprofv3 --kernel-trace kernel counts
-np 2: one request alone in slot 1, and 3 concurrent pairs, x2 restarts, master / PR / PR T=0
# perf
llama-bench -p 2048 -d 0,12000,32000,64000 -n 0 -r 5 -b 2048 -ub 2048 (order master, PR, PR, master); -p 0 -n 128 -r 5; -p 1,2,4,8 -n 32 -b 2048 -ub 1024 -r 5
scripts/bench-spec-prefill.sh (master copy) at 319 / 9068 tokens; at 28387 / 59946 tokens the same logic with --data-binary @file (the script passes the prompt as one curl -d argument, which fails above ~128 KB); -c 72000 -b 2048 -ub 2048, n-max 3, 128 tokens, round 1 master,PR, round 2 PR,master
GGML_CUDA_DISABLE_GRAPHS=1 test-backend-ops perf -b ROCm0 -o GATED_DELTA_NET (master, PR, PR, master)
Results
- Ops ROCm0, combined filter: master 547/547, PR 565/565 (HLB unset and =1).
- One op per run: SSM_CONV 60, CONCAT 231, SET_ROWS 179, GDN_DECODE_ROLLBACK 8 (master) / 26 (PR), all pass. GATED_DELTA_NET: master 69/69, PR aborts rc 134 at
ggml.c:1955: GGML_ASSERT(obj_new) failed. - Ops Vulkan0: master 822/822, PR 840/840. The 26 GDN_DECODE_ROLLBACK cases (max_err 0) pass.
- Full ROCm0 suite: master 56948/56948, PR 56966/56966, HLB unset and =1.
- support full: rc 0 on both. grad full: rc 134 on both at REGLU (pre-existing on master). grad -o ADD/SSM_CONV/GATED_DELTA_NET and support -o GATED_DELTA_NET: rc 0 on both.
- ctest -L main: 35/35 on both. test-llama-archs qwen35/qwen35moe/qwen4exp: OK on both. Spec ctest 3/3 on both. test-mtp-draft-vocab: PASS on both.
- Fusion in the tests: the rows cases fuse on the PR (OP_PROF). With T=0 none fuse, and the cases still pass. So the tests cannot see a silent loss of the fusion.
- Fusion in the model (n-max 3, rocprofv3): PR 560 fused + 560 norm kernels, unfused GDN/SSM_CONV 684 -> 124 (prefill and layer 0). Master and T=0: 0 fused. Each single-sequence verify graph fuses 35/36. Two-sequence verify graphs fuse 0 (rejected by the matcher).
- Server parity: 4 prompts x n-max 1/3/7, 7 arms each. Content, completion_probabilities and draft/accepted counts are identical in all 12 cells. Rejected drafts are present (for example prose n-max 7, 80/321 accepted).
- qwen35 27B control: same output on master and the PR, 0 fused (in-place state read, not matched).
- -np 2: one request alone is identical on all sides. Concurrent pairs vary at the same positions on master, the PR and T=0 alike (arrival order).
- Vulkan server smoke (n-max 3, 4 prompts): identical on master and the PR.
- Kernel resources gdn_decode_fused_cuda<128,4>: master 44 VGPR / 23 SGPR, PR 70 VGPR / 76 SGPR, scratch 0, LDS 3104 on both. Spill gate: 0 VGPR spills on both sides, the same 11 SGPR baseline entries.
- Memory: peak 41.0 GiB GTT with the target model loaded.
Correctness
| check | method | result |
|---|---|---|
| test-backend-ops changed ops | ROCm0 and Vulkan0, HLB unset/=1 | pass, except the -o GATED_DELTA_NET abort on the PR (Ask 2) |
| full backend suite | ROCm0 -j 4, HLB unset/=1 | pass, no head-only failure |
| test-vk-exact | not run | does not apply: no Vulkan code change |
| f32 logits + prompt tokens | llama-debug, 4 corpora, HLB unset/=1 | byte-identical |
| KLD/PPL short | -c 2048, 4 corpora | .kld identical, PPL equal |
| KLD/PPL long | joined corpora, -c 16384 | .kld identical, PPL 2.1522 both |
| greedy decode A/A | llama-completion 256 tokens | 4/4 identical |
| spec output at temp 0 | server, n-max 1/3/7, 7 arms | identical text, probs, acceptance |
| spec unit tests | ctest spec-mtp-pcum, draft-vocab; test-mtp-draft-vocab | pass |
| -Werror build | HIP | pass |
| VGPR spill gate | gcn-cdna-vgpr-check.py | no new spills (same result on both sides) |
| spec throughput | bench-spec-prefill, 4 depths, 2 rounds | +2.0 to +2.3 % tg |
| llama-bench | PP2048 d0-64000, tg128, pp1-8 | neutral |
Performance
llama-bench avg_ts (runs in order master, PR, PR, master; listed as master runs then PR runs):
- pp2048 d0: master 1106.48 +- 35.05 / 1085.60 +- 0.92 / 1104.18 +- 35.41 / 1085.84 +- 0.68; PR 1105.57 +- 35.06 / 1086.20 +- 0.96 / 1105.24 +- 35.12 / 1086.00 +- 0.79 (+0.02 %).
- d12000: master 1006.87 / 1003.51 / 1005.22 / 1002.56; PR 1006.52 / 1002.94 / 1006.86 / 1003.18 (+0.03 %).
- d32000: master 992.85 / 988.73 / 993.13 / 987.26; PR 991.97 / 988.72 / 992.83 / 990.18 (+0.04 %).
- d64000: master 984.61 / 980.16 / 985.40 / 978.26; PR 985.22 / 979.41 / 985.89 / 979.05 (+0.03 %).
- tg128: master 28.10 x3 / 28.09; PR 28.07 / 28.07 / 28.07 / 28.08 (-0.08 %, stddev 0.01-0.04).
- pp1 26.17-26.99 vs 26.23-27.01. pp2 44.01-44.25 vs 43.96-44.27. pp4 72.54-72.99 vs 72.19-72.93. pp8 86.63-87.03 vs 86.28-87.01. tg32 28.16-28.46 vs 28.16-28.43.
- Spec decode: see the table above. TTFT master/PR in ms at 319, 9068, 28387 and 59946 tokens: 719/735 vs 722/725; 11070/11107 vs 11085/11103; 34924/35032 vs 34971/35007; 74371/74498 vs 74499/74498. Acceptance 44 %, 54 %, 99 % and 77 % on both sides. The tg spread inside an arm is 0.2 tok/s or less.
- GATED_DELTA_NET op perf (graphs off): 22 cases, max delta 1.8 % (noise). The new cases have no perf mode.
Findings in full
- Ask 1: two env knobs. T1 is read with
getenvon every call, unlike the other cached switches in ggml-cuda.cu. The tests set both withsetenv/_putenv_s, and the value leaks to later cases. With-j 4, thatsetenvruns at the same time asgetenvin other threads. - Ask 2: the
-oabort, explained above. It happens only when the first matching case of the filter comes after the ident-2 cases. - Ask 3 and Ask 4: comments and indentation, as listed.
- Follow-up, not needed for this PR: no model emits the per-slot CPY form with K > 1 any more (
build_conv_state_storeemits one CPY when there are no rollback slots, and SET_ROWS otherwise). Soconv_fill_tail, the tail memcpy atgated_delta_net.cu:2305-2311and the CPY K > 1 cases cover a form that only the tests build. With that path gone,log1pfcould be used everywhere andsoftplus_log1premoved. That would change plain-decode bits back to the unfused result, so it belongs in its own PR. - Kernel review: the shared buffers reused across the token loop have no hazard between tokens (every reuse has a barrier between the last read and the next write). The state carried in registers equals the per-token launches, which read back the slot just written.
- Test coverage: the max_err 0 cases also pass when the fusion does not fire. A dispatch counter or debug check for CUDA fusions would catch a silent loss in the future (follow-up idea).
Claims
- The matcher takes the SET_ROWS rollback store at 2-8 tokens: reproduced (35/36 layers per verify graph).
- The fused path gives the same bits as the chain it replaces: reproduced (server text and probabilities, 7 arms).
GGML_CUDA_FUSE_GDN_DECODE_T=0restores the unfused chain: reproduced.T1=1widens the match to one token: no effect in the model (verify passes are never 1 token here). It fuses the (1,4) test case.- llama-bench is neutral: reproduced.
- +3.5 to +4.7 % 4-row decode: partly reproduced, +2.0 to +2.3 % with a different quant.
- Greedy streams and acceptance unchanged: reproduced.
- Full ROCm0 suite passes: reproduced.
- CUDA build untested: not tested here (no NVIDIA hardware).
Not tested
NVIDIA CUDA (no hardware). The author's UD-IQ4_XS model and Q8_0 draft (not available here; we used another quant of the same model family). The full Vulkan suite (the PR changes no Vulkan code; the targeted ops and a server smoke ran). ops-perf.sh. Fusion with more than one sequence per verify graph (the matcher rejects it).
90b3054 to
a1c1716
Compare
…review) Review of halo-box#297 (dzannotti): GGML_CUDA_DISABLE_FUSION already gives the unfused chain, so GGML_CUDA_FUSE_GDN_DECODE_T goes; the one-token rollback form stays on the existing path (GGML_CUDA_FUSE_GDN_DECODE_T1 goes with it, enabling it is a later PR with model numbers). The ident-2 test cases needed a larger test-mode context, which made `test-backend-ops test -o <op>` abort for every op listed after them; without T1 they repeat the ident-1 max_err 0 check, so they are removed and max_tensors() is reverted. Stale comments fixed, the token loop body and the CPY matcher branch re-indented, the redundant ggml_is_view_op() check dropped. Assisted-by: Claude Fable 5.1 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Thank you for the thorough run, the fusion counts and the depth table are more than I could measure here. Pushed as a second commit on top of the original (which now carries the
Nits: the redundant Not re-measured after the rebase: the decode numbers in the body are from the measured base; no commit between it and cb82e57 touches these files or the GDN graph. |
dzannotti
left a comment
There was a problem hiding this comment.
Verdict
Approved. Both blocking asks from our last review are fixed: the env knobs are gone, and test-backend-ops test -o GATED_DELTA_NET passes again. The PR rebased onto current master is exact against master and is about 2 % faster in MTP decode.
Direction
Accept. The fused verify path removes about 11 % of the kernel launches in MTP serving, and the output does not change.
Asks
- Please rebase onto master
1fe05fa45before merge. The rebase has no conflicts, and it is the tree we tested. We could not push it to thenbitslabsfork (HTTP 403, although maintainer edits are on). - Optional: the first commit message still describes
GGML_CUDA_FUSE_GDN_DECODE_Tand_T1, which the second commit removes. Squash the two commits, or reword the first one, so that the history does not name switches that do not exist.
Correctness
PASS on ROCm. Server greedy runs with the MTP draft at --spec-draft-n-max 1, 3 and 7 gave the same text, the same top-5 probabilities for all 128 tokens and the same draft and accepted counts on master and on the PR (12 of 12 cells), also with HIP_LAUNCH_BLOCKING=1. With GGML_CUDA_DISABLE_FUSION=1, the PR gives the same output as master with the same switch. A kernel trace shows the fused kernel on the PR (6160 calls, 0 on master). f32 final logits, prompt tokens, .kld files short and long and 256-token greedy decode are byte-identical. The full ROCm test-backend-ops passes with HIP_LAUNCH_BLOCKING unset and =1. The -Werror build and the VGPR spill gate pass.
Performance
MTP draft, --spec-draft-n-max 3, 128 tokens, 2 rounds alternated, tok/s:
| prompt tokens | master | PR | gain |
|---|---|---|---|
| 344 | 32.47 / 32.57 | 33.28 / 33.32 | +2.4 % |
| 10811 | 33.94 / 33.97 | 34.68 / 34.59 | +2.0 % |
| 36385 | 38.75 / 38.73 | 39.53 / 39.59 | +2.1 % |
| 63259 | 48.65 / 48.53 | 49.59 / 49.67 | +2.1 % |
TTFT and acceptance are the same. llama-bench (PP2048 at depths 0 to 64000, tg128, pp1/2/4/8) is neutral.
Verification
Strix Halo (gfx1151). We rebased the PR onto master 1fe05fa45 (10 commits behind, no conflicts) and compared it against master.
Not tested
NVIDIA CUDA, the full Vulkan suite (no Vulkan code changes; the changed ops pass on Vulkan), and verify graphs with more than one sequence (these do not fuse, by design).
Thank you for the quick and complete follow-up.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
Linux 7.0.0 (Ubuntu). ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb691863. Mesa RADV 26.0.8 (Radeon 8060S). cmake 4.2.3, Ninja, gcc 15.2.0.
Compared
- Master tip: 1fe05fa (base side).
- PR head: a1c1716 (previous review: 90b3054).
- Merge base: cb82e57, 10 commits behind master.
- Head side: local rebase b44efceff (2 commits on 1fe05fa).
Rebase
No conflicts. The range-diff shows both commits unchanged (=):
3: 5bd79eb09 = 1: b70682078 cuda : fused Gated DeltaNet decode chain at 2-8 tokens with the speculative rollback store (gfx1151)
4: a1c17165a = 2: b44efceff cuda : drop the GDN decode env knobs and the ident-2 rollback cases (review)
Not pushed: the push to the head repository returned HTTP 403. A plain git rebase origin/master gives the same tree.
Changes since the last review
GGML_CUDA_FUSE_GDN_DECODE_Tand_T1are removed, with thesetenvcalls in the tests. The one-token rollback form returns 0 from the matcher.- The ident-2 cases and
max_tensors()are removed. The test-mode context is 128 tensors again, as on master. - Comments fixed, the token loop and the CPY branch re-indented,
ggml_is_view_opcheck removed,Assisted-by:trailers on both commits. git diff -wofgated_delta_net.cubetween the two heads changes comments only.
Build
HIP: cmake -G Ninja -S <tree> -B <tree>/build-hip -DCMAKE_BUILD_TYPE=Release -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R)
Vulkan: cmake -G Ninja -S <tree> -B <tree>/build-vk -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON -DGGML_HIP=OFF
-Werror (head): HIP line + -DCMAKE_HIP_FLAGS="-Werror -Wno-tautological-compare", target ggml-hip
Metrics (head): HIP line + -DGGML_EXL3=ON -DGGML_HIP_EXPORT_METRICS=On -DCMAKE_HIP_FLAGS="", target ggml-hip
Models
- Target (qwen4exp): Qwen3.8-Flash-Next Gyro-M TQ2_0, sha256 7aa36d15131d255179ab6c87fa9c9f81a0b541fc9e81e959d4c3e29eb20feb5f, run with
-lm none -lzm on-direct. - MTP draft: unsloth/Qwen3.8-Flash-Next-GGUF
MTP/mtp-Qwen3.8-Flash-Next-shared-Q4_K_M.gguf, sha256 f521868a9e143718bef513772f6e04d9642551e362cf2439636d2abdbd149dfc. - Corpora (tests/corpus): code dec1127a, numeric d9f08d94, prose c90398f2, structured c21947b3.
Commands
# ops, each side its own binary, HIP_LAUNCH_BLOCKING unset and =1
test-backend-ops test -b ROCm0 -o GATED_DELTA_NET
test-backend-ops test -b ROCm0 -o GATED_DELTA_NET,SSM_CONV,CONCAT,SET_ROWS,GDN_DECODE_ROLLBACK
test-backend-ops test -b ROCm0 -o <op> (one run per op)
test-backend-ops test -b Vulkan0 -o GATED_DELTA_NET,SSM_CONV,CONCAT,SET_ROWS,GDN_DECODE_ROLLBACK ; -o GATED_DELTA_NET
test-backend-ops test -b ROCm0 -j 2
ctest --test-dir <build> -L main -E 'test-opt|test-llama-archs' ; ctest -R 'spec-mtp-pcum|draft-vocab|test-qwen4exp-mtp-cache-only'
test-llama-archs -b ROCm0 -a 'qwen35|qwen35moe|qwen4exp'
gcn-cdna-vgpr-check.py <metrics build> --baseline scripts/hip/gfx1151-vgpr-baseline.json (master copy)
# model, -ngl 99 -fa on -ctk f16 -ctv f16 -lm none -lzm on-direct
llama-debug -f correctness-<t>.txt -c 16384 -b 16384 -ub 512 --save-logits ; cmp logits + tokens
llama-perplexity -f <4 corpora joined> -c 2048 -b 2048 -ub 2048 --kl-divergence-base <side>.kld ; cmp ; A/A with -ub 512 ; head --kl-divergence
llama-perplexity -f <4 corpora joined> -c 16384 -b 512 -ub 512 (same steps)
llama-completion -f correctness-prose.txt -n 256 --temp 0 --seed 1 -no-cnv --ignore-eos -c 16384 (base x2, head x2)
# server, -c 16384 -b 2048 -ub 2048 -np 1 -md <draft> -ngld 99 --spec-type draft-mtp --spec-draft-n-max 1|3|7
POST /completion {"n_predict":128,"temperature":0,"n_probs":5,"cache_prompt":false,"seed":1,"ignore_eos":true}, prompts = first 6000 bytes of each corpus
arms: master, PR, master and PR with GGML_CUDA_DISABLE_FUSION=1, master and PR with HIP_LAUNCH_BLOCKING=1 (n-max 3)
rocprofv3 --kernel-trace on the n-max 3 server, 4 requests, master and PR
# perf
llama-bench -p 2048 -d 0,12000,32000,64000 -n 0 -r 5 -b 2048 -ub 2048 --load-mode none (order master, PR, master, PR)
llama-bench -p 0 -n 128 -r 5 ; -p 1,2,4,8 -n 32 -b 2048 -ub 1024 -r 5 (same order)
bench-spec-prefill.sh logic (master copy, request body sent with --data-binary @file because the prompt is larger than one argv entry allows), -c 72000 -b 2048 -ub 2048, n-max 3, 128 tokens, round 1 master then PR, round 2 PR then master
Results
-o GATED_DELTA_NET: master 69/69, PR 69/69, HLB unset and =1 (aborted on the previous head).- Combined filter: master 547/547, PR 560/560, HLB unset and =1. One op per run: SSM_CONV 60, CONCAT 231, SET_ROWS 179, GATED_DELTA_NET 69 on both; GDN_DECODE_ROLLBACK 8 (master) / 21 (PR).
- Vulkan0 combined filter: master 822/822, PR 835/835.
-o GATED_DELTA_NET69/69 on both. - Full ROCm0 suite: master 56961/56961, PR 56974/56974, with HLB unset and =1.
- ctest -L main 35/35, spec ctest 3/3, test-llama-archs 3/3, on both.
-Werrorbuild: pass. Spill gate: PASS (7222 kernels, 156 units, 0 VGPR spills, the same 11 SGPR baseline entries). gdn_decode_fused_cuda<128,4>: 70 VGPR, 74 SGPR, scratch 0 (as in the last review).- llama-debug: logits and tokens byte-identical on all four corpora.
.kldshort and long: byte-identical. Head against base: Mean KLD 0, same top p 100 %. A/A floor (-ub 512, short): Mean KLD 0.002592, same top p 98.54 %. PPL short 2.2333 both, long 2.1522 both.- Greedy decode: 4/4 runs identical.
- Server parity: master vs PR identical in text, completion_probabilities and draft/accepted counts in all 12 cells (4 prompts x n-max 1/3/7), and in the 4 HLB=1 cells on both sides. Rejected drafts are present (for example prose n-max 7: 80 of 321 accepted). PR with GGML_CUDA_DISABLE_FUSION=1 equals master with the same switch in all 12 cells. (Against master with fusion on it differs, as expected: that switch also turns off the fusions that master has.)
- Kernel trace (n-max 3, 4 requests): PR 6160 gdn_decode_fused_cuda + 6160 gdn_decode_norm_cuda, gated_delta_net 6408 -> 248, ssm_conv 6624 -> 464, all kernels 670206 -> 596286. Master: 0 fused. The text under the profiler equals the run without it.
Correctness
| check | method | result |
|---|---|---|
| test-backend-ops changed ops | ROCm0 HLB unset/=1, Vulkan0 | pass, -o GATED_DELTA_NET fixed |
| full backend suite | ROCm0 -j 2, HLB unset/=1 | pass, no head-only failure |
| test-vk-exact | not run | does not apply: no Vulkan code change |
| f32 logits + prompt tokens | llama-debug, 4 corpora | byte-identical |
| KLD/PPL short | -c 2048, 4 corpora joined | .kld identical, PPL equal |
| KLD/PPL long | -c 16384, 4 corpora joined | .kld identical, PPL equal |
| greedy decode A/A | llama-completion 256 tokens | 4/4 identical |
| spec output at temp 0 | server, n-max 1/3/7, HLB, DISABLE_FUSION | identical to master |
| spec unit tests | ctest spec-mtp-pcum, draft-vocab, mtp-cache-only | pass |
| -Werror build | HIP | pass |
| VGPR spill gate | gcn-cdna-vgpr-check.py | PASS |
| spec throughput | bench-spec-prefill, 4 depths, 2 rounds | +2.0 to +2.4 % tg, TTFT and acceptance equal |
| llama-bench | PP2048 d0-64000, tg128, pp1-8 | neutral |
Performance
llama-bench avg_ts +- stddev, order master, PR, master, PR (master runs, then PR runs):
- pp2048 d0: master 1121.91 +- 41.49 / 1137.06 +- 42.00; PR 1131.44 +- 41.40 / 1127.62 +- 42.08 (0.00 %).
- d12000: master 1016.10 / 1019.14; PR 1021.32 / 1018.32 (+0.22 %).
- d32000: master 1002.61 / 1003.70; PR 1005.01 / 1003.73 (+0.12 %).
- d64000: master 992.83 +- 10.13 / 993.80 +- 9.40; PR 941.55 +- 111.64 / 993.00 +- 10.15. The low PR run has one slow first repetition (741.9; the other four 989.9-995.7). Without it the sides are equal. pp2048 does not reach the new match (it needs 2-8 tokens).
- tg128: master 28.77 / 28.78; PR 28.76 / 28.76 (-0.05 %, stddev 0.01-0.02).
- pp1 26.31 / 26.42 vs 26.34 / 26.26; pp2 44.06 / 44.02 vs 44.29 / 44.25; pp4 72.88 / 72.91 vs 72.83 / 73.04; pp8 87.17 / 87.33 vs 87.26 / 87.21; tg32 28.46 / 28.46 vs 28.42 / 28.44.
Spec decode, per run: tg of the 3 timed requests, TTFT median, acceptance:
master-d0-r1 N=344 ttft_med=735ms tg_avg=32.47 tok/s tg_all=33.30,32.02,32.07 accept=46%
PR-d0-r1 N=344 ttft_med=734ms tg_avg=33.28 tok/s tg_all=34.10,32.81,32.92 accept=46%
PR-d0-r2 N=344 ttft_med=720ms tg_avg=33.32 tok/s tg_all=34.18,32.85,32.95 accept=46%
master-d0-r2 N=344 ttft_med=727ms tg_avg=32.57 tok/s tg_all=33.38,32.17,32.16 accept=46%
master-d12k-r1 N=10811 ttft_med=13212ms tg_avg=33.94 tok/s tg_all=33.96,33.94,33.92 accept=57%
PR-d12k-r1 N=10811 ttft_med=13222ms tg_avg=34.68 tok/s tg_all=34.75,34.68,34.60 accept=57%
PR-d12k-r2 N=10811 ttft_med=13234ms tg_avg=34.59 tok/s tg_all=34.59,34.67,34.50 accept=57%
master-d12k-r2 N=10811 ttft_med=13238ms tg_avg=33.97 tok/s tg_all=33.98,34.00,33.94 accept=57%
master-d32k-r1 N=36385 ttft_med=44528ms tg_avg=38.75 tok/s tg_all=38.73,38.79,38.74 accept=70%
PR-d32k-r1 N=36385 ttft_med=44587ms tg_avg=39.53 tok/s tg_all=39.54,39.54,39.52 accept=70%
PR-d32k-r2 N=36385 ttft_med=44562ms tg_avg=39.59 tok/s tg_all=39.62,39.56,39.61 accept=70%
master-d32k-r2 N=36385 ttft_med=44563ms tg_avg=38.73 tok/s tg_all=38.75,38.70,38.74 accept=70%
master-d64k-r1 N=63259 ttft_med=77946ms tg_avg=48.65 tok/s tg_all=48.73,48.71,48.52 accept=100%
PR-d64k-r1 N=63259 ttft_med=78066ms tg_avg=49.59 tok/s tg_all=49.43,49.66,49.68 accept=100%
PR-d64k-r2 N=63259 ttft_med=78052ms tg_avg=49.67 tok/s tg_all=49.64,49.56,49.81 accept=100%
master-d64k-r2 N=63259 ttft_med=78062ms tg_avg=48.53 tok/s tg_all=48.42,48.61,48.56 accept=100%
For the deepest point, a first 250 KB prompt (73932 tokens) did not fit in -c 72000, so that depth ran again with a 218 KB prompt (63259 tokens). Acceptance is 100 % there because the prompt repeats the corpora.
Findings in full
- Both blocking asks of the last review are fixed (see "Changes since the last review"). The should-fix items are done.
- The first commit message still names the removed switches (Ask 2).
- Not needed for this PR, as noted last time: the per-slot CPY form with K > 1 is only built by the tests, and
softplus_log1pcould go with it in a later PR. - Landing order: #231 changes the same matcher in
gated_delta_net.cu/ggml-cuda.cu; whichever lands second rebases.
Claims
- The matcher takes the SET_ROWS rollback store at 2-8 tokens: reproduced (6160 fused calls, 0 on master).
- The fused path gives the same bits as the chain it replaces: reproduced (server text, probabilities and acceptance, n-max 1/3/7).
GGML_CUDA_DISABLE_FUSION=1restores the unfused chain: reproduced (equal to master with the same switch).-o GATED_DELTA_NET69/69 and the full ROCm0 suite passes: reproduced (56974/56974 on the rebased tree).- Greedy streams and acceptance unchanged: reproduced.
- Decode gain: +2.0 to +2.4 % with our quant (your numbers are for another quant).
- CUDA build: not tested (no NVIDIA hardware).
Not tested
NVIDIA CUDA (no hardware). The full Vulkan suite (no Vulkan code change; the changed ops pass on Vulkan0). The author's model quant and Q8_0 draft. Fusion with more than one sequence per verify graph (the matcher rejects it). ops-perf.sh.
…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> Assisted-by: Claude Fable 5.1
…review) Review of halo-box#297 (dzannotti): GGML_CUDA_DISABLE_FUSION already gives the unfused chain, so GGML_CUDA_FUSE_GDN_DECODE_T goes; the one-token rollback form stays on the existing path (GGML_CUDA_FUSE_GDN_DECODE_T1 goes with it, enabling it is a later PR with model numbers). The ident-2 test cases needed a larger test-mode context, which made `test-backend-ops test -o <op>` abort for every op listed after them; without T1 they repeat the ident-1 max_err 0 check, so they are removed and max_tensors() is reverted. Stale comments fixed, the token loop body and the CPY matcher branch re-indented, the redundant ggml_is_view_op() check dropped. Assisted-by: Claude Fable 5.1 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
a1c1716 to
a505fc4
Compare
|
Thanks for the approval. Rebased onto master |
The branch is on the fork master 25b1c17. The import tools regenerate hooks/ from it: common/sampling and speculative, the server, the CUDA mmb and fused Gated DeltaNet decode of #297, src/llama-context.cpp, the CI workflows and the tests. The AMX mmq flags of the fork for clang 22 come through HOOK(cpu-amx) in ggml/src/ggml-cpu/CMakeLists.txt, with or without the hooks build (hooks/ggml/cpu-amx.cmake). test-backend-sampler-fork is registered in ctest with the fork labels. PORT.txt lists the 46 new hunks. check-port against 25b1c17: 64385/64385 lines, 514/514 files. Same as the fork binary: gpt-oss-20b PPL 5.4741 (HIP +llama,+cuda_graph,+sched), EXL3 7.4162 / 7.4148 / 7.4151, GATED_DELTA_NET 69/69 with cuda_graph. check-ctest 91/91, ctest -L main 38/38, the sampler tests pass. Assisted-by: Claude Opus
The branch is on the fork master 25b1c17. The import tools regenerate hooks/ from it: common/sampling and speculative, the server, the CUDA mmb and fused Gated DeltaNet decode of #297, src/llama-context.cpp, the CI workflows and the tests. The AMX mmq flags of the fork for clang 22 come through HOOK(cpu-amx) in ggml/src/ggml-cpu/CMakeLists.txt, with or without the hooks build (hooks/ggml/cpu-amx.cmake). test-backend-sampler-fork is registered in ctest with the fork labels. PORT.txt lists the 46 new hunks. check-port against 25b1c17: 64385/64385 lines, 514/514 files. Same as the fork binary: gpt-oss-20b PPL 5.4741 (HIP +llama,+cuda_graph,+sched), EXL3 7.4162 / 7.4148 / 7.4151, GATED_DELTA_NET 69/69 with cuda_graph. check-ctest 91/91, ctest -L main 38/38, the sampler tests pass. Assisted-by: Claude Opus
The branch is on the fork master 25b1c17. The import tools regenerate hooks/ from it: common/sampling and speculative, the server, the CUDA mmb and fused Gated DeltaNet decode of #297, src/llama-context.cpp, the CI workflows and the tests. The AMX mmq flags of the fork for clang 22 come through HOOK(cpu-amx) in ggml/src/ggml-cpu/CMakeLists.txt, with or without the hooks build (hooks/ggml/cpu-amx.cmake). test-backend-sampler-fork is registered in ctest with the fork labels. PORT.txt lists the 46 new hunks. check-port against 25b1c17: 64385/64385 lines, 514/514 files. Same as the fork binary: gpt-oss-20b PPL 5.4741 (HIP +llama,+cuda_graph,+sched), EXL3 7.4162 / 7.4148 / 7.4151, GATED_DELTA_NET 69/69 with cuda_graph. check-ctest 91/91, ctest -L main 38/38, the sampler tests pass. Assisted-by: Claude Opus
Overview
Supersedes #294, which was the same commit. My mistake there: I opened it against the
sync/upstream-2026-11-15branch so thediff would not include the whole upstream sync, instead of waiting for #293 to merge. When #293 landed and that branch was deleted,
GitHub closed the PR unreviewed. This is the commit rebased onto master, nothing else changed.
Review round 1 (dzannotti): the second commit removes the two env knobs and the ident-2 test cases, fixes the stale
comments and the indentation, and drops the redundant view check; the first commit carries the
Assisted-by:trailernow. Both commits are rebased onto master cb82e57 (the Behavior Check failure on the old base was the
grammar-parser test, fixed on master since). Nothing in the kernel or the matcher logic changed, except that the
one-token rollback form is now always left on the existing path.
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-serverdoes not emit that graph when itserves 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_ROWSover the K slots). That form never matched, at any row count, so inserving 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
sholds the window that starts at columnn_tokens - s). The fused kernel spells softplus aslog1pf(expf(x))like the unfused op, so the fused path producesthe same bits as the chain it replaces.
GGML_CUDA_DISABLE_FUSION=1restores the unfused chain (the review asked for the PR's own env knobs to go).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 1-8 tokens: the fused chain against the unfused one on the samebackend, max_err 0 for the SET_ROWS form).
Duplicate check
same function), so one of the two rebases over the other.
gated_delta_net.cufor prefill snapshots; unrelated in function, textual overlap only.Measurements
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-benchemits thein-place form, so the new match is not taken here; the numbers show the change is neutral where it does not fire):
llama-server(-c 16384 -b 1024 -ub 1024 -fa on), three 8k-token prompts (code, prose, agentic), 256 generatedtokens, 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):
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 tokenson 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 ROCm0on the measured head ad70207: 45212/45212 passed (the full suite, including the newrollback-chain cases and the existing GDN cases). On the rebased head 90b3054, on master: 56936/56936 passed (master's suite is
larger), built with master's
-Werror=overloaded-virtual -Werror=unused-parametertest flags. On the review-fix head(a1c1716, on master cb82e57): 56937/56937 passed;
test-backend-ops test -b ROCm0 -o GATED_DELTA_NET,GDN_DECODE_ROLLBACK90/90 and
-o GATED_DELTA_NETalone 69/69 (the filtered run that aborted before the fix).Written by an agent (Claude Fable 5.1) under my direction; built, measured and tested by me on this box.
🤖 Generated with Claude Code