Repository navigation
Conversation
Mix of ikawrakow@f67fd9a#diff-43453f510556d352276e897e137cb103b3bbca24acb6cba33208d4887b2e3c77 and ikawrakow#1355 (comment) instructions. Thanks @mullecofo
Fix issue reported here ikawrakow#1355 (comment)
This reverts commit 0d5680c.
A predictor-only MTP companion for qwen35/qwen35moe declares the full
block count (n_main + nextn_predict_layers) but ships only the NextN
block. Loading one with -md aborted at
check_tensor_dims: tensor 'blk.0.attn_norm.weight' not found
because create_qwen35{,moe}_tensors() creates every main block as
hard-required. Step-3.5 and DeepSeek-V4 already have an "mtp_only"
path for this; Qwen3.5 did not, and the surrounding MTP plumbing did
not recognise a Qwen3.5 companion either.
- llama-load-tensors: detect the companion (nextn > 0 and blk.0
attn_norm absent) and mark the absent main blocks
TENSOR_SKIP|TENSOR_NOT_REQUIRED, mirroring create_step35_tensors().
Guard the "9B shares q_proj" fixup, which has no trunk to borrow
from, and skip empty blocks in the split-mode-graph loop, where
split_recurrent_tensors() would assert on the missing ssm_in/wqkv.
- llama-model: add llama_model_is_qwen35_family() and let Qwen3.5 use
the common MTP package contract, so a companion classifies as
COMPANION and a plain target as TARGET_ONLY (which is what makes the
target export the hidden states the companion consumes). Also accept
enorm/hnorm as a predictor tail, since 9B/4B NextN blocks can be
built without eh_proj.
- llama-hparams: map qwen35moe n_layer 49 and 61 to 122B-A10B and
397B-A17B, so a companion of those sizes no longer prints "?B".
- speculative: recognise the Qwen3.5 companion, validate its arch and
head count, keep the embedded-tail + ordinary-draft combination
working, and force pooling_type = NONE on the companion context.
- common: reject a companion passed as -m with an actionable message
instead of aborting inside the graph builder.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Support standalone Qwen3.5 MTP companion GGUFs (-md ... --spec-type mtp)
Contributor
Author
|
PR moved there: #2328 |
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.
Problem
Qwen3.5 (
qwen35/qwen35moe) supports MTP speculative decoding, but only when theNextN block is embedded in the same GGUF as the model. If the MTP block is shipped as a
separate predictor-only companion file and passed with
-md, loading fails immediately:A companion declares the full block count (
n_main + nextn_predict_layers, e.g. 65) butonly contains the NextN block (
blk.64.*) plus the embeddings and output head. The mainblocks live in the target GGUF loaded with
-m.create_qwen35_tensors()neverthelesscreates every block
blk.0 … blk.63as hard-required, so the loader stops on the firstmissing tensor.
Step-3.5 and DeepSeek-V4 already handle this case (
mtp_onlyincreate_step35_tensors(),is_standalone_mtpincreate_deepseek4_tensors()). Qwen3.5 had no equivalent, and thesurrounding MTP plumbing did not recognise a Qwen3.5 companion either.
Fix
src/llama-load-tensors.cpp— detect a companion (nextn_predict_layers > 0andblk.0.attn_norm.weightabsent from the GGUF) and mark the absent main blocksTENSOR_SKIP | TENSOR_NOT_REQUIRED, mirroring the existing Step-3.5 idiom. Applied toboth
create_qwen35_tensors()andcreate_qwen35moe_tensors(). Also guards the"9B shares q_proj" fixup (a companion has no trunk layer to borrow
wqfrom), and skipsempty blocks in the split-mode-graph loop, where
split_recurrent_tensors()wouldotherwise assert on the missing
ssm_in/wqkv.src/llama-model.cpp— addllama_model_is_qwen35_family()and let Qwen3.5 use thecommon MTP package contract, so a companion is classified
COMPANIONand a plain targetas
TARGET_ONLY. The latter is what makesllama_context_has_mtp_outputs()true for thetarget, so it exports the hidden states the companion consumes.
enorm/hnormare alsoaccepted as a predictor tail, since a Qwen3.5 NextN block can be built without
eh_proj.src/llama-hparams.cpp— mapqwen35moen_layer49 and 61 to 122B-A10B and397B-A17B, so companions of those sizes report their model type instead of
?B(the dense switch already had the corresponding
+1cases).common/speculative.cpp— recognise the Qwen3.5 companion as an external MTPprovider, validate that its architecture matches the target and that it has exactly one
predictor layer, keep the existing "embedded tail + ordinary draft model" combination
working, and force
pooling_type = NONEon the companion context (an MTP graph neverappends a pooling layer).
common/common.cpp— reject a companion passed as-mwith an actionable messageinstead of aborting inside the graph builder.
Behaviour for Step-3.5, DeepSeek-V4, Gemma 4 and embedded-MTP Qwen3.5 is unchanged.
Companion layouts covered
Checked against the published Qwen3.5/3.6/3.8 companion tensor maps. All eleven follow one
of three layouts, and all three are handled:
output.weight, falls back totoken_embdEvery one of them carries its own
blk.<mtp>.attn_q.weight, so no companion depends on thetarget's
q_proj.output_extra.weightis absent throughout, sooutput_mtpfalls back tooutputas intended.Testing
Verified against real GGUFs —
Qwen3.5-0.8BandQwen3.8-27BatIQ1_S_R4, each with itsmatching companion. Both reproduce the reported
check_tensor_dimsfailure before the patchand load and generate after it. The 0.8B pair also covers the tied-embedding layout, since
its companion ships no
output.weight.Additionally checked with synthetic target/companion pairs reproducing each of the three
layouts above (4 main blocks + 1 NextN block, mixed full-attention and gated-delta-net
layers), which allows testing the
qwen35moepath and a companion built withouteh_proj.Regression matrix, before vs. after:
--spec-type mtpcheck_tensor_dimsfailureoutput.weight)check_tensor_dimsfailure--spec-type mtpcheck_tensor_dimsfailureeh_projcheck_tensor_dimsfailure--spec-type mtp, no-mdeh_proj,--spec-type mtp-mddraft,--spec-type draft-mddraft,--spec-type draft--spec-type mtp, no-md-mcheck_tensor_dimsfailure-md