Skip to content

spec : MTP draft vocab subset for qwen4exp and shared MTP sidecars - #253

Closed
Nathanw1014 wants to merge 2 commits into
masterfrom
hb/mtp-draft-vocab
Closed

Nathanw1014 wants to merge 2 commits into
masterfrom
hb/mtp-draft-vocab

Conversation

@Nathanw1014

Copy link
Copy Markdown

Overview

--spec-draft-mtp-vocab N scores each drafted token against the first N rows of the LM head instead of all 248k. It was accepted for qwen35 / qwen35moe only, so on a Qwen3.8-Flash-Next (qwen4exp) MTP draft the flag did nothing, and on a shared, head-less sidecar (Unsloth's mtp-Qwen3.8-Flash-Next-shared-*.gguf) the subset could not be built at all because the draft has no output.weight. This PR enables it for both. The target model, the verify step and token ids are unchanged; only the draft's head matmul gets smaller.

  • qwen4exp draft-head row subset (gaetan-puleo). mtp_draft_vocab_get accepts qwen4exp, and graph_mtp scores the draft on the row subset and scatters the logits into a full-vocab -inf row, as qwen35moe does. No file or weight change.
  • Head-less (shared) sidecars. mtp_draft_vocab_get takes the subset rows from the target's LM head when the draft has none (shape checked; warns when there is neither), and graph_mtp uses the subset whenever the block scores with the model LM head, own or borrowed, not only with its own.

Decode with --spec-draft-mtp-vocab 94208, MTP n3, 256 greedy tokens: +7.5% code, +9.2% prose, +7.2% reasoning on Vulkan, +5.8% code on ROCm. Prefill is unchanged.

Measurements

Device AMD Ryzen AI Max+ 395, Radeon 8060S (gfx1151), GMKtec EVO-X2
Memory 128 GB
Power firmware default (no platform_profile)
BIOS UMA 2 GB
Kernel 6.17.0-35-generic, amdgpu.gttsize=118784 ttm.pages_limit=30408704 ttm.page_pool_size=1048576 amd_iommu=off
Backend Vulkan, RADV, Mesa 26.2.4 (release tag, unmodified); ROCm TheRock 10.3.0a20261026 for the HIP rows
Build Vulkan -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON -DGGML_NATIVE=OFF -DLLAMA_BUILD_TESTS=ON, shaderc glslc; HIP -DGGML_HIP=ON -DGPU_TARGETS=gfx1151 -DGGML_HIP_ROCWMMA_FATTN=OFF
Baseline master ea5285d (merge-base), separate source and build dir
Change ede6d5b
Model Qwen3.8-Flash-Next UD-Q4_K_XL (unsloth) + mtp-Qwen3.8-Flash-Next-Q8_0.gguf (unsloth, own head); shared rows with mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf

Server, both arms (a fresh server per cell, master / PR / PR / master, the same flag on master where it is ignored for qwen4exp):

llama-server -m Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf -ngl 99 -fa on -ctk f16 -ctv f16 -lm none -lzm on-direct -np 1 -c 8192 -b 1024 -ub 1024 -md mtp-Qwen3.8-Flash-Next-Q8_0.gguf -ngld 99 --spec-type draft-mtp --spec-draft-mtp-vocab 94208 --spec-draft-n-max 3

Requests: /completion, temperature 0, top_k 1, cache_prompt false, ignore_eos, 256 tokens, one 32-token warmup per server, three prompts (code, prose, reasoning) x 3 reps per server, 2 servers per arm (6 requests per prompt and arm). t/s is the server's predicted_per_second.

prompt n master t/s this PR t/s change accepted / drafted, master this PR
code 3 47.04 [46.25-48.52] 50.55 [49.76-52.11] +7.5% 1086 / 1314 1080 / 1332
prose 3 29.39 [29.31-29.50] 32.08 [31.88-32.44] +9.2% 822 / 2118 822 / 2118
reasoning 3 47.66 [47.08-48.17] 51.10 [50.66-51.45] +7.2% 1104 / 1272 1098 / 1296
code 1 39.18 [38.43-40.42] 40.59 [39.91-41.81] +3.6% 750 / 780 744 / 786
prose 1 33.73 [33.53-33.84] 35.21 [34.82-35.47] +4.4% 630 / 894 630 / 894
reasoning 1 38.17 [37.76-38.45] 39.52 [38.94-39.94] +3.5% 744 / 786 738 / 792

Other cells (n3, 2 reps x prompt per server, one server per arm):

cell master this PR change
shared sidecar, code / prose / reasoning 47.55 / 29.49 / 47.81 50.94 / 32.23 / 50.90 +7.1 / +9.3 / +6.5%
1024 tokens, code / prose 49.65 / 31.97 53.69 / 34.71 +8.1 / +8.6%
ROCm, code 41.59 44.00 +5.8%
pp with the draft loaded, 2048 / 8192 / 32768 (client t/s, 4 servers x 2 reps per arm) 1058.62 / 1058.80 / 1070.39 1053.30 / 1059.56 / 1070.01 -0.5 / +0.1 / -0.0%

Correctness

  • Full test-backend-ops -b Vulkan0: 43840/43840 on this PR and on master (no ggml change).
  • Every stream is run-to-run identical within an arm (one sha per prompt over the 6 requests, also across the two servers).
  • Code and prose streams are identical to master at n1 and n3, including the 1024-token runs and ROCm. Reasoning differs from master at n3 and on the shared sidecar (sha 940da1c8 vs 427169d3): with the subset the draft proposes different tokens, so the verify batches take other widths, and Vulkan verify numerics depend on the batch width. Acceptance stays within 1% of master.
  • No MTP: AR streams on all three prompts are identical to master on Vulkan and ROCm.
  • Verdict: TARGET PASS, GLOBAL PASS.

Requirements

  • AI usage: ASSISTED. Written with Claude, tested by me.
  • Not verified: other GPUs than gfx1151; drivers other than RADV 26.2.4; subset sizes other than 94208; llama-benchy at depth (the cells above use a plain /completion client); more than one sequence (-np 1 only).

gaetan-puleo and others added 2 commits November 5, 2026 07:50
--spec-draft-mtp-vocab was accepted for qwen35/qwen35moe only, so on a
qwen4exp MTP sidecar the flag was silently ignored and every drafted token
was scored against the full 248k-row Q6_K LM head.

Allow LLM_ARCH_QWEN4EXP in mtp_draft_vocab_get and add the row-subset head
branch to graph_mtp, mirroring qwen35moe: score build_lora_mm on the runtime
subset (rows copied from the existing head at load - no file or weight change)
and scatter its logits into a full-vocab -inf row, so token ids and the
verification path stay unchanged.

Measured on Qwen3.8-Flash-Next UD-IQ4_XS + mtp-...-Q4_K_M sidecar, 128
greedy tokens, same-session A/B: 38.0 -> 41.5 t/s at N=65536 (+8%), identical
output and acceptance. N=131072 is slower than the control; N=32768/16384 are
about equal with a small acceptance loss. With the subset the draft phase is
340 ms of ~3.4 s and the target verify is the remainder.
A shared qwen4exp MTP sidecar (nextn_shared_target_tensors, e.g. Unsloth's
mtp-Qwen3.8-Flash-Next-shared-*.gguf) has no output.weight: graph_mtp borrows
the target's LM head through ctx_other. Two places made --spec-draft-mtp-vocab
a silent no-op on these files:

- llama_model::mtp_draft_vocab_get() returned nullptr when the draft had no
  output tensor. It now takes the subset rows from the target's LM head
  (shape checked) and warns when there is neither a head nor a target.
- the qwen4exp MTP graph used the subset only when head_w == model.output.
  It now uses it whenever the block scores with the model LM head, own or
  borrowed (not with a shared_head_head), and sizes the -inf row from head_w.

Assisted-by: Claude Opus 5.5
@github-actions github-actions Bot added the model label Nov 5, 2026
@dzannotti dzannotti mentioned this pull request Nov 10, 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 Nov 11, 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

This change does what it says. On both backends the target output is byte-identical to master, and acceptance does not change. With --spec-draft-mtp-vocab 94208, a qwen4exp MTP draft decodes 6-8% faster. A maintainer must approve it because it is speculative-decoding code. The asks below are small and none of them blocks the merge.

Direction

Accept. The flag is off by default, the diff is small and lives only in fork-local code, and the gain is real on both the own-head sidecar and the shared (head-less) sidecar. This PR replaces the first commit of the closed #108.

Asks

  1. Should fix. src/llama-model.cpp:1273 and :2822: the subset cache on the draft model has the key (n_keep, buft). With a borrowed head, the rows come from the target's output. So if one draft model serves two targets, the second context gets the first target's rows (wrong drafts, or the type assert in qwen4exp.cpp:593). No in-tree tool can do this today, but the fix is one line: add the source tensor to the key, std::tuple<int32_t, ggml_backend_buffer_type_t, const ggml_tensor *>, built with std::make_tuple(n_keep, buft, out).
  2. Should fix. src/llama-model.cpp:2781: the subset head is a new tensor, so hdmd.rot (keyed by tensor pointer) has no entry for it. If output.weight is Hadamard-rotated (prism allows that for qwen4exp), build_lora_mm skips the input rotation and the drafts are wrong. Output stays correct, but acceptance collapses. qwen35 already has this gap. Before this PR, qwen4exp files could not reach it, because the subset was rejected for qwen4exp. Return nullptr when the model that owns out (this model, or head_src) has out in hdmd.rot. The published Gyro files rotate only the expert FFN weights, so they are not affected.
  3. Should fix. tests/test-mtp-draft-vocab.cpp:1-13: the test loads one model and sets no ctx_other, so it cannot reach the borrowed-head path, and its header still says qwen35/qwen35moe only. Add a mode that loads a draft with -md and passes the target as ctx_other, and update the header.
  4. Should fix. Commit 086c701 has no Assisted-by: trailer. The PR says AI usage is ASSISTED. If that commit was AI-assisted too, add the trailer.

Nits: the "no LM head and no target to borrow one from" warning (llama-model.cpp:2797-2799) cannot fire, because the context constructor throws first, so delete it. The shape check at :2789-2793 repeats the check in qwen4exp_shared_model, and context creation then fails on that check anyway. The new comments at llama-model.cpp:2785-2786 and qwen4exp.cpp:590-591 are hard-wrapped, which AGENTS.md asks you to avoid. The subset block now has three copies (qwen35, qwen35moe, qwen4exp), so a shared helper would be a good follow-up.

Correctness

PASS on Vulkan and ROCm. The target graph does not change. On a qwen4exp target and on a qwen35 27B target, llama-debug f32 final logits and prompt token IDs are byte-identical base vs head on all four corpora. The .kld files are byte-identical too (short -c 2048 and long -c 16384), and so are PPL and the 256-token greedy decodes (base A/A equal). On ROCm, llama-debug parity and the spec greedy runs give the same result with HIP_LAUNCH_BLOCKING unset and =1. Spec decode: every server stream has the same sha and the same accepted/drafted count in all four cells (base/head, flag off/on), so the subset changes only speed. ctest -L main, test-llama-archs (all archs, and qwen4exp alone), the spec ctests and test-mtp-draft-vocab give the same results on both sides. Full test-backend-ops was not needed, because nothing under ggml/ changed.

Performance

Decode t/s, MTP n3, 256 greedy tokens, mean of 6 requests per cell (base/head/head/base servers). Base is master with the same flag, where it does nothing for qwen4exp. Prefill (prompt_per_second) moves less than 1% in every cell.

backend sidecar code prose reasoning base spread
Vulkan shared Q4_K_M 54.90 -> 59.39 (+8.2%) 46.65 -> 50.48 (+8.2%) 53.76 -> 58.17 (+8.2%) <= 0.5% sd
Vulkan own-head Q4_K_M 57.38 -> 60.90 (+6.1%) 44.89 -> 47.68 (+6.2%) 53.97 -> 57.33 (+6.2%) <= 0.5% sd
ROCm shared Q4_K_M 50.60 -> 54.62 (+8.0%) 42.80 -> 46.25 (+8.1%) 45.71 -> 49.28 (+7.8%) <= 1.0% sd
ROCm own-head Q4_K_M 51.44 -> 54.85 (+6.6%) 43.47 -> 46.23 (+6.4%) 46.36 -> 49.31 (+6.4%) <= 1.8% sd

With the flag on, depth runs (bench-spec-prefill shape) show the gain holds at 9k, 28k and 60k tokens of context on Vulkan (+5.8% to +7.8%), and TTFT is unchanged. With its own MTP head, the qwen35 27B gives the same speed on base and head (within 0.2%), with the flag and without it.

Verification

Strix Halo (gfx1151), Vulkan (RADV) and ROCm. We compared this PR merged into master 0c1021e (52 commits behind, clean merge) against master. Target: Qwen3.8-Flash-Next Gyro-M TQ2_0 with the Unsloth mtp-Qwen3.8-Flash-Next-shared-Q4_K_M and mtp-Qwen3.8-Flash-Next-Q4_K_M sidecars, plus Qwen3.8-27B UD-Q4_K_XL with its own MTP head.

Not tested

Your exact files (UD-Q4_K_XL with Q8_0 sidecars); ROCm at depth 64000; -np > 1 with the subset (the graph uses the full head when more than one output is drafted); GPUs other than gfx1151.

Thanks for the clear write-up and the shared-sidecar fix.

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

Full verification (for reproduction and agents)

Environment

  • Linux 7.0.0-43-generic, Ubuntu; gcc 15.2.0; cmake 4.2.3; Ninja.
  • ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb691863.
  • Mesa 26.0.8 RADV (Radeon 8060S, RADV STRIX_HALO).

Compared

  • master tip: 0c1021e
  • PR head: ede6d5b
  • merged (PR into master tip, local only, not pushed): e21f2ea57ab86f504675075dc6d9921c4d86a874
  • merge base: ea5285d; the PR was 52 commits behind master. Merge clean; git diff origin/master HEAD in the merged tree touches only the four PR files and is equal to the PR diff. git diff origin/master HEAD -- ggml common tools is empty.

Build

Identical per backend for base and merged, each in its own tree:

cmake -G Ninja -S <tree> -B <tree>/build-vk -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=ON -DGGML_VULKAN=ON -DGGML_HIP=OFF
cmake -G Ninja -S <tree> -B <tree>/build-hip -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=ON -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R)
cmake --build <tree>/build-<be> -j

No new warning in the changed files.

Models

model repo / file sha256
qwen4exp target agentionai/Qwen3.8-Flash-Next-Gyro-GGUF, Qwen3.8-Flash-Next-Gyro-M-TQ2_0.gguf (output.weight Q8_0, Hadamard on ffn_*_exps only) 7aa36d15131d255179ab6c87fa9c9f81a0b541fc9e81e959d4c3e29eb20feb5f
shared sidecar (no output/token_embd) unsloth/Qwen3.8-Flash-Next-GGUF, MTP/mtp-Qwen3.8-Flash-Next-shared-Q4_K_M.gguf f521868a9e143718bef513772f6e04d9642551e362cf2439636d2abdbd149dfc
own-head sidecar (output.weight Q6_K) unsloth/Qwen3.8-Flash-Next-GGUF, MTP/mtp-Qwen3.8-Flash-Next-Q4_K_M.gguf 8087dbb39fc73f79ac069b1debe4069a44b73ada900c8bd761569d43a5a90231
qwen35 target with MTP head unsloth Qwen3.8-27B-UD-Q4_K_XL.gguf 3f227079003add2511437e5b1e94812e363385225bf6a9b47b0054a72bc8b01e

Gyro-M loads with -lm none -lzm on-direct. On Vulkan, --lazy-mode on lost the device at load on master too, so it is not related to this PR.

Commands

  • Suites: ctest --test-dir <build> --output-on-failure -L main -E 'test-opt|test-llama-archs'; test-llama-archs -b <dev> and -a qwen4exp; ctest -R 'spec-mtp-pcum|draft-vocab|qwen4exp-mtp'; test-mtp-draft-vocab -m <27B> -ngl 99.
  • Logits: llama-debug -m <model> [-lm none -lzm on-direct] -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>, then cmp of the logits .bin, tokens.bin and prompt files.
  • KLD/PPL: llama-perplexity -m <model> -f <corpus> -c 2048 -b 2048 -ub 2048 -ngl 99 -fa on -ctk f16 -ctv f16 --kl-divergence-base <side>-<t>.kld per corpus; long: the four corpora joined, -c 16384 -b 512 -ub 512; cmp of the .kld files.
  • Greedy decode: llama-completion -m <model> -f <corpus> -n 256 --temp 0 --seed 1 -no-cnv --ignore-eos -ngl 99 -fa on -c 16384, base twice, then head.
  • Spec server: llama-server -m <target> [-lm none -lzm on-direct] [-md <sidecar>] -ngl 99 -ngld 99 -fa on -ctk f16 -ctv f16 -c 8192 -np 1 --spec-type draft-mtp --spec-draft-n-max 3 [--spec-draft-mtp-vocab 94208] (the 27B uses its own nextn head, no -md). Client: /completion, temperature 0, top_k 1, cache_prompt false, ignore_eos, n_predict 256, one 32-token warmup per server, 3 reps x 3 prompts per server, 4 servers per arm in the order base/head/head/base (n=6 per side and cell). Prompts: the first 6000 bytes of correctness-code.txt and correctness-prose.txt, and a short word problem for reasoning.
  • Depth: scripts/bench-spec-prefill.sh (from master) with -c 70000 and the flag on, base/head/head/base. Prompts of 9, 9064, 28383 and 59944 tokens, cut from the joined corpora. The script passes the prompt with curl -d and fails above about 128 KB, so the 28k and 60k runs used a client that sends the same request.
  • ROCm: all of the above with HIP_LAUNCH_BLOCKING unset. With =1: llama-debug parity on both targets and one server per side for the spec arms.

Results

Spec decode, decode t/s mean +- sd [min-max], n=6. "off" means no flag; "on" means --spec-draft-mtp-vocab 94208.

Vulkan:

arm prompt base off head off base on head on head on vs base on accepted/drafted per request (all 4 cells) sha (all 4 cells)
shared code 54.78 +- 0.28 [54.41-55.00] 54.80 +- 0.14 54.90 +- 0.08 59.39 +- 0.23 [58.99-59.65] +8.2% 186/207 2c390aa46019
shared prose 46.49 +- 0.25 46.56 +- 0.06 46.65 +- 0.12 50.48 +- 0.29 +8.2% 173/246 71470bb0757a
shared reasoning 53.56 +- 0.33 53.70 +- 0.12 53.76 +- 0.12 58.17 +- 0.31 +8.2% 184/210 16af9e3e7943
own head code 57.30 +- 0.26 57.40 +- 0.14 57.38 +- 0.13 60.90 +- 0.25 +6.1% 187/204 2c390aa46019
own head prose 44.76 +- 0.30 44.89 +- 0.08 44.89 +- 0.11 47.68 +- 0.25 +6.2% 167/262 24b6fb25add9
own head reasoning 53.81 +- 0.36 53.94 +- 0.10 53.97 +- 0.12 57.33 +- 0.29 +6.2% 182/216 16af9e3e7943
qwen35 27B code 32.94 +- 0.03 32.94 +- 0.03 35.64 +- 0.02 35.56 +- 0.17 -0.2% 187/202 568e1ecc9791
qwen35 27B prose 25.25 +- 0.01 25.24 +- 0.02 27.33 +- 0.01 27.28 +- 0.13 -0.2% 166/267 174ce3a5dd77
qwen35 27B reasoning 29.74 +- 0.03 29.75 +- 0.03 32.21 +- 0.03 32.21 +- 0.03 -0.0% 179/226 b4bbf2c10581

ROCm (HIP_LAUNCH_BLOCKING unset):

arm prompt base off head off base on head on head on vs base on accepted/drafted per request sha
shared code 50.57 +- 0.39 50.46 +- 0.39 50.60 +- 0.51 54.62 +- 0.46 +8.0% 187/202 a7271fa423b3
shared prose 42.81 +- 0.24 42.81 +- 0.18 42.80 +- 0.19 46.25 +- 0.22 +8.1% 176/237 25849198daa4
shared reasoning 45.69 +- 0.17 45.66 +- 0.18 45.71 +- 0.17 49.28 +- 0.23 +7.8% 181/218 e6ad8c10ce79
own head code 51.55 +- 0.80 51.57 +- 0.83 51.44 +- 0.92 54.85 +- 0.91 +6.6% 186/204 a7271fa423b3
own head prose 43.52 +- 0.21 43.50 +- 0.22 43.47 +- 0.20 46.23 +- 0.30 +6.4% 175/240 25849198daa4
own head reasoning 46.41 +- 0.17 46.42 +- 0.16 46.36 +- 0.14 49.31 +- 0.17 +6.4% 180/221 e6ad8c10ce79
qwen35 27B code 29.36 +- 0.14 29.36 +- 0.14 31.37 +- 0.15 31.35 +- 0.16 -0.1% 187/202 568e1ecc9791
qwen35 27B prose 20.63 +- 0.03 20.62 +- 0.01 22.00 +- 0.04 22.01 +- 0.02 +0.0% 159/287 15327234dd5e
qwen35 27B reasoning 27.95 +- 0.04 27.96 +- 0.01 29.86 +- 0.02 29.84 +- 0.01 -0.1% 184/212 6edf3056c43b

With HIP_LAUNCH_BLOCKING=1, every sha and every accepted/drafted value matches the unset run for all three arms, with the flag off and on.

Depth, flag on, 128 tokens, two servers per side (tg t/s base -> head; TTFT within 0.5% base vs head in every row; accept identical):

backend arm 9 tok 9064 tok 28383 tok 59944 tok
Vulkan shared 44.30 -> 49.69 (+12.2%) 42.59 -> 45.91 (+7.8%) 52.79 -> 56.82 (+7.6%) 52.79 -> 56.68 (+7.4%)
Vulkan own head 43.63 -> 46.12 (+5.7%) 42.87 -> 45.34 (+5.8%) 54.31 -> 57.63 (+6.1%) 54.25 -> 57.40 (+5.8%)
ROCm shared 37.91 -> 40.96 (+8.0%) 34.63 -> 36.40 (+5.1%) 45.54 -> 46.91 (+3.0%, one slow head server inside the base range) not run
ROCm own head 38.95 -> 41.70 (+7.1%) 35.21 -> 36.98 (+5.0%) 46.54 -> 48.83 (+4.9%) not run

Edge cases (Vulkan, head, shared sidecar):

  • --spec-draft-mtp-vocab 1: no crash, every draft rejected (0/759), output identical to flag off.
  • 248320 and 999999: full vocab; output, acceptance and speed are the same as flag off.
  • -np 2 with two concurrent requests, flag off and on: no crash. The outputs differ from single-slot, but the same way with the flag off and on (batch shape on Vulkan, as on master).
  • Default fit path: no new warning; the subset is active.
  • Shared qwen4exp sidecar on the qwen35 27B target: head first logs mtp_draft_vocab = 94208 ignored: draft and target LM heads disagree in shape. Then base and head both fail context creation with QWEN4EXP MTP: draft and target disagree on the shape of 'token_embd.weight', and the server exits cleanly.
  • Log lines on head: own head MTP draft head uses 94241 of 248320 rows (188.74 MiB of q6_K, Vulkan0); shared MTP draft head uses 94241 of 248320 rows (244.46 MiB of q8_0, Vulkan0), where q8_0 is the target's head type. On master, the own-head run logs ignored: not supported for this model, and the shared run logs nothing.

Correctness

check method result
test-llama-archs all archs and -a qwen4exp, both backends Vulkan 137/137, ROCm 136/136, qwen4exp 1/1, same on both sides
ctest main `-L main -E 'test-opt test-llama-archs'`
spec unit tests `ctest -R 'spec-mtp-pcum draft-vocab
f32 logit parity llama-debug + cmp, 4 corpora, 2 targets byte-identical, Vulkan and ROCm, ROCm also with HLB=1
KLD/PPL short -c 2048, 4 corpora .kld byte-identical, PPL equal
KLD/PPL long 4 corpora joined, -c 16384 -b 512 -ub 512 .kld byte-identical, PPL equal (qwen4exp 2.1512 VK, 2.1520 ROCm)
greedy decode llama-completion -n 256, base A/A then head identical on all 4 corpora, 2 targets, both backends
target output under spec, base vs head server greedy, same flags identical sha in every cell
acceptance accepted/drafted identical in every cell
speed server t/s, depth runs head with the flag is faster; head without the flag equals base
HIP_LAUNCH_BLOCKING unset and =1 identical; no case passes only with =1
test-backend-ops not run no ggml change

Findings in full

  • Cache key: mtp_draft_cache is std::map<std::pair<int32_t, ggml_backend_buffer_type_t>, ...> (llama-model.cpp:1273), looked up with std::make_pair(n_keep, buft) (:2822). With a borrowed head, out is head_src->output, so the cache cannot tell two targets apart. common/speculative owns one draft model per target, so no shipped tool reaches this. A library user who shares one draft model between targets can.
  • Hadamard: llm_graph_context looks up hdmd->rot by weight pointer. The subset is a new tensor, so a rotated output.weight gives an unrotated matmul on the subset. prism accepts output.weight in weight_names, and the v2 tied_output binding uses token_embd as the head. Verification stays exact, so only acceptance suffers. qwen35/qwen35moe have the same gap today.
  • The dead warning and the duplicate shape check are covered under Asks.
  • The cost of upstream sync is close to zero: all lines are in fork-local MTP code. This PR conflicts with the open #201 in src/llama-model.cpp.

Claims

claim result
flag now works for qwen4exp drafts with their own head reproduced (log line, speed)
head-less shared sidecar takes the rows from the target's LM head reproduced (subset type is the target's q8_0)
target, verify step and token IDs unchanged reproduced (byte-identical logits, .kld, decode, server streams)
+7.5 / +9.2 / +7.2% Vulkan, +5.8% ROCm code, shared +7.1 / +9.3 / +6.5% reproduced in size with other files: Vulkan +6.1-8.2%, ROCm +6.4-8.1%
prefill unchanged reproduced (within 1%; TTFT within 0.5% at all depths)
acceptance within 1% of master reproduced, and stronger: identical
reasoning stream differs from master at n3 on Vulkan not reproduced with our files: every stream was identical. Not a problem
no-MTP streams identical to master reproduced
warns when there is neither a head nor a target not reachable (the context constructor throws first); checked by reading the code
shape check warns on mismatch reproduced; context creation then fails on both sides

Not tested

  • The PR's exact files (UD-Q4_K_XL target, Q8_0 sidecars). We used Gyro-M TQ2_0 with the Q4_K_M sidecars.
  • ROCm depth 64000 (it took too long; Vulkan 64000 ran for both sidecars).
  • KLD and decode under HIP_LAUNCH_BLOCKING=1 (only logits and spec ran there).
  • -ngld 0 (the own-head sidecar head is Q6_K, which is not repacked on x86).
  • --spec-draft-mtp-vocab 248319.
  • -np > 1 with the subset active (the graph uses the full head when n_outputs > 1).
  • Other GPUs and drivers.

@dzannotti dzannotti added needs-human Review done; a maintainer must approve. risk:medium Risk: medium verified The claims were reproduced. and removed verifying Building and running the PR to verify its claims. labels Nov 11, 2026
@dzannotti dzannotti added waiting-user We asked the author for something. and removed needs-human Review done; a maintainer must approve. labels Nov 13, 2026
dzannotti added a commit that referenced this pull request Nov 13, 2026
spec : MTP draft vocab subset for qwen4exp and shared MTP sidecars (rebase of #253)
@dzannotti

Copy link
Copy Markdown
Collaborator

Merged as #289: your two commits rebased onto master c054baa, with the authors unchanged. The only conflict was in mtp_draft_vocab_get: master added an EXL3 guard (#201), and the resolution keeps both that guard and the qwen4exp arch. We checked it again on the rebased branch: output identical with the flag off and on, and decode +8.5 to +10.1% on ROCm and Vulkan. The numbers are in #289. Thanks!

@dzannotti dzannotti closed this Nov 13, 2026
@dzannotti dzannotti removed the waiting-user We asked the author for something. label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model risk:medium Risk: medium verified The claims were reproduced.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants