Repository navigation
spec, qwen4exp, delta-net : faster prompt processing with an MTP draft loaded - #255
Conversation
|
This PR with 4 slots ( The PR lists more than one sequence and GPUs other than gfx1151 as not verified, so we ran it at our production
Method:
Without the draft ( One observation, not chased down. Earlier the same day, on the same machine and shape, we had measured two local
At 16384 tokens:
So at Written by Claude Code (an AI agent), run on rcfa's Strix Point machine; rcfa owns it. |
dzannotti
left a comment
There was a problem hiding this comment.
Verdict
Changes requested. Target correctness holds on both backends, but with the PR merged into current master the delta-net part gives about +5% prompt speed on ROCm and nothing on Vulkan. On Vulkan the conv split also makes the backend reject its direct conv fold.
Direction
Accept after work. We want the prompt-speed win with an MTP draft. The eh_proj GEMM is small and self-contained. The scan and conv split should live in qwen4exp.cpp, not in the shared delta-net base, and it needs numbers on current master for both backends.
Asks
- Blocking.
src/models/qwen4exp.cpp:2844(build_conv_state_split). The first part's conv input is a prefix view ofqkv_mixed, so the Vulkan direct conv matcher rejects it ("x layout": 576 rejections in one 2048-tokenllama-benchrun on head, none on master). The HIP gdn_conv matcher has the samenelements(x) == C*T*Scheck. Make part 0 a whole tensor that the matchers accept, or drop commit 4, and show a Vulkan prefill gain on current master. Please also say which commit gives the +4.6% in the description: without a draft, the two delta-net commits do not speed up Vulkan prefill on either base (table below). - Blocking.
src/models/delta-net-base.cpp:526-632,src/models/models.h:93-114. The split adds 73 lines, astd::pairout-param and astd::functioncallback to an upstream method, for one model.llama_model_qwen4exp::graphalready derives fromllm_build_delta_net_base, so build the split inqwen4exp.cppas straight-line code and leave the upstream file and struct as they are. This also removes the unreachable!part1_qkvbranches and the SCALE(RMS_NORM) re-application inslice_tokens(only qwen4exp calls the split, and it always passespart1_qkv). - Should fix.
common/speculative.cpp:1838andqwen4exp.cpp:2094. Width (n_all <= n_max + 1,n_seq_tokens > K) is not a prompt test. With--spec-type draft-mtp,ngram-modan ngram verify batch is wider thann_max + 1, and MTP'saccept(is_other = true)then takes the last row instead of rown_accepted. With--spec-n-rs-seqbelow the draftn_max, verify batches also take the graph split. Use the per-row output flags (a prompt batch outputs only its last row). Onedraft-mtp,ngram-modrun on Qwen3.8-27B per backend gave the same acceptance on base and head, so this is from reading the code. - Should fix.
qwen4exp.cpp:1079-1118.build_norm_gated_partscopies the fast-path condition and thestatic padofbuild_norm_gated. Use one shared helper so that the two paths cannot drift. - Should fix. No test reaches the split.
case_rollbackintests/llama-context/cases-rs.cppdecodesn_rs_seq + 1tokens, which is never wider than K. Decoden_rs_seq + 1 + 16tokens in one ubatch there and compare the replay against an unsplit run.
Nits: the (size_t) 0 - c1->view_offs view is legal but hard to read; the split path drops the cb() names of the other paths; the comments with ms and MB figures belong in the commit messages.
Correctness
PASS for target output. AR (no slots) final logits and token ids are byte-identical base vs head on qwen4exp and qwen35, both backends. With rollback slots forced (n_rs_seq 3), qwen4exp KLD head vs master is 0.0019 (Vulkan) and 0.0024 (ROCm), below the A/A floor of 0.0021 and 0.0026, and head is as close to the AR run as master (0.0017 vs 0.0020 Vulkan, 0.0025 vs 0.0024 ROCm). qwen35 (Qwen3.8-27B with its MTP head) gives byte-identical logits with slots and identical greedy streams and acceptance with --spec-type draft-mtp, both backends. On a small random qwen4exp, a prompt reused after dropping 1-3 tokens (restored from the rollback slots) gives the same tokens and top-5 log-probs as a fresh run, base and head. ROCm results are the same with HIP_LAUNCH_BLOCKING=1. Not run: a qwen4exp target with its MTP draft (see Not tested), so the eh_proj change and the draft acceptance are not verified.
Performance
Qwen3.8-Flash-Next (qwen4exp) TQ2_0, no draft loaded, rollback slots forced to n_rs_seq 3 (the target side of --spec-draft-n-max 3), llama-bench -ub 2048, 2 rounds x 3 reps, base and head alternated:
| backend | prompt | master t/s | head t/s | change |
|---|---|---|---|---|
| Vulkan | 512 | 825.9 +- 6 | 826.3 +- 7 | +0.0% |
| Vulkan | 2048 | 1089.1 +- 25 | 1084.3 +- 26 | -0.4% |
| Vulkan | 8192 | 1037.2 +- 2 | 1033.8 +- 3 | -0.3% |
| ROCm | 512 | 807.7 +- 6 | 820.7 +- 3 | +1.6% |
| ROCm | 2048 | 986.0 +- 13 | 1037.1 +- 9 | +5.2% |
| ROCm | 8192 | 944.4 +- 1 | 992.2 +- 1 | +5.1% |
AR without slots is unchanged (2048: Vulkan 1158 vs 1150, ROCm 1123 vs 1126, within stddev). On Vulkan, slots still cost about 6% at 2048 on head, so the split does not recover what it targets there. On the PR's own base (ea5285d vs d208045), Vulkan with slots goes from 1048 to 1029 t/s at 2048 (-1.9%) and from 979 to 965 t/s at 8192 (-1.4%, stddev about 1.5). There, slots cost master almost nothing (AR 1052 t/s), so the +4.6% in the description probably comes from the draft side (eh_proj and the carry row), which we could not test.
Verification
Strix Halo (gfx1151), Vulkan (RADV) and ROCm. We compared the PR merged into master 50c2c8c (the PR was 78 commits behind) against master.
Not tested
The qwen4exp target with the MTP draft: target, draft, KV and compute buffers do not fit our memory budget, so the eh_proj GEMM, the carry-row change on qwen4exp, draft acceptance and end-to-end decode t/s are untested. Also not tested: -np 4, contexts above 8192 on qwen4exp, the server pytest suite (not installed).
Thanks for the detailed write-up and the split commits.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
- Ubuntu 26.04.1, kernel 7.0.0-43-generic, Strix Halo (gfx1151, Radeon 8060S), 128 GB unified memory.
- ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb69.
- Mesa RADV 26.0.8.
- cmake 4.2.3, gcc 15.2.0, Ninja.
Compared
- master tip: 50c2c8c (
50c2c8cb522e6c5e0532939db52785a2977a9440). Master later moved to 093c552 (CI workflow files only). - PR head: d208045 (
d208045642003bbe35088f52eb9aae7e6fa77865). - merged (PR merged into master, local only, clean merge): c9b7b3a41.
- merge base: ea5285d. The PR was 78 commits behind master.
- Extra Vulkan check on the PR's own base: ea5285d vs d208045.
Build
Vulkan: cmake -S <tree> -B <tree>/build-vk -DGGML_VULKAN=ON -DGGML_HIP=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja
ROCm: cmake -S <tree> -B <tree>/build-hip -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 \
-DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R) -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake --build <tree>/build-<be> -j
No HIP source changed, so no -Werror HIP build and no VGPR spill gate.
Models
| model | arch | sha256 |
|---|---|---|
| Qwen3.8-Flash-Next TQ2_0 (176.9 B params, 85.6 GiB), agentionai/Qwen3.8-Flash-Next-Gyro-GGUF | qwen4exp | 7aa36d15131d255179ab6c87fa9c9f81a0b541fc9e81e959d4c3e29eb20feb5f |
| Qwen3.8-27B UD-Q4_K_XL (with its MTP head) | qwen35 | 3f227079003add2511437e5b1e94812e363385225bf6a9b47b0054a72bc8b01e |
random tiny qwen4exp MoE from test-llama-archs -a qwen4exp -o <dir> (default seed) |
qwen4exp | 433fb2d994f1005c... |
Corpora (tests/corpus, sha256 prefixes): code dec1127ae75ffa56, numeric d9f08d9470e53ef6, prose c90398f2e2885f20, structured c21947b360bea62d.
Rollback slots without a draft: a small LD_PRELOAD shim wraps llama_init_from_model and sets params.n_rs_seq = 3. That is the target context that --spec-type draft-mtp --spec-draft-n-max 3 creates; the log prints n_rs_seq = 3. We used it for llama-debug, llama-perplexity, llama-bench and llama-server (tiny model). We did not load the qwen4exp MTP draft. With the 85.6 GiB target, draft, KV and compute buffers, it does not fit our memory budget.
Commands
# unit, both sides, both backends
ctest --test-dir <build> --output-on-failure -L main -E 'test-opt|test-llama-archs'
ctest --test-dir <build> -R 'spec-mtp-pcum|draft-vocab'
test-llama-archs -b <dev> -a qwen4exp ; test-llama-archs -b <dev> -a qwen35
test-backend-ops test -b <dev> -o GATED_DELTA_NET ; -o SSM_CONV
test-vk-exact # Vulkan only
test-llama-context -m <tiny qwen4exp> ; -m <tiny qwen35> ; -m <Qwen3.8-27B>
# logits + token ids (llama-debug), AR and with slots (shim)
llama-debug -m <model> -f correctness-<t>.txt -c 16384 -b 16384 -ub <512|2048> -ngl <99|0> -fa on -ctk f16 -ctv f16 \
--save-logits --logits-output-dir <dir>
# Qwen3.8-27B: -ub 512, AR on code, slots on code + prose. tiny qwen4exp: -ub 512, all 4 corpora, AR + slots, -ngl 99 and 0.
# KLD/PPL, qwen4exp TQ2_0, code corpus
llama-perplexity -m <model> -f correctness-code.txt -c 2048 -b 512 -ub 512 -ngl 99 -fa on -ctk f16 -ctv f16 --kl-divergence-base <side-mode>.kld
llama-perplexity -m <model> -c 2048 -b 512 -ub 512 ... --kl-divergence-base <ref>.kld --kl-divergence
# floor: base AR scored with -ub 256 against base AR -ub 512
# greedy decode with the draft, Qwen3.8-27B, fresh server per side, base/head/head/base
llama-server -m <27B> --spec-type draft-mtp --spec-draft-n-max 3 -ngl 99 -fa on -ctk f16 -ctv f16 -np 1 -c 16384 -b 2048 -ub 512
# /completion, token-id prompts = first 2000 tokens of code / prose / structured, n_predict 256, temperature 0, top_k 1,
# ignore_eos, cache_prompt false, each prompt twice per server
# same with --spec-type draft-mtp,ngram-mod on a repetitive code prompt (1899 tokens), 2 requests
# rollback restore, tiny qwen4exp, server with n_rs_seq 3 (shim) and without
llama-server -m <tiny> -ngl 99 -fa on -ctk f16 -ctv f16 -np 1 -c 256 -b 256 -ub 64
# P = first 200 tokens of prose; send P (cache_prompt true), then Q = P with token n-d changed (d = 1, 2, 3, 5),
# n_predict 8, n_probs 5, cache_prompt true (reuse); then Q again with cache_prompt false (fresh); compare
# prefill, qwen4exp TQ2_0, no draft, slots (shim), base/head alternated, 2 rounds
llama-bench -m <model> -p 512,2048,8192 -n 0 -b 2048 -ub 2048 -r 3 -ngl 99 -fa on -ctk f16 -ctv f16 -o jsonl
llama-bench -m <model> -p 2048 -n 0 ... -r 3 # AR, no shim, once per side
GGML_VK_FUSION_DEBUG=1 llama-bench -m <model> -p 2048 -n 0 -r 1 ... # Vulkan fold check, slots on
ROCm: correctness ran twice, with HIP_LAUNCH_BLOCKING unset and =1 (tiny logits + restore, 27B logits, qwen4exp KLD). Benchmarks with it unset. A memory guard stopped any run above 89 GiB of GPU memory; peak was 37 GiB GTT plus the mapped model, and system MemAvailable stayed above 32 GiB.
Results
Unit tests (both backends, base and head the same): ctest -L main 63/65 on both sides, with the same 2 failures on base and head (test-tokenizers-ggml-vocabs, and test-llama-context, which aborts when ctest runs it without a model). Spec ctest 2/2. test-llama-archs qwen4exp and qwen35 OK on both sides. GATED_DELTA_NET and SSM_CONV OK on both sides. test-vk-exact: the same 11 failing checks on base and head. test-llama-context: tiny qwen4exp and qwen35 pass on both sides; Qwen3.8-27B fails the same rollback case (replay nmse 1.1e-5) on base and head.
llama-debug (final logits + token ids, cmp):
| model | mode | corpora | Vulkan base vs head | ROCm base vs head | ROCm HLB=1 |
|---|---|---|---|---|---|
| Qwen3.8-27B | AR | code | identical | identical | identical |
| Qwen3.8-27B | slots | code, prose | identical | identical | identical (code) |
| tiny qwen4exp | AR | all 4 | identical | identical | identical |
| tiny qwen4exp | slots | all 4 | max abs diff up to 3e-8 (logits about 0.1), same argmax | same | same |
| qwen4exp TQ2_0 | AR (.kld) | code | identical | identical | identical |
On the tiny model, LLAMA_FUSED_GDN_CH=0 and LLAMA_GDN_NORM_PAD=0 with slots run without error on head; the logits are within 1.1e-8 of the default path.
KLD, qwen4exp TQ2_0, code corpus, -c 2048 -b 512 -ub 512:
| comparison | Vulkan Mean KLD | Vulkan same top p | ROCm Mean KLD | ROCm same top p |
|---|---|---|---|---|
| head slots vs base slots | 0.001913 | 99.238 % | 0.002395 | 98.749 % |
| head slots vs base AR | 0.001722 | 99.120 % | 0.002460 | 98.866 % |
| base slots vs base AR | 0.001961 | 99.101 % | 0.002433 | 98.866 % |
| A/A floor (base AR -ub 256 vs -ub 512) | 0.002142 | 98.944 % | 0.002592 | 98.807 % |
PPL (code, 2048): Vulkan AR 1.8113 on both sides, base slots 1.8122, head slots 1.8108; ROCm AR 1.8131 on both sides, base slots 1.8135, head slots 1.8100 (all +- 0.042). ROCm with HIP_LAUNCH_BLOCKING=1 gave the same KLD values.
Greedy decode with --spec-type draft-mtp --spec-draft-n-max 3, Qwen3.8-27B (sha256 of the generated token ids, accepted / drafted, t/s mean of 8 requests per side):
| backend | prompt | base | head |
|---|---|---|---|
| Vulkan | code | 723c75598b49ed02, 185 / 207, 32.1 |
same stream, 185 / 207, 32.1 |
| Vulkan | prose | 102702665186b035, 168 / 261, 25.9 |
same stream, 168 / 261, 25.9 |
| Vulkan | structured | f054b3b44df5e774, 175 / 235, 28.2 |
same stream, 175 / 235, 28.2 |
| ROCm | code | 723c75598b49ed02, 185 / 207, 28.1 |
same stream, 185 / 207, 28.1 |
| ROCm | prose | 29442c48b347f293, 170 / 254, 23.2 |
same stream, 170 / 254, 23.2 |
| ROCm | structured | b8b370ba9d646069, 177 / 234, 25.2 |
same stream, 177 / 234, 25.2 |
Every stream was the same in both rounds and both requests per server.
--spec-type draft-mtp,ngram-mod, Qwen3.8-27B, repetitive code prompt: both requests give the same stream on base and head, acceptance 194 / 432 and 243 / 390 (mean draft length 31.4 on the second request), on both backends.
Rollback restore, tiny qwen4exp, d = 1, 2, 3 (restored from the slots, 4 prompt tokens processed) and d = 5 (68 tokens reprocessed): reuse and fresh runs give the same 8 tokens and the same top-5 log-probs on base and head, with and without slots, Vulkan and ROCm (both HIP_LAUNCH_BLOCKING settings).
Vulkan fold check (GGML_VK_FUSION_DEBUG=1, one 2048-token run with slots): master logs 8 direct ssm conv not matched: state layout. Head logs the same 8 plus 576 x layout and 504 concat srcs are not (state, transpose(x)).
Performance
Prefill t/s, qwen4exp TQ2_0, no draft, slots n_rs_seq 3, -b 2048 -ub 2048, llama-bench -r 3 (avg +- stddev per round):
| backend | prompt | base r1 | base r2 | head r1 | head r2 | change |
|---|---|---|---|---|---|---|
| Vulkan | 512 | 828.1 +- 6.9 | 823.6 +- 3.0 | 821.0 +- 6.0 | 831.5 +- 1.6 | +0.0% |
| Vulkan | 2048 | 1090.0 +- 25.7 | 1088.2 +- 24.9 | 1083.8 +- 27.7 | 1084.8 +- 25.1 | -0.4% |
| Vulkan | 8192 | 1038.9 +- 1.5 | 1035.4 +- 1.2 | 1035.5 +- 2.1 | 1032.0 +- 3.0 | -0.3% |
| ROCm | 512 | 804.8 +- 1.6 | 810.5 +- 7.8 | 820.8 +- 2.6 | 820.5 +- 3.9 | +1.6% |
| ROCm | 2048 | 985.9 +- 12.0 | 986.1 +- 13.2 | 1038.4 +- 10.1 | 1035.7 +- 7.1 | +5.2% |
| ROCm | 8192 | 945.0 +- 0.7 | 943.8 +- 0.2 | 992.9 +- 0.4 | 991.5 +- 0.4 | +5.1% |
AR (no slots), 2048: Vulkan 1158.4 +- 35.6 (base) vs 1150.1 +- 43.0 (head); ROCm 1123.0 +- 23.0 vs 1125.7 +- 22.7.
PR on its own base, Vulkan, slots: 2048 1051.4 +- 30.1 / 1045.0 +- 28.5 (merge base) vs 1029.7 +- 25.8 / 1027.8 +- 24.4 (PR head), -1.9%; 8192 982.0 +- 1.2 / 975.5 +- 1.1 vs 964.9 +- 1.7 / 964.3 +- 1.3, -1.4%. AR 2048: 1052.1 +- 27.0 vs 1052.5 +- 26.4.
Findings in full
- Blocking: the conv split makes the first part's conv input a prefix view of
qkv_mixed. The Vulkan matcherggml_vk_ssm_conv_direct_checkresolvesx = transpose->view_srcand requiresggml_nelements(x) == C*T*S; for part 0,xis the wholeqkv_mixedwhileT = t, so it fails with "x layout". The tail concat fails earlier (view_offs != 0). The HIP matcher inconv-tail.cuhhas the same element-count check. The fold check above confirms it on Vulkan. The commit 4 message says part 0 is "the same graph as an unsplit ubatch"; at the matcher level it is not. - Blocking:
delta-net-base.cppis upstream code (3 lines of difference from the last sync before this PR). The PR changes the signature ofbuild_recurrent_attnin the upstreamllm_build_delta_net_base, addsslice_tokens, apartsout-param, astd::functioncallback and anullptrreturn. Onlyqwen4exp.cpppassesparts; the six other callers (qwen35, qwen35moe, qwen3next, kimi-k3, glm5-next, bailingmoe3) build the same graph as before. Upstream changes this function often, so each change becomes a manual conflict.qwen4exp.cppis also upstream code; the PR moves its conv / q / k / v block into a lambda, which moves upstream lines too. - Should fix:
i_beg = n_all <= n_max + 1 ? 0 : n_all - 1classifies by width.common_speculative_acceptalso calls the MTPaccept(..., is_other = true)after another drafter's verify, and MTP readsverify_h[min(n_accepted, n_rows - 1)]. A verify batch fromngram-mod(itsn_maxdefaults to 64) is wider than MTP'sn_max + 1, so only the last row stays and MTP pairs the wrong hidden row. The graph split uses the same kind of width test (n_seq_tokens > n_rs_seq + 1), so with--spec-n-rs-seqbelow the draftn_maxevery verify batch takes the split and pays one more GDN dispatch, conv,contand two-part norm per layer. - Should fix:
build_norm_gated_partsrepeats the fast-path condition ofbuild_norm_gatedand a secondstatic const pad. - Should fix: no test reaches the split (see Asks).
- Nits:
(size_t) 0 - c1->view_offs(legal: ggml folds the view tobufat offset 0); missingcb()names on the split path; long comments with ms / MB figures. On Vulkan the K=1 chunked scan starts at 64 tokens and on ROCm at 256, so a split with a shorter first part only adds dispatches. - Info: going by the batch-split code, the split should also engage at
-np 4when one prompt is in flight (n_seqs == 1). Not measured.
Claims
| claim | result |
|---|---|
| Carry row only after a prompt batch | Not tested on qwen4exp. Code-reviewed: the dropped rows are never read in an MTP-only setup; see finding 3 for mixed drafters. Qwen3.8-27B streams and acceptance unchanged. |
| eh_proj as one GEMM | Not tested (no qwen4exp draft run). Code-reviewed: the reshape is legal and the target graph is unchanged. |
| Rollback-slot scan split speeds up prompt processing | ROCm: reproduced, +5.2% at 2048 and +5.1% at 8192 with slots (no draft). Vulkan: not reproduced, -0.4% / -0.3% merged into master, -1.9% / -1.4% on the PR's own base. |
| Conv split: part 0 is the same graph as an unsplit ubatch, which the backends fold | Not reproduced: the Vulkan direct conv fold is rejected on head. |
| Slots get the same K states | Consistent with our results: restore after 1-3 dropped tokens equals a fresh run on the tiny model; KLD with slots within the A/A floor on qwen4exp. |
| AR serving unchanged | Reproduced: AR logits byte-identical and AR prefill unchanged, both backends. |
| Other delta-net models unchanged | Reproduced for qwen35: byte-identical logits with slots and identical draft streams. |
| +4.0 to +4.6% client prefill with an MTP draft | Not tested (no qwen4exp draft run). |
Not tested
- Any run with the qwen4exp MTP draft. With the 85.6 GiB target, draft, KV and compute buffers, it does not fit our memory budget. So the eh_proj change, MTP acceptance on qwen4exp, end-to-end decode t/s and TTFT are untested.
- qwen4exp contexts above 8192 tokens (memory budget),
-np 4, small-ubtiming, the long KLD case. - The server pytest suite (not installed).
- GPUs other than gfx1151.
|
I ran into the same problem on a Strix Halo last week, before I had seen this PR: load the MTP draft and prompt Setup first. One fresh
So with the draft loaded the PR is worth +16 % to +23 % here at 8k and above. The 2048 row is dominated by the first Decode, Now the other approach. The mechanism, for completeness: with a draft loaded the recurrent cache keeps Why I think it is worth a look given the review: because the long ubatch builds the unmodified graph, there is no Not verified: Vulkan at all; If the batch-side fix is useful I can open it as its own PR with the test, or as commits on this branch, whichever AI usage: the branch, the benchmark scripts and this comment were produced by an AI agent (Claude Fable 5.1) under my |
d208045 to
b329e93
Compare
|
Thanks for the review, and to @neavra for the ROCm numbers with the draft loaded. @neavra, on your question: we keep the in-graph split here. Its first part builds the same conv and plain-scan graph as serving without a draft, and with the Vulkan fold fixed (below) it now gains on both backends. On our rebased tip, your batch-side tail cut showed no prefill change on Vulkan: 1212.5 / 1239.5 / 1245.3 t/s at 2k / 8k / 32k against 1218.1 / 1255.2 / 1243.4 for the same branch without it. We have not checked whether it engaged there, so please treat that number as unexplained. We would gladly test your branch against this one if you open it. I rebased onto current master (c495f90) and addressed all five asks. With the Vulkan direct conv fold working again, the split now speeds up Vulkan prefill too. What changedThe branch is now 5 commits:
Vulkan, draft loadedQwen3.8-Flash-Next UD-Q4_K_XL + Method:
Vulkan direct conv fold
The remaining ROCm, draft loadedSame protocol on ROCm, this PR against commits 1-2 alone (narrow), so the line isolates the split. Master was not run on ROCm in this round.
The HIP gdn_conv matcher still declines the first part's prefix view (the same element-count check). A matching HIP change could add more, but that is left for a follow-up. More than one sequence (
|
| master | this PR | change | |
|---|---|---|---|
-np 2, aggregate prompt t/s |
1112.4 [1063-1144] | 1125.5 [1083-1150] | +1.2% |
-np 2, aggregate gen t/s |
37.3 [37.3-37.4] | 38.8 [36.9-40.8] | +4.0% (stream-dependent) |
-np 4, aggregate prompt t/s |
955.6 [929-1002] | 1083.4 [1063-1106] | +13.4% |
-np 4, aggregate gen t/s |
46.1 [45.7-46.5] | 47.6 [46.8-48.4] | +3.3% (stream-dependent) |
- No crash, no device or rollback error in any server log. Every request returned its full token count.
- Greedy streams with a draft at
-np > 1are not run-to-run stable on master either: the same mixed request gave different streams on master's two servers. So a stream comparison against-np 1or against master is not meaningful there. The 2600-token prompt of the stagger phase gave the same stream as its-np 1run on every server, on both arms. - Which path runs: a local debug build (one log line per delta-net layer per graph, not part of this PR) shows the split only on one-sequence ubatches. Every ubatch with 2, 3 or 4 sequences took the unsplit path, at
-np 2and-np 4and in the new two-sequence test. At-np 4, prompts that arrive together and are batched as several sequences keep the K-snapshot scan. The gain there comes from the one-sequence tails and from prompts processed alone. - New test case
rollback_wide_prompt_2seq: two sequences in one prompt ubatch (unsplit path), rolled back and replayed against the all-outputs run. It passes on the 11 recurrent tiny archs at-ngl 99and-ngl 0, as does the one-sequence case.
Wide verify batches
--spec-type draft-mtp,ngram-mod --spec-n-rs-seq 1, so every MTP verify batch (4 rows) is wider than K = 2. Same 1500-token repetitive prompt, 256 tokens, 2 reps, -np 1, GGML_VK_FUSION_DEBUG=1. As a positive control, the previous revision of this PR (width test) splits verify batches. Lines below are part-1 concat lines and x layout rejects in the generation phase of each rep:
| master | previous revision | this PR | |
|---|---|---|---|
| rep 0 | 443 / 0 | 6239 / 5832 | 659 / 0 |
| rep 1 | 325 / 0 | 3376 / 3204 | 424 / 0 |
| stream, rep 0 | 6f02684d 168/261 |
6f02684d 168/261 |
6f02684d 168/261 |
This PR's extra lines over master are about one prompt's split, against thousands for the width test, so verify batches keep the unsplit path. Rep 1 streams differ from master on both PR revisions, after a prompt that ran through the split.
Correctness (Vulkan, this PR)
test-backend-ops -o CONCAT_SSM_CONV_SILU: 15/15, with nox layoutreject under the fusion debug log. A 40-launch hazard run of the same filter: 0 failures.test-backend-ops -o 'SSM_CONV|CONCAT|GATED_DELTA_NET|GDN_CONV_PREFILL|SILU': 491/491.test-llama-contexton the random tiny qwen4exp MoE fromtest-llama-archs -a qwen4exp -o: 16/16, includingrollback_wide_prompt. The narrow branch passes the same 15 old cases. Under the fusion debug log, the new case shows part 1's concat, so the split engaged.- Full
test-backend-ops -b Vulkan0on the final binary: 44197/44197. test-llama-context --test 'rollback|rollback_wide_prompt'over every tiny arch fromtest-llama-archs -o, at-ngl 99and-ngl 0: 11 recurrent archs pass both, the other 119 skip, 0 fail. There is no negative control: no run deliberately broke a slot to show the test failing.ctest -R 'spec-mtp-pcum|draft-vocab|qwen4exp-mtp': 3/3.test-llama-archs -a qwen4exp -b Vulkan0: OK. Without-b, the Meta device row asserts atggml-backend.cpp:844on master too.- Carry row with
--spec-type draft-mtp,ngram-modanddraft-mtp: 3 prompts x 2 reps x 256 tokens. Every request gives the same stream and accepted / drafted counts as eh_proj alone. The wide verify case is covered in the section above.
Overlap: #250 edits the next line of ggml_vk_ssm_conv_direct_check (the token gate). The two merge without conflicts, but I have not built or tested the combination. This PR does not change how the recurrent state rows are laid out, so #247 is unaffected.
Not tested:
- other delta-net models with a draft (they keep the old path)
- GPUs other than gfx1151
- drivers other than RADV 26.2.4
Device: Ryzen AI Max+ 395 / Radeon 8060S (gfx1151), GMKtec EVO-X2, 128 GB, BIOS power mode balanced, UMA 2 GB. Kernel 6.17.0-35-generic, amdgpu.gttsize=118784 ttm.pages_limit=30408704 ttm.page_pool_size=1048576 amd_iommu=off. Mesa 26.2.4 RADV (release tag, unmodified), shaderc glslc. Build: -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON -DGGML_NATIVE=OFF.
AI usage: ASSISTED. Written with Claude, tested by me.
The rebased branch addresses every blocking ask of this review. A new review on b329e93 replaces it.
dzannotti
left a comment
There was a problem hiding this comment.
This review replaces our earlier one on d208045.
Verdict
Changes requested, for one new item. The rebased branch fixes every earlier ask, and with the MTP draft loaded we measured +8.5% to +10.3% prompt speed on Vulkan and +4.8% to +7.7% on ROCm. Output without a draft is unchanged on both backends. One test gate still fails on ROCm, because the context reserve never builds the split graph.
Direction
Accept after work. The split now lives in qwen4exp.cpp, the Vulkan fold works again, and both backends gain. After the reserve fix this is ready for a maintainer decision.
Asks
- Blocking.
src/llama-context.cpp:2971-2995withsrc/models/qwen4exp.cpp:2189-2192. The reserve sets its outputs from row 0 of each sequence, so the split condition (no output before the last K rows) is never true at reserve time. The first prompt ubatch that takes the split then needs a larger compute buffer, and the scheduler grows it at run time. On ROCm,test-llama-contexton the tiny qwen4exp withGGML_SCHED_DEBUG_REALLOC=1(the env that ctest sets for this test) aborts inreplaywith "unexpected graph reallocation" 3 of 3 times, and master passes 3 of 3. Without the env it prints 13 "compute buffer size ... does not match expectation" warnings, against 0 on master. Reserve the split shape as well whenn_rs_seq > 0, for example by putting the reserve's output on the last row of a one-sequence ubatch, and runctest -L mainon ROCm. - Should fix.
tests/llama-context/cases-rs.cpp:24-131.rollback_wide_promptruns a 25-token ubatch, sofused_gdn_norm_f16is off (it needs 32 tokens), the padded branch ofbuild_norm_gated_partsnever runs, and part 0 (16 tokens) never reaches the chunked GDN or the GDN conv fold with a prefix x. Slot 0 is also never checked (rollbacks are 1, 3 and n_rs_seq). Use 64 or more extra tokens, add a step with no rollback, and add oneGDN_CONV_PREFILLcase with a prefix x. - Should fix.
src/models/qwen4exp.cpp:3035-3052and2290-2311.build_conv_tail_atadds a third copy of the per-slot conv copy loop, and part 1's scan and slot write repeat the keep branch ofbuild_recurrent_attnline for line. One call tobuild_recurrent_attn(..., part0.second, il)and one shared slot-store helper would drop about 80 copied lines that the next upstream sync must otherwise update by hand. - Should fix.
tests/test-backend-ops.cpp:17576-17579. Thex_tailcases have slot copies and no history reader. The real part-0 graph has aCONT(VIEW(concat))history reader and no slot copies, so the matcher's tail-reader branch is not tested with a prefix x. Add one case with that shape.
Nits: the new struct in cases-rs.cpp:17-23 sits under the doc comment of case_multi_seq_split_replay. Both conv_qkv calls use the same cb() names, so add a _part1 suffix to the second call. The comment at qwen4exp.cpp:2187 says the arithmetic is the same, but the chunked scan rounds differently.
Correctness
PASS for output, FAIL on one ROCm test gate (Ask 1). Without a draft, head and master give byte-identical llama-debug final logits and token ids (code and prose corpora), and the same greedy server stream, on both backends. With rollback slots forced (n_rs_seq 3), the argmax is the same everywhere, and head is closer to the no-slot logits than master in 3 of 4 backend and corpus cells. The 4th cell is inside the noise. With the draft, all 8 servers gave the same 64-token stream with 46 of 50 drafts accepted. SSM_CONV, CONCAT and GATED_DELTA_NET match master on both backends, and CONCAT_SSM_CONV_SILU passes 15/15 on Vulkan with 0 x layout rejects. test-llama-context passes 17/17 on both backends, with HIP_LAUNCH_BLOCKING unset and set to 1, but not under the ctest env on ROCm. Not run: KLD/PPL, the full backend suites, the structured and numeric corpora, -np > 1.
Performance
Qwen3.8-Flash-Next (qwen4exp) TQ2_0 with the shared Q4_K_M MTP sidecar, --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -b 2048 -ub 2048, servers in the order master / head / head / master, 4 requests per size:
| backend | prompt | master t/s [min-max] | head t/s [min-max] | change |
|---|---|---|---|---|
| Vulkan | 2048 | 874.1 [860-888] | 964.4 [949-980] | +10.3% |
| Vulkan | 8192 | 843.0 [836-850] | 920.5 [915-925] | +9.2% |
| Vulkan | 32768 | 853.8 [851-857] | 925.9 [925-927] | +8.5% |
| ROCm | 2048 | 809.7 [794-825] | 848.9 [835-865] | +4.8% |
| ROCm | 8192 | 801.7 [795-809] | 853.7 [850-856] | +6.5% |
| ROCm | 32768 | 814.3 [812-817] | 876.6 [875-878] | +7.7% |
The ranges do not overlap. Without a draft, prompt and decode speed match master within 0.1% on both backends.
Verification
Strix Halo (gfx1151), Vulkan (RADV) and ROCm. The PR is based on the current master c495f90 (0 commits behind). We compared the PR merged into that master against master.
Not tested
KLD/PPL, llama-bench depth sweeps, full backend suites, -np 2 and -np 4, the wide-verify check, and the UD-Q4_K_XL + Q8_0 files from the description.
Thanks for the careful rework.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
- Ubuntu 26.04.1, kernel 7.0.0-43-generic, Strix Halo (gfx1151, Radeon 8060S), 128 GB unified memory.
- ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb69.
- Mesa RADV 26.0.8, shaderc glslc 2026.1.
- cmake 4.2.3, gcc 15.2.0, ninja 1.13.2.
Compared
- master tip and merge base: c495f90 (
c495f90f55e647f9a5b6820b503be6d39c74baa7). The PR was 0 commits behind. - PR head: b329e93 (
b329e9374d4994f1fc32037770b412b9cebd1ca7). - merged (local only, clean, tree equal to the PR head): 010fd19b9.
- Earlier reviewed head: d208045.
Build
Vulkan: cmake -S <tree> -B <tree>/build-vk -DGGML_VULKAN=ON -DGGML_HIP=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja
ROCm: cmake -S <tree> -B <tree>/build-hip -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 \
-DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R) -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake --build <tree>/build-<be> -j 16 --target llama-server llama-debug test-backend-ops test-llama-context test-llama-archs
No HIP source changed, so we did not run the -Werror HIP build or the VGPR spill gate.
Models
| model | source | sha256 |
|---|---|---|
| Qwen3.8-Flash-Next-Gyro-M-TQ2_0.gguf (qwen4exp) | agentionai/Qwen3.8-Flash-Next-Gyro-GGUF | 7aa36d15131d255179ab6c87fa9c9f81a0b541fc9e81e959d4c3e29eb20feb5f |
| mtp-Qwen3.8-Flash-Next-shared-Q4_K_M.gguf (head-less MTP sidecar) | unsloth/Qwen3.8-Flash-Next-GGUF, MTP/ |
f521868a9e143718bef513772f6e04d9642551e362cf2439636d2abdbd149dfc |
| random tiny qwen4exp MoE | test-llama-archs -a qwen4exp -o <dir> (base build) |
n/a |
Gyro-M always ran with -lm none -lzm on-direct. Peak GPU memory was 41 GiB.
Commands
# op tests, base and head
test-backend-ops test -b <dev> -o SSM_CONV | -o CONCAT | -o GATED_DELTA_NET # Vulkan0 and ROCm0
test-backend-ops test -b Vulkan0 -o CONCAT_SSM_CONV_SILU # also with GGML_VK_FUSION_DEBUG=1
# context tests, tiny qwen4exp, base and head
test-llama-context -m <tiny> -ngl 99 # Vulkan; ROCm with HIP_LAUNCH_BLOCKING unset and =1
GGML_SCHED_DEBUG_REALLOC=1 test-llama-context -m <tiny> -ngl 99 [--test replay] # ROCm, 3 runs each side
GGML_SCHED_DEBUG_REALLOC=1 test-llama-context -m <tiny> -ngl 0 # CPU only (no GPU visible)
GGML_VK_FUSION_DEBUG=1 test-llama-context -m <tiny> -ngl 99 --test rollback_wide_prompt
# final logits, rollback slots forced with an LD_PRELOAD shim that wraps llama_init_from_model and sets n_rs_seq = 3
llama-debug -m <Gyro-M> -f <corpus> -c 8192 -b 8192 -ub 2048 -ngl 99 -fa on -ctk f16 -ctv f16 -lm none -lzm on-direct \
--save-logits --logits-output-dir <dir>
# corpora: the first ~20 KB (cut at a newline) of tests/corpus/correctness-code.txt (5848 tokens) and correctness-prose.txt (4827 tokens)
# variants: base AR, head AR (cmp against base AR), base slots, head slots
# prefill with the draft, servers master / head / head / master
llama-server -m <Gyro-M> -ngl 99 -fa on -ctk f16 -ctv f16 -lm none -lzm on-direct -np 1 --cache-ram 0 -c 33792 -b 2048 -ub 2048 \
-md <sidecar> -ngld 99 --spec-type draft-mtp --spec-draft-n-max 3
# prompt ids: the four corpora joined, tokenized once with /tokenize; first N ids per size; the same id files for every server
# per server: 512-token warm-up, then 2048 / 8192 / 32768 x 2, /completion n_predict 1 cache_prompt false, timings.prompt_per_second
# then 2048 prompt + n_predict 64, temperature 0, top_k 1
# fold check: the same server with GGML_VK_FUSION_DEBUG=1, one 2048 prompt, base and head
# no-draft check: the same server without -md / -ngld / --spec-*, 2048 prompt + 64 greedy tokens, base and head
Results
Op tests:
| op | Vulkan base | Vulkan head | ROCm base | ROCm head |
|---|---|---|---|---|
| SSM_CONV | 45/45 | 45/45 | 45/45 | 45/45 |
| CONCAT | 202/202 | 202/202 | not run | not run |
| GATED_DELTA_NET | 69/69 | 69/69 | 69/69 | 69/69 |
| CONCAT_SSM_CONV_SILU | 12/12 | 15/15 (3 new prefix cases), 0 x layout |
n/a | n/a |
test-llama-context, tiny qwen4exp:
| run | base | head |
|---|---|---|
| Vulkan, default env | 15/15 | 17/17 |
ROCm, HIP_LAUNCH_BLOCKING unset / =1 |
15/15 / 15/15 | 17/17 / 17/17 |
ROCm, GGML_SCHED_DEBUG_REALLOC=1, --test replay, 3 runs |
3 passed | 3 aborted: ggml-backend.cpp:1958: ggml_backend_sched_alloc_splits: unexpected graph reallocation (graph size = 484, nodes = 484, leafs = 93) |
| ROCm, compute buffer mismatch warnings | 0 | 13 |
Vulkan, GGML_SCHED_DEBUG_REALLOC=1 |
aborts earlier in rf |
the same abort in rf (exists on master, so replay was not reached) |
CPU, GGML_SCHED_DEBUG_REALLOC=1 |
15/15 | 17/17 |
The new cases pass alone under the realloc env on ROCm. The abort comes in the next case, after the first split graph has grown the buffer. On Vulkan, rollback_wide_prompt under the fusion debug log shows 23 part-1 concat srcs lines and 0 x layout, so the split engages.
llama-debug, final logits (AR = no slots):
| backend | corpus | head AR vs base AR | head slots vs base slots (cos) | head slots vs base AR (cos) | base slots vs base AR (cos) | argmax |
|---|---|---|---|---|---|---|
| Vulkan | code | byte-identical | 0.998256 | 0.998587 | 0.998237 | equal in all |
| Vulkan | prose | byte-identical | 0.995280 | 0.995693 | 0.996463 | equal in all |
| ROCm | code | byte-identical | 0.997878 | 0.998699 | 0.997778 | equal in all |
| ROCm | prose | byte-identical | 0.987193 | 0.992028 | 0.989803 | equal in all |
For scale, ROCm AR against Vulkan AR on prose is cos 0.99282. The token ids are identical in all variants.
Fold check with the draft (one 2048 prompt, debug log lines):
x layout |
concat srcs |
state layout |
|
|---|---|---|---|
| master | 0 | 18 | 14 |
| head | 0 | 126 | 14 |
The extra concat srcs lines are the part-1 K-token concat. Our earlier review measured 576 x layout lines on d208045.
Greedy streams: with the draft, all 8 servers (both backends, both sides) gave the same 64 tokens, with 46 of 50 drafts accepted. Without the draft, base and head gave the same stream on both backends.
Performance
Prefill t/s with the draft, every request (master: servers 1 and 4; head: servers 2 and 3; 2 requests each):
| backend | prompt | master | head |
|---|---|---|---|
| Vulkan | 2048 | 866.8 887.9 860.4 881.2 | 948.8 980.2 951.5 977.2 |
| Vulkan | 8192 | 839.3 850.0 836.3 846.4 | 918.2 925.1 915.3 923.5 |
| Vulkan | 32768 | 856.6 855.2 852.1 851.2 | 926.5 925.6 926.7 924.9 |
| ROCm | 2048 | 815.7 793.7 825.1 804.4 | 865.0 844.1 851.5 835.1 |
| ROCm | 8192 | 795.3 809.1 798.1 804.4 | 855.2 853.0 856.1 850.4 |
| ROCm | 32768 | 816.7 815.4 813.2 811.8 | 876.7 878.3 874.8 876.6 |
Decode after the 2048 prompt with the draft: Vulkan 49.18 / 49.44 (master) vs 50.32 / 50.21 (head), ROCm 42.66 / 42.71 vs 43.62 / 42.49 t/s. Without the draft: Vulkan pp 1017.8 vs 1018.3, tg 30.26 vs 30.34; ROCm pp 967.3 vs 967.4, tg 25.85 vs 25.85.
Correctness
| check | method | result |
|---|---|---|
| op tests for the changed ops | test-backend-ops, both backends | PASS, same as master; 3 new fusion cases pass |
| full backend suites, test-vk-exact | not run | not run (time budget) |
| context and rollback tests | test-llama-context, tiny qwen4exp | PASS in the default env; FAIL under the ctest env on ROCm (Ask 1) |
| no-draft path | llama-debug logits + token ids, cmp; server greedy stream | byte-identical, both backends |
| slot path | llama-debug logits, slots forced | argmax equal, head as close or closer to AR |
| KLD/PPL short and long | not run | the split engages only on prompt ubatches with no output before the last K rows, and llama-perplexity outputs every row |
| greedy decode with the draft | server, 64 tokens | same stream and acceptance on all servers |
ROCm HIP_LAUNCH_BLOCKING unset and =1 |
test-llama-context | same results |
| HIP -Werror and VGPR gate | n/a | no HIP source changed |
| spec unit tests | not run | the carry-row change was reviewed in the code |
Findings in full
- Blocking: the reserve (
llama-context.cpp:2971-2995) sets outputs from row 0 of each sequence, soubatch.output[0]is true and qwen4exp builds the unsplit graph at reserve time. The split graph has more nodes (484 on the tiny model) and a larger compute buffer, which is allocated only at the first split ubatch. On real Gyro-M runs the mismatch lines were the same on base and head, so we saw no extra memory there. The repo's own gate (GGML_SCHED_DEBUG_REALLOC=1intests/CMakeLists.txt) treats this as a failure. - Should fix: test coverage of the production paths (see Ask 2).
- Should fix: about 80 lines copied from
build_conv_state_atandbuild_recurrent_attn(see Ask 3). The conv/q/k/v block in theconv_qkvlambda is still upstream code, now re-indented, so upstream edits there will conflict. We accept that cost, because the split needs the block twice. - Should fix: the test shape (see Ask 4).
- Info: the HIP gdn_conv matcher still requires the whole x, so on ROCm part 0 runs the unfused conv. That is correct, and ROCm gains without it.
- Info: graph reuse ignores output positions, so in a rare case a prompt ubatch can reuse an unsplit graph, or the reverse. Both graphs write the same slots, so only the numerics differ.
- Checked and correct: the Vulkan
x_prefixread range (the strides limit it to tokens [0, T), andview_offsmust be 0); the history reader of the part-0 concat (taken as a tail reader, written before the cont); the SSM and conv slot offsets and order; theback_to_bufview;LLAMA_GDN_NORM_PADoff, the fused GDN paths off, LoRA, EXL3 and bf16ssm_out, n = K + 1; the carry row with mixed drafters.
Claims
| claim | result |
|---|---|
| Vulkan prefill with the draft +14.2% / +11.1% / +9.3% at 2k / 8k / 32k | Reproduced in direction, smaller on our model: +10.3% / +9.2% / +8.5% |
| ROCm with the draft +6.6% / +8.7% at 8k / 32k against commits 1-2 | Not tested as stated. Against master: +6.5% / +7.7% (+4.8% at 2k) |
| No-draft serving unchanged | Reproduced, both backends |
The Vulkan fold accepts the part-0 prefix (0 x layout) |
Reproduced |
CONCAT_SSM_CONV_SILU 15/15 |
Reproduced |
test-llama-context passes, including rollback_wide_prompt |
Reproduced in the default env; fails under the ctest env on ROCm |
| Verify batches keep the unsplit path | Confirmed by reading the code; not measured |
-np 2 / -np 4 gains |
Not tested |
Not tested
- KLD/PPL, the structured and numeric corpora,
llama-benchdepth sweeps, the full backend suites,test-vk-exact. -np 2and-np 4, the wide-verify check (--spec-n-rs-seq 1), the spec unit tests.- The UD-Q4_K_XL target and the Q8_0 MTP file from the description.
- The server pytest suite (not installed).
- GPUs other than gfx1151.
A prompt batch is never accepted against, so its rows past the last one were copied for nothing (80 MB per 2048 rows on Qwen3.8-Flash-Next). accept() reads the row of the last accepted draft token, and only the rows of a verify batch carry outputs. Keep the rows from the first output row of the sequence on: a verify batch keeps every row, whichever drafter made the draft and however wide it is, and a prompt batch keeps its last row, the carry. With shared memory the master rule stays: all rows when every row is an output, else the last row. Resolution of the rebase onto the new row selection by dzannotti. Assisted-by: Claude Opus 5.5
The draft's eh_proj input is [2*n_embd, hc, n_tokens], so ggml ran n_tokens batched hc-column mat-vecs, each reading the whole weight: 93 ms per 2048-token prompt ubatch on Qwen3.8-Flash-Next (Vulkan perf logger), 70% of the draft's prompt catch-up. Reshape to 2D around the matmul. Assisted-by: Claude Opus 5.5
…r sequence After such a ubatch the recurrent memory refuses a partial rollback (rs_max = 0), so no snapshot slot but the final state is ever read. Run the no-draft scan and conv state store for it, and keep the K-slot path for ubatches that a rollback can end inside. Suggested by dzannotti in the review of #255. Assisted-by: Claude Opus 5.5
b329e93 to
df2f118
Compare
|
Thanks @dzannotti, the plain-scan rule was the right call. Rebased onto master 403dfcb and reworked as you suggested:
Strix Halo (gfx1151), Vulkan RADV 26.2.4, Qwen3.8-Flash-Next UD-Q4_K_XL + shared Q4_K_M MTP,
The middle row comes from a local test build with the plain scan switched off; that switch is not in the branch. The carry row alone measured +0.1% / +2.3% on a cut-down model, inside the spread, same as you found. I kept it since it is small, but happy to drop it. Without a draft: same logits and token ids as master on this model, llama-bench pp/tg within the spread. On the extra compute buffer line: master prints it too on this model (953 vs 946 MiB, plus a Vulkan_Host line even without a draft). Both reallocate once, on a 2048-token prompt ubatch at depth 4096, and with the plain scan that growth is about 20 MiB larger. It looks like a reserve gap on master, so I'd rather look at it separately, unless you want it in here. Not tested: ROCm speed, |
|
Measured the case the review could not run, on gfx1150 (Radeon 890M, Strix Point; not Strix Halo), Vulkan, Mesa 26.1.6 Arms: master 253022c (today's, with #318) and 253022c with this PR's head df2f118 merged (no conflicts).
Not run: ROCm; Strix Halo; a second sample at 2048 and 16384. Measured and written by Claude Code (an AI agent) for rcfa. |
dzannotti
left a comment
There was a problem hiding this comment.
This review replaces our review of 2026-11-22.
Verdict
Changes requested, for one small fix. The reworked branch does what we asked for, and the speed and logit results are good on both backends. Merged into current master, the plain scan makes test-llama-context fail on 10 architectures under GGML_SCHED_DEBUG_REALLOC=1 (the ctest setting), on Vulkan and on ROCm. Master passes on them.
Direction
Accept after work. This is the shape we asked for. With an MTP draft loaded, prompt processing is 11 to 15% faster on Qwen3.8-Flash-Next and 2 to 5% faster on Qwen3.8-27B. Without a draft, nothing changes.
Asks
- Blocking.
src/llama-context.cpp:1086: withn_rs_seq > 0the reserve no longer covers the K-slot graph of a short multi-token ubatch. The pp reserve is now the plain-scan graph, and the tg reserve has only one token per sequence. Master'srollback_cell_movecase (from #318, newer than your base 403dfcb) runs such a ubatch and aborts with "unexpected graph reallocation" on bailingmoe3, clover_moe, glm5-next, kimi-k3, kimi-k31, lfm2, lfm2moe, lfm3, nemotron_h and nemotron_h_moe. qwen35 and qwen4exp pass, becausegraph_depends_on_n_tokens()already probes the token ranges for them. This one-line change fixes all 10 on both backends (we tested it):Then run- if (!cparams.training && !model.no_alloc() && model.graph_depends_on_n_tokens()) { + if (!cparams.training && !model.no_alloc() && (model.graph_depends_on_n_tokens() || cparams.n_rs_seq > 0)) {
ctest -L mainon both backends against current master.inkling2-moeaborts the same way on master and with the fix, so it is not yours.
Optional: in common/speculative.cpp the nested ternary for h_offset would read better as an if (is_mem_shared) block, and the new comments are hard-wrapped (AGENTS.md asks for no hard wraps).
Correctness
PASS for model output, FAIL for the context test (Ask 1).
- Without a draft, base and head are byte-identical on both backends. This covers final f32 logits and token ids on all four corpora (27B and Flash-Next), the
.kldfiles, and 256-token greedy decodes. - We forced
n_rs_seq = 3on the target without a draft. Head then gives byte-identical logits, a KLD of 0 and the same greedy stream asn_rs_seq = 0. Master's K-slot path is at or near the noise floor (Flash-Next VK 0.00283 vs floor 0.00270; ROCm 0.00259 vs 0.00222). - With the draft, the head's first-token log-probs on the 27B on ROCm equal the no-draft ones, and on Flash-Next they are closer to the no-draft ones than master's.
test-llama-archs(all), the four op tests and the spec unit tests pass on both sides.-np 2and-np 4(unified and not) and DFlash2 ran with no abort.
Performance
Prompt t/s with the draft (--spec-draft-n-max 3 -np 1 -b 2048 -ub 2048), mean of 4 requests from 4 servers in base/head/head/base order (2 requests at 32k on the 27B and at 64k):
| backend | model | 2048 | 12000 | 32000 | 64000 |
|---|---|---|---|---|---|
| Vulkan | Flash-Next + shared MTP | 948.9 -> 1073.3 (+13.1%) | 887.3 -> 997.3 (+12.4%) | 902.7 -> 1001.1 (+10.9%) | 879.6 -> 977.3 (+11.1%) |
| ROCm | Flash-Next + shared MTP | 801.5 -> 923.8 (+15.3%) | 791.3 -> 892.8 (+12.8%) | 816.1 -> 924.2 (+13.2%) | 800.0 -> 904.3 (+13.0%) |
| Vulkan | 27B + MTP head | 498.9 -> 515.3 (+3.3%) | 450.6 -> 460.8 (+2.3%) | 414.8 -> 424.5 (+2.3%) | 372.4 -> 382.1 (+2.6%) |
| ROCm | 27B + MTP head | 391.8 -> 411.1 (+4.9%) | 372.8 -> 390.0 (+4.6%) | 332.9 -> 346.6 (+4.1%) | 278.8 -> 288.1 (+3.4%) |
Without a draft, every cell is within 1% of master. Decode with the draft, averaged over 6 prompts x 256 tokens, is 0.4 to 2.5% lower, with acceptance 0.3 to 3.6 points lower. The texts differ by prompt, and head wins on some prompts. The prompt gain is larger than this cost from 2048 tokens on. The ranges are in the details block.
Verification
Strix Halo (gfx1151), Vulkan (RADV) and ROCm. We compared your branch merged into master 1da4f8e (7 commits behind, clean merge) against master.
Not tested
Other GDN or KDA models with a real draft (the tiny models of all architectures ran in the context tests), CPU speed, and the server pytest suite (not available).
Thanks for the quick rework.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
- Ubuntu 26.04.1, kernel 7.0.0-44-generic, Strix Halo (gfx1151, Radeon 8060S), 128 GB unified memory.
- ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb69.
- Mesa RADV 26.0.8.
- cmake 4.2.3, gcc 15.2.0, ninja.
Compared
- master tip: 1da4f8e (
1da4f8e50cd679aba69682990a9abe9bacec7f5c) - PR head: df2f118 (
df2f118d20d952562028dbcd4128182749eb1956), merge base 403dfcb, 7 commits behind - merged: f961300ec (local
git merge --no-ffof the head into 1da4f8e, never pushed) - reserve fix: f961300ec + the Ask 1 line (local only)
Build
ROCm: 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
cmake --build <tree>/build-<be> -j
Models
| model | source | sha256 (prefix) |
|---|---|---|
| Qwen3.8-Flash-Next-Gyro-M-TQ2_0.gguf (qwen4exp) | agentionai/Qwen3.8-Flash-Next-Gyro-GGUF | 7aa36d15131d2551 |
| mtp-Qwen3.8-Flash-Next-shared-Q4_K_M.gguf | unsloth/Qwen3.8-Flash-Next-GGUF, MTP/ |
f521868a9e143718 |
| Qwen3.8-27B-UD-Q4_K_XL.gguf (qwen35, built-in MTP head) | unsloth | 3f227079 |
| Qwen3.8-27B-DFlash2-Q4_K_M.gguf | DFlash2 draft for the 27B | 1a25c568 |
| LFM2-700M-Q4_K_M.gguf | LiquidAI | 684e8406dc133214 |
| Inkling-2-Mini-IQ4_NL.gguf | ggml-org/Inkling-2-Mini-GGUF | cbdf3fa9 |
| 146 tiny models | test-llama-archs -o <dir> (master build) |
n/a |
Flash-Next runs with -lm none -lzm on-direct.
Commands
# tests, both trees, both backends
ctest --test-dir <build> -L main -E 'test-opt|test-llama-archs' --output-on-failure
test-llama-archs -b <dev>
test-llama-context --models <tiny> -ngl 99 # plain, and GGML_SCHED_DEBUG_REALLOC=1 x3
HIP_LAUNCH_BLOCKING=1 test-llama-context --models <tiny> -ngl 99 # ROCm, also with the realloc env
GGML_SCHED_DEBUG_REALLOC=1 test-llama-context -m <tiny>/<arch>.gguf -ngl 99 # each of the 146 models alone, base and head
test-backend-ops test -b <dev> -o GATED_DELTA_NET | SSM_CONV | CONCAT | CONCAT_SSM_CONV_SILU
# parity, n_rs_seq forced through llama_context_params (an LD_PRELOAD wrapper of llama_init_from_model) for the "rs3" runs
llama-debug -m <model> -f tests/corpus/correctness-<t>.txt -c 16384 -b 16384 -ub 512 -ngl 99 -fa on -ctk f16 -ctv f16 --save-logits --logits-output-dir <dir>
llama-perplexity -m <model> -f <4 corpora joined> -c 2048 -b 2048 -ub 2048 --chunks 6 -ngl 99 -fa on -ctk f16 -ctv f16 --kl-divergence-base <base.kld> [--kl-divergence]
llama-perplexity ... -c 16384 -b 512 -ub 512 --chunks 2 ... # long, 27B only (Flash-Next at c16384 does not fit our memory cap)
llama-completion -m <model> -f correctness-prose.txt -n 256 --temp 0 --seed 1 -no-cnv --ignore-eos -ngl 99 -fa on -c 16384
# servers, one at a time
llama-server -m <model> -ngl 99 -fa on -ctk f16 -ctv f16 --cache-ram 0 -b 2048 -ub 2048 -np 1 -c 70000 \
[-md <sidecar> -ngld 99] --spec-type draft-mtp --spec-draft-n-max 3 # or -md <DFlash2> --spec-type draft-dflash2
# prompt = the four corpora joined twice, tokenized once with /tokenize, first N ids; 512-token warm-up;
# N = 2048, 12000 (x2 each), 32000 (x2, 27B x1), 64000 (x1), n_predict 1, cache_prompt false
# then 2048 prompt + 256 greedy tokens (top_k 1, n_probs 10); a 2048 + 64 + 1500 continuation with cache_prompt true vs false
# decode: 6 prompts of 2048 ids (offsets 0, 5000, 10000, 15000, 20000, 30000) x 256 greedy tokens, 4 servers per side
# -np 2 and -np 4 (kv-unified and not): concurrent prompts of 3000 / 2000 and 200 / 1500 / 5000 / 50 tokens, compared with solo runs
Results
test-llama-context, realloc env, each tiny model alone (146 models):
| Vulkan base | Vulkan head | Vulkan head + fix | ROCm base | ROCm head | ROCm head + fix | |
|---|---|---|---|---|---|---|
| models that abort | inkling2-moe | inkling2-moe + 10 | inkling2-moe | inkling2-moe | inkling2-moe + 10 | inkling2-moe |
The 10 are bailingmoe3, clover_moe, glm5-next, kimi-k3, kimi-k31, lfm2, lfm2moe, lfm3, nemotron_h, nemotron_h_moe. They abort in rollback_cell_move, after rollback_bound. The --models run and the ctest test-llama-context abort on both sides, because inkling2-moe aborts on master too. Without the realloc env, 146/146 pass on both sides and both backends, also with HIP_LAUNCH_BLOCKING=1. On CPU (-ngl 0), lfm2 and kimi-k3 already abort on master, so CPU says nothing here.
Other tests, the same on base and head and both backends: ctest 34/35 (only test-llama-context, see above); test-llama-archs all pass (155 ROCm, 156 Vulkan); GATED_DELTA_NET 69/69, SSM_CONV 60/60, CONCAT 246/246 (VK), CONCAT_SSM_CONV_SILU 12/12 (VK).
llama-debug, all four corpora, both backends, 27B and Flash-Next (logits and token ids):
| comparison | result |
|---|---|
| base rs0 vs head rs0 | identical |
| head rs3 vs base rs0 | identical |
| base rs3 vs base rs0 | logits differ, tokens identical |
| LFM2-700M and Inkling-2-Mini (code, prose): every pair | identical |
KLD against base rs0 (.kld files of base rs0 and head rs0 have the same sha256 on both backends):
| backend | model | floor (ub 512) | base rs3 | head rs3 | head rs0 (long) |
|---|---|---|---|---|---|
| Vulkan | Flash-Next short | 0.002696 | 0.002827 | 0.000000 | n/a |
| Vulkan | 27B short / long | 0.000004 / n/a | 0.000005 / 0.000014 | 0 / 0 | 0 |
| ROCm | Flash-Next short | 0.002223 | 0.002591 | 0.000000 | n/a |
| ROCm | 27B short / long | 0.000552 / n/a | 0.000383 / 0.000545 | 0 / 0 | 0 |
Greedy 256 tokens (prose): base A/A identical; head equal to base; head rs3 equal to base rs0 on both models on Vulkan and on the 27B on ROCm. On ROCm Flash-Next, base rs3 and head rs3 both differ from rs0, because single-token decode steps use the K-slot path on both sides.
Prompt t/s, mean [min-max]:
| backend | model | N | base | head | change |
|---|---|---|---|---|---|
| VK | Flash-Next + MTP | 2048 | 948.9 [931.8-971.8] | 1073.3 [1039.3-1111.1] | +13.1% |
| VK | Flash-Next + MTP | 12000 | 887.3 [876.6-897.0] | 997.3 [991.8-1003.6] | +12.4% |
| VK | Flash-Next + MTP | 32000 | 902.7 [902.1-903.2] | 1001.1 [998.7-1004.1] | +10.9% |
| VK | Flash-Next + MTP | 64000 | 879.6 [878.4-880.8] | 977.3 [976.3-978.4] | +11.1% |
| VK | Flash-Next, no draft | 2048 / 32000 | 1133.5 / 1080.2 | 1144.8 / 1082.2 | +1.0% / +0.2% |
| ROCm | Flash-Next + MTP | 2048 | 801.5 [749.2-824.7] | 923.8 [911.4-935.6] | +15.3% |
| ROCm | Flash-Next + MTP | 12000 | 791.3 [782.7-796.1] | 892.8 [881.2-899.4] | +12.8% |
| ROCm | Flash-Next + MTP | 32000 | 816.1 [815.0-816.9] | 924.2 [919.4-926.6] | +13.2% |
| ROCm | Flash-Next + MTP | 64000 | 800.0 [799.6-800.4] | 904.3 [903.1-905.4] | +13.0% |
| ROCm | Flash-Next, no draft | 2048 / 32000 | 959.3 / 964.9 | 962.0 / 964.4 | +0.3% / -0.0% |
| VK | 27B + MTP | 2048 | 498.9 [489.3-509.2] | 515.3 [504.7-526.5] | +3.3% |
| VK | 27B + MTP | 12000 | 450.6 [447.5-453.8] | 460.8 [459.8-461.6] | +2.3% |
| VK | 27B + MTP | 32000 | 414.8 [413.9-415.7] | 424.5 [424.2-424.8] | +2.3% |
| VK | 27B + MTP | 64000 | 372.4 [371.6-373.1] | 382.1 [381.9-382.2] | +2.6% |
| VK | 27B + DFlash2 | 2048 | 509.0 [496.1-521.9] | 528.5 [516.9-540.0] | +3.8% |
| VK | 27B, no draft | 2048 / 32000 | 537.9 / 441.3 | 535.5 / 440.4 | -0.4% / -0.2% |
| ROCm | 27B + MTP | 2048 | 391.8 [384.8-398.8] | 411.1 [403.2-419.7] | +4.9% |
| ROCm | 27B + MTP | 12000 | 372.8 [372.2-373.5] | 390.0 [390.0-390.1] | +4.6% |
| ROCm | 27B + MTP | 32000 | 332.9 [332.6-333.1] | 346.6 [346.5-346.7] | +4.1% |
| ROCm | 27B + MTP | 64000 | 278.8 [278.5-279.0] | 288.1 [287.8-288.5] | +3.4% |
| ROCm | 27B + DFlash2 | 2048 | 399.6 [391.9-407.3] | 421.1 [411.7-430.5] | +5.4% |
| ROCm | 27B, no draft | 2048 / 32000 | 421.9 / 359.1 | 421.1 / 359.1 | -0.2% / +0.0% |
Decode with the draft, 6 prompts x 256 tokens, 2 servers per side (each server gives the same result):
| backend | model | base tg | head tg | change | acceptance base -> head |
|---|---|---|---|---|---|
| VK | Flash-Next | 47.87 [42.29-56.38] | 46.69 [37.18-53.75] | -2.5% | 0.792 -> 0.756 |
| ROCm | Flash-Next | 44.57 [41.48-50.62] | 43.83 [39.31-51.92] | -1.7% | 0.812 -> 0.781 |
| VK | 27B | 30.08 [26.58-33.80] | 29.81 [25.59-33.63] | -0.9% | 0.807 -> 0.787 |
| ROCm | 27B | 27.06 [23.29-30.35] | 26.94 [24.14-30.31] | -0.4% | 0.809 -> 0.806 |
Per prompt, head is faster on 2 of 6 Flash-Next prompts and slower on 4. On both sides the greedy streams leave the no-draft stream at about the same token. On the one Vulkan prompt where both sides give the no-draft stream for all 256 tokens, head accepts 184/210 and base 186/206.
Multi-slot: no abort or "failed to remove sequence" on any server. The concurrent vs solo streams differ on some slots both with and without a draft, on base and on head alike (batch shape), so they do not gate the PR.
Compute buffer warnings at shutdown: with the draft, the Vulkan0 line is 953.09 MiB on head and 947.04 MiB on base. 953.09 MiB is also the size of master without a draft, so head grows to the no-draft graph. On ROCm head prints 639.21 MiB where base prints 648.21 MiB.
Correctness
| check | method | result |
|---|---|---|
| spec unit tests | ctest -L main (spec-mtp-pcum, draft-vocab, rejection sampling) |
pass both |
| test-llama-archs | all archs, both backends | pass both |
| test-llama-context | 146 tiny models, realloc env, each alone | FAIL: 10 head-only aborts (Ask 1); pass with the fix |
| f32 logit parity, no draft | llama-debug, 4 corpora, 27B + Flash-Next | byte-identical |
| f32 logit parity, n_rs_seq = 3 | llama-debug, head rs3 vs rs0 | byte-identical |
| KLD/PPL short | c2048, 6 chunks | head 0; base rs3 within floor (VK) or near it (ROCm Flash-Next) |
| KLD/PPL long | c16384, 27B | head 0 |
| greedy decode A/A | llama-completion 256 | base A/A identical, head equal |
| target output with draft, temp 0 | server, 2048 prompt + 256, and 6 prompts | not a gate (see Results); first-token log-probs closer to no-draft on head |
| HIP_LAUNCH_BLOCKING=1 | test-llama-context, ROCm | same as unset |
| op tests | GDN, SSM_CONV, CONCAT, CONCAT_SSM_CONV_SILU | pass both (no ggml change) |
| -Werror / VGPR gate | n/a | no HIP files changed |
| server pytest | n/a | not available |
Findings in full
- Blocking: reserve gap (Ask 1). Before this PR the pp reserve built the K-slot graph at full width, so it covered every short K-slot ubatch. Now the pp reserve builds the plain graph. A ubatch of 2 to n_rs_seq+1 tokens per sequence with several sequences builds a K-slot graph that neither reserve covers.
reserve_token_rangesprobes the node-count change at n_rs_seq+2 and reserves the top of each range, but it runs only forgraph_depends_on_n_tokens()models (qwen35, qwen35moe, qwen4exp). Running it whenevern_rs_seq > 0closes the gap. In production this is a compute-buffer grow at runtime, not wrong output. - Upstream ggml-org ggml-org#31669 ("GDN: use replay instead of rollback") rewrites
build_recurrent_attn. Its keep rule has the same upper bound,n_seq_tokens <= n_rs_seq + 1. At the next sync thedelta-net-base.cpphunk resolves to upstream. Thebuild_conv_state_storehunk stays. common/speculative.cpp: for verify batches and shared memory the result is the same as master. For a prompt batch only the carry row is copied now, which is whataccept()reads.
Claims
- "16 to 18% faster on Vulkan with the MTP draft": reproduced in direction, +10.9 to +13.1% on our Flash-Next file (TQ2_0, not UD-Q4_K_XL), +12.8 to +15.3% on ROCm.
- "No change without a draft: same logits and token ids": reproduced, byte-identical.
- "
ctest -L mainpasses on Vulkan and ROCm": not reproduced on current master (Ask 1). Your base 403dfcb does not haverollback_cell_move. - "four op tests pass": reproduced.
- decode "-0.4%": we see -0.4 to -2.5% over 6 prompts.
Not tested
Real GDN/KDA models other than qwen35 and qwen4exp with a draft (only the tiny models), Flash-Next long KLD (memory), CPU speed, server pytest (not installed), GPUs other than gfx1151.
Replaced by the review of 2026-11-26.
With n_rs_seq > 0 the pp reserve is the plain-scan graph and the tg reserve has one token per sequence, so a short multi-token ubatch that takes the K-slot path was not covered and test-llama-context aborted with "unexpected graph reallocation" under GGML_SCHED_DEBUG_REALLOC=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
We added the one-line fix from our review as commit 6f02a13 ( Re-checked on Strix Halo, with the branch merged into current master 730b567 (clean merge) against that master, on Vulkan and on ROCm (with
Thanks @Nathanw1014 for the work and the quick rework. Comment made with AI on behalf of the strix-llama.cpp maintainers. |
…r sequence After such a ubatch the recurrent memory refuses a partial rollback (rs_max = 0), so no snapshot slot but the final state is ever read. Run the no-draft scan and conv state store for it, and keep the K-slot path for ubatches that a rollback can end inside. Suggested by dzannotti in the review of halo-box#255. Assisted-by: Claude Opus 5.5 (cherry picked from commit df2f118)
With an MTP draft loaded, prompt processing on qwen4exp is 16 to 18% faster on Vulkan (Strix Halo, Qwen3.8-Flash-Next UD-Q4_K_XL + shared Q4_K_M MTP).
n_rs_seq + 1tokens per sequence runs the plain scan and stores only the final state. The memory refuses a partial rollback after such a ubatch (rs_max), so the other snapshot slots are never read. Suggested by @dzannotti.No change without a draft (
n_rs_seq = 0): same logits and token ids as master.Tested:
ctest -L mainon Vulkan and ROCm, test-backend-ops CONCAT_SSM_CONV_SILU / SSM_CONV / CONCAT / GATED_DELTA_NET on Vulkan. Not tested:-np> 1, other delta-net models with a draft, GPUs other than gfx1151.AI usage: ASSISTED. Written with Claude, tested by me.
🤖 Generated with Claude Code