Repository navigation
spec : MTP draft vocab subset for qwen4exp and shared MTP sidecars (rebase of #253) - #289
Merged
Merged
Conversation
--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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #253 by @Nathanw1014 (with the qwen4exp commit by @gaetan-puleo). Same two commits, rebased onto master c054baa. The authors of both commits are unchanged. The original branch does not allow maintainer edits, so the rebase lands from this branch.
What changed in the rebase
One conflict, in
llama_model::mtp_draft_vocab_get(src/llama-model.cpp): master added an EXL3 guard (#201), and #253 addsLLM_ARCH_QWEN4EXPto the same condition. The resolution keeps both:git range-diffagainst the #253 head shows no other change.Verification on the rebased branch
The maintainer review of #253 (head ede6d5b) covers the code. These runs check that it still works on current master.
Qwen3.8-Flash-Next Gyro-M TQ2_0 with the shared MTP sidecar (
mtp-Qwen3.8-Flash-Next-shared-Q4_K_M.gguf),--spec-type draft-mtp,-np 1 -c 8192 -b 1024 -ub 1024 -fa on -lm none -lzm on-direct, 256 greedy tokens, 2 rounds, flag off vs--spec-draft-mtp-vocab 94208, gfx1151:The two rounds agree within 1%. The server log has no "ignored" warning, so the subset is active.
test-llama-archs -a qwen4exppasses on ROCm0 and CPU. It aborts on the Meta device withggml-backend.cpp:844: GGML_ASSERT(reg) failedinllama_memory_hybrid_idx. Master c054baa aborts in the same place, so this is not from this change. It needs its own issue.🤖 Generated with Claude Code
https://claude.ai/code/session_01YKmjzcT1LTvKtbw9EzBVGE