Skip to content

qwen4exp : share the QSA fast-path update rows across the fast layers - #339

Open
neavra wants to merge 2 commits into
halo-box:masterfrom
nbitslabs:pr/qsa-inputs-once-per-graph
Open

neavra wants to merge 2 commits into
halo-box:masterfrom
nbitslabs:pr/qsa-inputs-once-per-graph

Conversation

@neavra

@neavra neavra commented Dec 2, 2026 •

Copy link
Copy Markdown

Overview

In the speculative verify graph every "fast" QSA layer declares its own three host inputs for the incremental
block-selection cache (members, positions, rows). The scheduler uploads each host input with its own synchronous
host-to-device copy. The rows are filled by qsa_fill_updates, which depends only on the ubatch, so every fast layer was
uploading identical bytes: three copies per graph here in place of three per fast layer.

This change lets the first fast layer own one set of the three tensors; the other fast layers point at the same tensors
(owner = false), so their set_input skips the fill and only does the per-layer qsa_commit(il). An assert checks
that every layer agrees on the row count (prep_blocks). No arithmetic changes: greedy outputs are byte-identical to
master in every cell below, and the logits compare identically to master.

Review follow-up 970e5f4 (no arithmetic): comments reworded (the saving is the per-input synchronous copy, not scheduler
split cuts), the row-count assert now checks the members tensor against r*prep_blocks, and llm_graph_input_qsa_cache
is declared inside llama_model_qwen4exp next to the other QSA inputs.

A second hunk was measured alongside and deliberately left out: copying the compact block limits to the compute backend
once per graph for the single-stream case (master reads them through two host views per layer; the multi-stream case
already takes a device copy, 04e4ecb). Alone it gives +1.3 % tg128 at depth, but costs 0.8-0.9 % on pp2048 at depth
12k-64k in every cell of both rounds (one device copy per prefill graph, visible on a two-ubatch prefill). The hunk here
has no measurable prefill cost, so it goes in on its own.

Measurements

Device:     Ryzen AI Max+ 395 / GMKtec EVO-X2
Memory:     128 GB LPDDR5X-8000
Power:      default profile (amdgpu power_dpm_force_performance_level=auto, CPU governor powersave)
BIOS:       UMA split 2 GB
Kernel:     7.0.0-44-generic, amdgpu.gttsize=126976 ttm.pages_limit=32505856 amd_iommu=off
Backend:    ROCm 10.1 (AMD clang 24.0.0git d6f6cb69), gfx1151, HIP_LAUNCH_BLOCKING=0 (unset)
Build:      -DGGML_HIP=ON -DGPU_TARGETS=gfx1151 -DCMAKE_BUILD_TYPE=Release -DGGML_CCACHE=ON
Baseline:   dc5521842 (master), built and run in this same session
Change:     310a41be8 (this commit alone on dc5521842)
Model:      Qwen3.8-Flash-Next UD-IQ4_XS + shared Q8_0 MTP draft (--spec-type draft-mtp, n-max 3, vocab 65536)
Protocol:   four builds (master, this change, the left-out hunk alone, both) run in the order A B C D then D C B A,
            fresh process per cell; tables show master and this change, both rounds, gain on the pooled means.

llama-bench, no draft model (-p 2048 -n 128 -d 0,12000,32000,64000 -b 1024 -ub 1024 -r 4 -ngl 999 -fa on -ctk f16 -ctv f16 --load-mode none), mean ± sd over 4 repetitions:

test depth master round 1 / 2 change round 1 / 2 gain (pooled)
pp2048 0 1484.2 ± 44.7 / 1477.7 ± 48.5 1468.8 ± 42.4 / 1474.9 ± 47.8 -0.6 % (sd ± 3 %)
pp2048 12000 1280.7 ± 9.0 / 1275.8 ± 10.7 1277.7 ± 11.6 / 1275.3 ± 11.8 -0.1 %
pp2048 32000 1256.4 ± 11.2 / 1252.6 ± 10.2 1254.5 ± 12.8 / 1251.5 ± 13.1 -0.1 %
pp2048 64000 1236.0 ± 15.7 / 1234.6 ± 14.9 1235.1 ± 14.7 / 1233.5 ± 17.0 -0.1 %
tg128 0 28.7 ± 0.0 / 28.9 ± 0.0 28.9 ± 0.1 / 28.9 ± 0.0 +0.5 %
tg128 12000 26.6 ± 0.0 / 26.8 ± 0.1 27.2 ± 0.1 / 27.2 ± 0.1 +1.8 %
tg128 32000 26.3 ± 0.0 / 26.5 ± 0.1 26.9 ± 0.0 / 26.9 ± 0.0 +1.9 %
tg128 64000 26.0 ± 0.0 / 26.2 ± 0.1 26.6 ± 0.1 / 26.6 ± 0.1 +1.8 %

Depth 0 has no block selection to cache, so the tg gain starts at depth; the pp2048 deltas at depth sit inside master's
own run-to-run spread (sd 9-16 t/s).

llama-bench at the review's shape (-p 512 -n 128 -d 0,12000,32000 -b 512 -ub 512 -r 3 -ngl 999 -fa on -ctk f16 -ctv f16 --load-mode none), master tip cd44688 vs this PR (310a41b + the review follow-up) merged into it, same build flags, three alternated rounds (master, PR, master, PR, master, PR); mean ± sd of the three round means, the round means in brackets:

test depth master cd44688 PR merged change
pp512 0 1286.6 ± 4.6 (1285.4, 1282.7, 1291.7) 1280.4 ± 1.5 (1282.1, 1279.2, 1279.9) -0.5 %
pp512 12000 969.4 ± 2.8 (972.6, 967.9, 967.7) 970.5 ± 6.7 (976.0, 972.3, 963.1) +0.1 %
pp512 32000 977.1 ± 6.9 (984.2, 976.5, 970.5) 977.6 ± 3.0 (980.8, 974.7, 977.3) +0.1 %
tg128 0 28.9 ± 0.2 (28.7, 29.0, 29.0) 29.0 ± 0.0 (29.0, 29.0, 29.0) +0.3 %
tg128 12000 26.8 ± 0.2 (26.6, 26.9, 26.9) 27.2 ± 0.0 (27.2, 27.2, 27.2) +1.5 %
tg128 32000 26.5 ± 0.2 (26.4, 26.6, 26.6) 26.9 ± 0.0 (27.0, 26.9, 26.9) +1.5 %

qsa_fast_fits takes the fast path only at ubatch <= 512, so this table is the one where the changed code runs on every prefill ubatch as well as in decode. Same picture as the ub1024 table above: tg gains at depth, pp flat inside the per-run sd.

Serving configuration, MTP draft on (llama-server -fa on -ctk f16 -ctv f16 -c 200704 -b 1024 -ub 1024 --parallel 1), prose prompts, fresh server per cell. Cold prefill = full prompt with cache_prompt=false; follow-up = ~3k new tokens appended to the cached prompt (the second-turn shape); decode = three 256-token greedy completions on the cached prompt, mean:

band shape master round 1 / 2 change round 1 / 2 master spread gain
8k cold prefill tok/s 1045.8 / 1040.1 1049.0 / 1031.3 0.5 % -0.3 %
8k follow-up prefill tok/s 1034.6 / 1035.0 1034.7 / 1025.4 0.0 % -0.5 %
8k decode tok/s 42.3 / 41.9 42.6 / 42.4 1.0 % +1.0 %
64k cold prefill tok/s 1084.4 / 1081.5 1081.5 / 1080.6 0.3 % -0.2 %
64k follow-up prefill tok/s 1008.2 / 1000.4 1003.8 / 1004.1 0.8 % 0.0 %
64k decode tok/s 43.4 / 43.4 43.8 / 43.8 0.0 % +0.9 %

The prefill deltas are of the size of master's own round-to-round spread and change sign between cells; the decode gain
is consistent in both rounds. An earlier 15-band sweep (8k-192k, code/prose/agentic, 30 cells) of the two-hunk version
measured +1.3..+1.9 % decode; this hunk carries about two thirds of that.

Correctness: sha256 of the greedy completion is identical across all 16 server runs (four builds × two rounds × two
bands): 8k 2bccee8d…, 64k 2fb82e37…. ctest -R qwen4exp on 310a41b: 2/2 passed (test-qwen4exp-mtp-cache-only,
test-qwen4exp-merged-weights). test-backend-ops is not affected (no backend change).

Draft acceptance (server logs of the four-build run): the accepted / generated draft-token counts are identical in
master and this change on every completion, e.g. 166 accepted / 266 generated, mean draft length 2.87 on the first 8k
completion in both master runs and both change runs; acceptance is unchanged by construction (same tokens, same drafts).

Logit comparison (llama-perplexity --kl-divergence, four repository corpora, -c 4096 -b 512 -ub 512, where qsa_fast_fits accepts the ubatch; base logits saved by master tip cd44688 and compared against master itself and against this PR merged into it):

corpus side PPL mean KLD max / min KLD same top-1
prose master 7.063240 ± 0.211116 0.000000 ± 0.000000 0.000060 / -0.000060 100.000 %
prose PR merged 7.063240 ± 0.211116 0.000000 ± 0.000000 0.000060 / -0.000060 100.000 %
code master 1.769637 ± 0.046214 0.000000 ± 0.000000 0.000056 / -0.000053 100.000 %
code PR merged 1.769637 ± 0.046214 0.000000 ± 0.000000 0.000056 / -0.000053 100.000 %
structured master 1.926031 ± 0.053381 -0.000000 ± 0.000000 0.000054 / -0.000062 100.000 %
structured PR merged 1.926031 ± 0.053381 -0.000000 ± 0.000000 0.000054 / -0.000062 100.000 %
numeric master 1.198478 ± 0.012761 0.000000 ± 0.000000 0.000058 / -0.000052 100.000 %
numeric PR merged 1.198478 ± 0.012761 0.000000 ± 0.000000 0.000058 / -0.000052 100.000 %

PR-vs-master equals master-vs-master to the last digit on every corpus: the ±6e-5 is the precision of the saved base logits, not a difference between the builds. Top-1 agreement 100 % everywhere. (An earlier version of this table ran at -ub 2048, where the fast path is off; replaced after review.)

llama-benchy 0.4.0 (--pp 2048 --tg 128 --depth 0 12000 32000 64000 --runs 4 --no-cache, temperature 0, seed 1, thinking off; against llama-server with the serving flags above, MTP draft on, fresh server per run; run order 1-base / 2-pr / 3-base / 4-pr; client on a laptop over an ssh tunnel, API latency probe 242, 13, 155, 117 ms):

depth metric 1-base 2-pr 3-base 4-pr change vs master (pooled)
0 pp2048 t/s 1047.1 ± 34.3 928.2 ± 13.2 1015.8 ± 18.1 998.8 ± 26.8 -6.6 % (master pooled sd 3 %)
0 tg128 t/s 36.0 ± 2.5 37.4 ± 3.6 37.3 ± 2.9 36.8 ± 2.2 +1.3 % (master pooled sd 8 %)
0 e2e TTFT ms 2201.0 ± 63.8 2220.7 ± 31.3 2173.3 ± 36.3 2169.9 ± 53.7 +0.4 % (master pooled sd 2 %)
12000 pp2048 t/s 1085.0 ± 9.1 1063.2 ± 23.5 1087.6 ± 17.2 1066.9 ± 50.1 -2.0 % (master pooled sd 1 %)
12000 tg128 t/s 33.3 ± 0.8 35.7 ± 3.0 34.3 ± 0.8 39.6 ± 1.5 +11.4 % (master pooled sd 3 %)
12000 e2e TTFT ms 13189.2 ± 109.5 13233.3 ± 297.9 13075.5 ± 204.7 13314.6 ± 646.3 +1.1 % (master pooled sd 1 %)
32000 pp2048 t/s 1094.4 ± 4.3 1080.4 ± 2.5 1090.8 ± 4.6 1086.4 ± 16.7 -0.8 % (master pooled sd 0 %)
32000 tg128 t/s 36.0 ± 4.5 38.1 ± 0.8 41.6 ± 2.6 38.6 ± 3.6 -1.1 % (master pooled sd 12 %)
32000 e2e TTFT ms 31354.6 ± 123.6 31527.6 ± 71.8 31370.6 ± 132.8 31466.1 ± 489.8 +0.4 % (master pooled sd 0 %)
64000 pp2048 t/s 1073.5 ± 2.5 1072.3 ± 5.3 1074.5 ± 6.1 1075.3 ± 2.4 -0.0 % (master pooled sd 0 %)
64000 tg128 t/s 36.5 ± 3.7 33.2 ± 3.0 46.2 ± 16.6 35.8 ± 2.8 -16.4 % (master pooled sd 31 %)
64000 e2e TTFT ms 61769.4 ± 140.2 61609.6 ± 303.7 61629.2 ± 345.8 61543.7 ± 136.6 -0.2 % (master pooled sd 0 %)

pp2048 t/s in llama-benchy is prompt_tokens / (time_to_first_response - API_latency_probe), and the probe is one
/models round trip taken once per run (242 and 155 ms for the two master runs, 13 and 117 ms for the change). The
larger probes shrink the master denominator and inflate its prompt rate at short depth (a tenth of a 2.2 s TTFT at
depth 0); e2e TTFT, the raw wall time to the first token, is the comparable number and is flat at every depth
(-0.2..+1.1 %, master's own spread 0-2 %). tg128 is 128 tokens of speculative decode on a random window of the text,
so its spread (up to 31 % with one 64k master run at 46 t/s) is the draft acceptance varying with the text, not the
builds. The benchy text is the fork's four tests/corpus/correctness-*.txt files concatenated (45k tokens; Project
Gutenberg answered 503 to every request on the day), served from the client machine. The table is included because the
fork asks for it; the fixed-prompt measurements above (identical prompts, master round-to-round spread 0-1 %) are the
evidence for the size of the gain.

Hashes (corpora full sha256; model shards over 4 GB hashed as head+tail 1 MB, as validate.sh does):

dec1127ae75ffa56deea0ac36d6aa7b2558b27bf25fb7c76ad09f70c2ee26045  tests/corpus/correctness-code.txt
d9f08d9470e53ef61cb1a44a85052ec262103ec86065a787e02880678a9f5298  tests/corpus/correctness-numeric.txt
c90398f2e2885f20475fed09f6216768a21d47f8641852b2d58a391a698e0618  tests/corpus/correctness-prose.txt
c21947b360bea62d6ae2daad06a97ca3e9e0ec8127d205123a6f0affafffbf32  tests/corpus/correctness-structured.txt
5ce89370720f8bf90890f439361282104c1aa1482d4013bb9a50923e758e71a4  Qwen3.8-Flash-Next-UD-IQ4_XS-00001-of-00003.gguf (10946624 bytes)
b5591984f512401e3ca81850b30191e87b448c246b2dd4dfeda02d1fb3c23fb4  Qwen3.8-Flash-Next-UD-IQ4_XS-00002-of-00003.gguf (49835229856 bytes, head+tail 1 MB)
42499e733f68968f0f0d21f57c7f43d54d30e1ba17f9450c7bb0715a0317ac37  Qwen3.8-Flash-Next-UD-IQ4_XS-00003-of-00003.gguf (43836407744 bytes, head+tail 1 MB)
5ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6  mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf (2786568256 bytes)

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • This change is Strix Halo specific, or justified by measurements on Strix Halo: measured on gfx1151 / ROCm 10.1
    with the shipped model and serving flags; the code is backend-generic graph construction.
  • AI usage disclosure: AGENT-AUTHORED. Claude (Opus 5.5) wrote the change from a copy log of the verify graph;
    Claude (Fable 5.1) ran the measurements, cut this commit and drafted this description; the owner reviewed and opened it.
  • What was NOT verified: CUDA (NVIDIA) and Vulkan builds (the change is in the model graph code, not a backend). The
    llama-bench and server tables were taken on a build of this exact source plus one unused header member that the
    commit drops; the correctness runs (KLD, ctest) and llama-benchy ran on the commit itself.

🤖 Generated with Claude Code

In the speculative verify graph every fast QSA layer declared its own
members/positions/rows host inputs for the incremental block-selection
cache, and the scheduler uploaded each one with a synchronous copy.
qsa_fill_updates depends only on the ubatch, so the layers were uploading
identical bytes. The first fast layer now owns one set and the others point
at it (owner = false: set_input skips the fill and keeps the per-layer
qsa_commit). An assert checks that the layers agree on prep_blocks.

Assisted-by: Claude Opus 5.5, Claude Fable 5.1
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the model label Dec 2, 2026
@dzannotti dzannotti added in-review We are reviewing. verifying Building and running the PR to verify its claims. and removed in-review We are reviewing. labels Dec 3, 2026

@dzannotti dzannotti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

The change is correct, and we found no blocking issue. With the PR merged into current master, every logit, token, .kld and greedy-decode comparison against master is byte-identical on ROCm and on Vulkan, and the shared inputs are really used. A maintainer approval is still needed, because this is the QSA graph of the qwen4exp model and we could not run the real model here.

Direction

Accept. Three host uploads per graph in place of three per fast layer is a small, local change with no arithmetic effect, and the sharing follows the same pattern as the existing qsa_inps and qsa_k_inp inputs. It does not overlap with #276: #276 does not touch this block and already conflicts with master in the same regions with or without this PR.

Asks

None of these block the merge.

  1. Should fix. src/models/qwen4exp.cpp:1638 says the extra inputs "push the scheduler's input-count split cuts". Current master does not cut a split on the input count: ggml_backend_sched_split_inputs_grow grows the input array instead (since dbadb68). Our scheduler dumps show the same number of splits on master and on the PR, with fewer split inputs on the PR. The saving is one synchronous host-to-device copy per shared input. Please change the comment, and the same sentence in the description.
  2. Should fix. src/llama-memory-hybrid-idx.cpp:1849-1853, the comment in qsa_fast(), still says "the 3 host inputs this path adds per layer moved the scheduler's input-count split cuts". After this PR there are 3 inputs per graph. Keep only the part that is still useful (the old mismatch came from the CUDA residual-mark bug, not from the cache).
  3. Nit. The assert at qwen4exp.cpp:1646 compares two values that both come from n_tokens, so it cannot fail. members (r*prep_blocks) is the tensor that breaks if a fast layer ever has a different r; assert on qsa_fast_inp->members->ne[0] == r*prep_blocks instead. The forward declaration in models.h:14 could also move into llama_model_qwen4exp next to the other QSA inputs.

Correctness

PASS on both backends, for every check that could run. The description's KLD table used -ub 2048, and qsa_fast_fits rejects ubatches above 512 tokens, so that table does not reach the changed code. We therefore ran all comparisons at -ub 512 (and 1, 7 and 64), on a synthetic 8-layer qwen4exp MoE model with 4 QSA layers, in two variants: indexer top-k 16 (block selection active) and top-k 131072.

  • f32 final logits and prompt token IDs on the 4 corpora, and on prose at -ub 1, 7 and 64: byte-identical on ROCm (HIP_LAUNCH_BLOCKING unset and =1) and on Vulkan.
  • .kld files, short (-c 2048, 4 corpora) and long (-c 8192, the 4 corpora joined): byte-identical, PPL identical.
  • 256-token greedy decode: master A/A identical, PR identical to master.
  • The fast path runs: on the top-k 16 model the PR has fewer split inputs than master (ROCm 1300 vs 1354, Vulkan 1142 vs 1214 over the same graphs) and the same number of splits.
  • test-llama-archs -a qwen4exp, --mtp-cache-only, --qwen4exp-merged, test-qsa-fast, test-qsa-recover, test-qsa-prefix, test-spec-mtp-pcum, test-draft-vocab: pass on both sides and both backends.

Performance

We could not reproduce the decode gain on the target model. As a regression check only, we ran llama-bench on the synthetic model (top-k 16, 8 layers), 2 rounds of master and PR alternated, -r 5. On this model the host inputs are a large share of the decode step, so the gains overstate what a real model sees. Prefill is flat within the spread on both backends.

synthetic qwen4exp, t/s (mean of 2 rounds) master PR stddev per run gain
ROCm tg128 @ d0 358.3 368.5 1.1-1.4 +2.8 %
ROCm tg128 @ d3000 336.3 344.2 0.5-1.8 +2.3 %
ROCm pp512 @ d3000 23215 23287 1155-1262 +0.3 %
Vulkan tg128 @ d0 615.4 619.3 0.8-4.4 +0.6 %
Vulkan tg128 @ d3000 580.9 580.7 1.9-3.5 -0.0 %
Vulkan pp512 @ d3000 25321 25427 1296-1575 +0.4 %

Verification

Strix Halo (gfx1151), ROCm 10.1 and Vulkan (RADV). We compared the PR merged into master 8707b3a91 (9 commits behind, clean merge) against that master.

Not tested

The real Qwen3.8-Flash-Next model (the smallest official GGUF is larger than we can run for a review), so the decode gain, MTP speculative decoding and draft acceptance were not reproduced; the synthetic model also uses the masked top-k attention, not the selected-key kernels. CUDA was not tested.

Thank you for the clear write-up and the measured split of the two hunks.

Review made with AI on behalf of the strix-llama.cpp maintainers.

Full verification (for reproduction and agents)

Environment

  • Ubuntu 26.04.1, Linux 7.0.0-44-generic, Strix Halo (Radeon 8060S, gfx1151), 128 GB unified memory.
  • ROCm 10.1: hipconfig 7.16.26385, AMD clang 24.0.0git d6f6cb69.
  • Mesa 26.0.8 (RADV STRIX_HALO), glslc shaderc 2026.1.
  • gcc 15.2.0, cmake 4.2.3, Ninja.

Compared

  • master tip: 8707b3a915b51f614de48061622f3da118d43d4f
  • PR head: 310a41be8e589de4a2a47a93432c5ffe9514fd9c
  • merged (local only, not pushed): 0e7114ab1, the PR head merged into the master tip, clean merge
  • merge base: dc5521842, 9 commits behind master. The merged diff against master is the PR diff at shifted line numbers.

Build

ROCm:   cmake -S <tree> -B <tree>/build-hip -G Ninja -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 -S <tree> -B <tree>/build-vk  -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON -DGGML_HIP=OFF
targets: test-llama-archs test-llama-context llama-perplexity llama-tokenize llama-bench llama-server llama-debug llama-completion test-qsa-fast test-qsa-recover test-qsa-prefix test-spec-mtp-pcum test-draft-vocab

Models

No real qwen4exp model was used. We generated two synthetic qwen4exp MoE models with test-llama-archs -a qwen4exp -s 1234 -o <dir> on master, with a local change to the generator only: 8 layers (n_layer_min 8, so 4 QSA layers with compress ratio 4 and full-attention interval 2), and the indexer top-k set to 16 or left at the default 131072. With top-k 131072 the incremental cache does not take the fast path, so that model is a control.

3e34493ef87f6965a61965134abefb9af3439f87119d4a3a6b63b649a900bb06  qwen4exp-moe.gguf (top-k 16, 71502624 bytes)
7480a8fb190317a4306106f0ba1f6874f0711090910a548fef3120ca5ad81076  qwen4exp-moe.gguf (top-k 131072, 71502624 bytes)
dec1127ae75ffa56deea0ac36d6aa7b2558b27bf25fb7c76ad09f70c2ee26045  tests/corpus/correctness-code.txt
d9f08d9470e53ef61cb1a44a85052ec262103ec86065a787e02880678a9f5298  tests/corpus/correctness-numeric.txt
c90398f2e2885f20475fed09f6216768a21d47f8641852b2d58a391a698e0618  tests/corpus/correctness-prose.txt
c21947b360bea62d6ae2daad06a97ca3e9e0ec8127d205123a6f0affafffbf32  tests/corpus/correctness-structured.txt

Token counts with this vocab: code 7490, numeric 6273, prose 10547, structured 4840, the 4 joined 29154.

Commands

Per backend (<dev> ROCm0 or Vulkan0), per side (master, merged), per model. ROCm ran everything with HIP_LAUNCH_BLOCKING unset, and the llama-debug and decode checks again with HIP_LAUNCH_BLOCKING=1.

test-llama-archs -a qwen4exp -b <dev>
test-llama-archs --mtp-cache-only -s 1234
test-llama-archs --qwen4exp-merged -s 1234
test-qsa-fast; test-qsa-recover; test-qsa-prefix; test-spec-mtp-pcum; test-draft-vocab
GGML_SCHED_DEBUG=1 llama-completion -m <model> -f correctness-prose.txt -n 4 --temp 0 --seed 1 -no-cnv --ignore-eos -ngl 99 -fa on -ctk f16 -ctv f16 -c 4096 -ub 512 -v
llama-debug -m <model> -f correctness-<t>.txt -c 16384 -b 16384 -ub 512 -ngl 99 -fa on -ctk f16 -ctv f16 --save-logits --logits-output-dir <dir>
llama-debug -m <model> -f <first 6000 bytes of prose> -c 4096 -b 4096 -ub {1,7,64} <same flags> --save-logits --logits-output-dir <dir>
cmp <base>/llamacpp-*.bin <head>/llamacpp-*.bin     (logits and tokens)
llama-perplexity -m <model> -f correctness-<t>.txt -c 2048 -b 2048 -ub 512 <same flags> --kl-divergence-base <side>-<t>.kld
llama-perplexity -m <model> -f <4 corpora joined> -c 8192 -b 512 -ub 512 <same flags> --kl-divergence-base <side>-long.kld
llama-perplexity (head) <same args, no -f> --kl-divergence-base base-<t>.kld --kl-divergence
llama-completion -m <model> -f correctness-prose.txt -n 256 --temp 0 --seed 1 -no-cnv --ignore-eos <same flags> -c 16384 -ub 512   (master twice, head once)
llama-bench -m <top-k 16 model> -p 512 -n 128 -d 0,3000 -b 512 -ub 512 -r 5 -ngl 99 -fa on -ctk f16 -ctv f16 --load-mode none -o jsonl   (master, head, master, head)

The long KLD uses -c 8192. The joined corpora give 29154 tokens with this vocab, fewer than the 32768 that -c 16384 needs.

Correctness

check method result
test-llama-archs qwen4exp -a qwen4exp -b <dev>, both sides OK on ROCm and Vulkan, both sides
qwen4exp MTP cache-only, merged weights --mtp-cache-only, --qwen4exp-merged PASS, both sides and backends
QSA and spec unit tests test-qsa-fast/recover/prefix, test-spec-mtp-pcum, test-draft-vocab PASS, both sides and backends
fast path taken GGML_SCHED_DEBUG=1, same 46 graphs top-k 16: split inputs ROCm 1354 to 1300, Vulkan 1214 to 1142; splits 380 = 380 and 126 = 126. Top-k 131072: unchanged (control)
f32 final logits and prompt token IDs llama-debug and cmp, 4 corpora at -ub 512, prose at -ub 1/7/64 byte-identical, 14 cmp pairs per backend and model; ROCm also with HIP_LAUNCH_BLOCKING=1
KLD/PPL short .kld cmp, -c 2048 -ub 512, 4 corpora .kld byte-identical, PPL identical (127.9545, 127.3842, 128.0738, 128.1932)
KLD/PPL long .kld cmp, -c 8192 -ub 512, joined .kld byte-identical, PPL 127.9010 on both
greedy decode 256 tokens, master A/A, head identical on all runs, both models, both backends, ROCm HIP_LAUNCH_BLOCKING unset and =1
test-llama-context none not run: no KV or state code changed
real-model parity, MTP acceptance none not run: no real qwen4exp model (see Not tested)

Same top p reads 99.967 % on the numeric corpus with top-k 16 for the PR against master, and the same 99.967 % for master against master. It comes from ties in the 16-bit stored log-probs of the synthetic model, not from a difference: the .kld files are byte-identical.

Performance

Raw llama-bench results, avg_ts / stddev_ts in t/s, rounds 1 and 2:

backend test master r1 master r2 PR r1 PR r2
ROCm pp512 d0 47141.6 / 514.3 46486.0 / 416.1 46058.5 / 639.1 45536.6 / 1283.5
ROCm tg128 d0 358.2 / 1.1 358.4 / 1.2 368.3 / 1.4 368.6 / 1.1
ROCm pp512 d3000 23103.4 / 1261.8 23326.8 / 1181.2 23316.8 / 1155.4 23256.9 / 1175.5
ROCm tg128 d3000 336.2 / 1.1 336.4 / 0.5 344.6 / 1.1 343.8 / 1.8
Vulkan pp512 d0 59107.4 / 3148.5 60544.3 / 823.6 60217.5 / 1085.0 59411.6 / 547.9
Vulkan tg128 d0 617.1 / 0.8 613.6 / 4.4 619.0 / 3.5 619.6 / 3.3
Vulkan pp512 d3000 25416.5 / 1549.1 25225.0 / 1574.6 25574.5 / 1296.5 25280.2 / 1494.2
Vulkan tg128 d3000 580.9 / 2.7 580.9 / 2.7 580.7 / 3.5 580.7 / 1.9

ROCm pp512 at d0 is 1.6 % lower on the PR, inside the per-run stddev (416-1284 t/s, about 1-3 %).

Findings in full

  1. Should fix, comment. src/models/qwen4exp.cpp:1637-1638. On master, ggml_backend_sched_split_graph starts a new split only on a backend change or on a weight buffer that the backend cannot use. When a split has more inputs than its array holds, ggml_backend_sched_split_inputs_grow grows the array. The scheduler copies each input once per (input, backend) per graph, so sharing the tensors saves the extra synchronous copies, not split cuts. Our dumps agree: the same split count, fewer inputs.
  2. Should fix, comment. src/llama-memory-hybrid-idx.cpp:1849-1853 repeats the "3 host inputs per layer" and "split cuts" text, which this PR makes wrong.
  3. Nit. qwen4exp.cpp:1646: rows->ne[0] and prep_blocks both come from n_tokens. An assert on members->ne[0] == r*prep_blocks would catch a future fast layer with a different r (storage is gated on r == 4 today).
  4. Nit. models.h:14 declares llm_graph_input_qsa_cache at global scope. The sibling QSA inputs are declared inside llama_model_qwen4exp.
  5. Checked, no finding. qsa_fill_updates reads only qsa_prefix and the row count, never the layer, qsa_ready or qsa_keys. qsa_commit(il) writes only qsa_ready[il], so the order of the set_input calls does not matter. qsa_fast_inp is a member of the per-build graph object, so each build starts with no owner. Graph reuse calls can_reuse on every input, so the owner's context is refreshed before it fills. The graph result owns the heap-allocated owner object, and the other layers keep only the tensor pointers.
  6. Description evidence. The KLD table used -ub 2048, pp2048 used -ub 1024, and test-qwen4exp-mtp-cache-only uses large ubatches. qsa_fast_fits rejects ubatches above 512 tokens, so those runs do not reach the changed code. The server greedy hashes and the decode runs do.

Claims

  • "No arithmetic changes, greedy outputs byte-identical, logits identical": reproduced on the synthetic model on ROCm and Vulkan, at ubatch sizes that take the fast path. Not reproduced on the real model.
  • "+1.8 % tg128 at depth, about +1 % server decode with MTP": not reproduced (no real model). The synthetic model shows +2.3 to +2.8 % tg on ROCm and no change on Vulkan. The direction matches, but the workload is not the same.
  • "No measurable prefill cost": our data agrees, within the spread on both backends.
  • "The inputs push the scheduler's split cuts": not reproduced. The split count does not change (finding 1).
  • "Draft acceptance unchanged": not tested.
  • "--parallel 2 behaves as master": not tested. By reading, storage needs n_stream == 1, so split KV streams do not reach this code.

Not tested

  • The real Qwen3.8-Flash-Next model. The smallest official GGUF is over our download and memory budget for a review. So there are no real-model logits, KLD, MTP speculative decoding, draft acceptance or depth sweep up to 64000.
  • The selected-key (maskless) QSA kernels. The synthetic model's head size takes the masked top-k path. The changed code runs before the attention and is the same on both paths.
  • CUDA, --parallel 2, and the server pytest suite (not installed here).

@dzannotti dzannotti added needs-human Review done; a maintainer must approve. risk:medium Risk: medium and removed verifying Building and running the PR to verify its claims. labels Dec 3, 2026
@dzannotti dzannotti self-assigned this Dec 3, 2026
@dzannotti

Copy link
Copy Markdown
Collaborator

Status from the maintainers: the change is correct in our checks, but we cannot accept it on the speed claim yet. We could not run Qwen3.8-Flash-Next, so the +1.8% decode gain is unchecked, and the KLD table in the description ran at ubatch 2048, where the changed code does not run.

Could you add a base-vs-head llama-bench on Flash-Next (same build flags, alternated runs, at least 3 repetitions, -d 0,12000,32000, tg and pp at ubatch 512 or less) with the environment block (GPU, driver, backend, commit SHAs)? With that we can re-check and move it forward.

Review made with AI on behalf of the strix-llama.cpp maintainers.

@dzannotti dzannotti added waiting-user We asked the author for something. and removed needs-human Review done; a maintainer must approve. labels Dec 3, 2026
@dzannotti dzannotti assigned neavra and unassigned dzannotti Dec 3, 2026
- The comment claimed the per-layer inputs "push the scheduler's input-count
  split cuts". The scheduler grows the split's input array instead; what the
  sharing saves is one synchronous host-to-device copy per input per graph.
  Reworded here and trimmed the matching sentence in qsa_fast().
- The assert compared two values derived from n_tokens; assert on the
  members tensor instead so a fast layer with a different r is caught.
- llm_graph_input_qsa_cache is declared inside llama_model_qwen4exp next to
  the other QSA inputs.

No arithmetic changes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@neavra

neavra commented Dec 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review. Follow-up commit 970e5f4 addresses the three items:

  1. The comment in qwen4exp.cpp and the qsa_fast() comment in llama-memory-hybrid-idx.cpp no longer talk about split
    cuts. Your reading is right: the scheduler grows the split's input array, and what the sharing saves is one synchronous
    host-to-device copy per input per graph. The description's Overview says the same now.
  2. The assert is on members->ne[0] == r*prep_blocks, so a fast layer with a different r is caught instead of comparing
    two values derived from n_tokens.
  3. llm_graph_input_qsa_cache is declared inside llama_model_qwen4exp next to llm_graph_input_qsa and
    llm_graph_input_qsa_k, and defined as llama_model_qwen4exp::llm_graph_input_qsa_cache.

On the evidence: you are right that the KLD table ran where qsa_fast_fits rejects the ubatch. Both tables below were
re-run at ubatch 512 on master tip cd44688 vs this PR merged into it, same build flags on both sides.

Device:     Ryzen AI Max+ 395 / GMKtec EVO-X2, 128 GB LPDDR5X-8000, BIOS UMA 2 GB
OS/Kernel:  Ubuntu 26.04.1, 7.0.0-44-generic
Backend:    ROCm 10.1 (HIP), gfx1151, HSA_OVERRIDE_GFX_VERSION=11.5.1; hipcc clang 24
Build:      -DGGML_HIP=ON -DGPU_TARGETS=gfx1151 -DCMAKE_BUILD_TYPE=Release
Sides:      master cd4468885; master cd4468885 + this PR (310a41be8 + 970e5f4c0) merged locally
Weights:    unsloth/Qwen3.8-Flash-Next-GGUF UD-IQ4_XS (no draft model in llama-bench)

llama-bench -p 512 -n 128 -d 0,12000,32000 -b 512 -ub 512 -r 3 -ngl 999 -fa on -ctk f16 -ctv f16 --load-mode none,
three alternated rounds (master, PR, master, PR, master, PR), mean ± sd of the three round means:

test depth master cd44688 PR merged change
pp512 0 1286.6 ± 4.6 (1285.4, 1282.7, 1291.7) 1280.4 ± 1.5 (1282.1, 1279.2, 1279.9) -0.5 %
pp512 12000 969.4 ± 2.8 (972.6, 967.9, 967.7) 970.5 ± 6.7 (976.0, 972.3, 963.1) +0.1 %
pp512 32000 977.1 ± 6.9 (984.2, 976.5, 970.5) 977.6 ± 3.0 (980.8, 974.7, 977.3) +0.1 %
tg128 0 28.9 ± 0.2 (28.7, 29.0, 29.0) 29.0 ± 0.0 (29.0, 29.0, 29.0) +0.3 %
tg128 12000 26.8 ± 0.2 (26.6, 26.9, 26.9) 27.2 ± 0.0 (27.2, 27.2, 27.2) +1.5 %
tg128 32000 26.5 ± 0.2 (26.4, 26.6, 26.6) 26.9 ± 0.0 (27.0, 26.9, 26.9) +1.5 %

Same picture as the ub1024 table in the description: tg gains at depth, pp flat inside the per-run sd.

llama-perplexity --kl-divergence, four repository corpora, -c 4096 -b 512 -ub 512, base logits saved by master:

corpus side PPL mean KLD max / min KLD same top-1
prose master 7.063240 ± 0.211116 0.000000 ± 0.000000 0.000060 / -0.000060 100.000 %
prose PR merged 7.063240 ± 0.211116 0.000000 ± 0.000000 0.000060 / -0.000060 100.000 %
code master 1.769637 ± 0.046214 0.000000 ± 0.000000 0.000056 / -0.000053 100.000 %
code PR merged 1.769637 ± 0.046214 0.000000 ± 0.000000 0.000056 / -0.000053 100.000 %
structured master 1.926031 ± 0.053381 -0.000000 ± 0.000000 0.000054 / -0.000062 100.000 %
structured PR merged 1.926031 ± 0.053381 -0.000000 ± 0.000000 0.000054 / -0.000062 100.000 %
numeric master 1.198478 ± 0.012761 0.000000 ± 0.000000 0.000058 / -0.000052 100.000 %
numeric PR merged 1.198478 ± 0.012761 0.000000 ± 0.000000 0.000058 / -0.000052 100.000 %

PR-vs-master equals master-vs-master to the last digit on every corpus; the ±6e-5 is the precision of the saved base logits. The description's KLD table is replaced by this one.

Review made with AI on my behalf (Claude Fable 5.1); the runs were on my box.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model risk:medium Risk: medium waiting-user We asked the author for something.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants