Skip to content

Qwen3.5: don't shift norm weights just because a checkpoint has MTP tensors - #598

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
mandrael:qwen35-norm-shift-mtp
Aug 31, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
mandrael:qwen35-norm-shift-mtp

Conversation

@mandrael

Copy link
Copy Markdown
Contributor

MLX-converted Qwen3.5 checkpoints that retain their mtp.* tensors (e.g. for speculative decoding) generate garbage tokens.

sanitize(weights:) in both MLXLLM/Models/Qwen35.swift and MLXVLM/Models/Qwen35.swift applies the zero-centered RMSNorm +1 shift when

let shouldShiftNormWeights = hasMTPWeights || hasUnsanitizedConv1d

The hasMTPWeights term assumes MTP tensors only occur in raw upstream checkpoints. That doesn't hold: a converted checkpoint (conv1d already [.., .., 1], norms already shifted, metadata format: "mlx") can keep its MTP weights, trips the term, and gets shifted twice — every layernorm lands near 2.0 instead of 1.0.

Repro: convert a Qwen3.5 checkpoint with mlx-lm keeping the mtp.* tensors, load through the text-model path, generate.

Evidence: in such a checkpoint the norm tensors are bit-identical to a working MTP-stripped conversion of the same base model (input_layernorm mean ≈ 0.97, i.e. already shifted) — the only difference is the presence of mtp.* keys.

Change: drop hasMTPWeights from the condition in both files. hasUnsanitizedConv1d alone identifies raw upstream checkpoints: transformers exports store conv1d as [C, 1, K], and any converter that transposes conv1d shifts the norms in the same sanitize pass, so the two signals can't diverge in a valid checkpoint. MTP-only drafter checkpoints are unaffected — the mtp. filter removes all their tensors before the shift loop, so the flag never did anything there.

Side note: the VLM class already guards sanitize(weights:metadata:) with format == "mlx", the LLM classes don't — this PR fixes the shared heuristic instead of duplicating that gate.

…ensors

An MLX-converted checkpoint may keep its mtp.* tensors for speculative
decoding. Treating their presence as proof of a raw upstream checkpoint
applies the zero-centered RMSNorm +1 shift a second time, leaving every
layernorm near 2.0 instead of 1.0 and degrading generation to garbage
tokens.

The conv1d layout identifies raw checkpoints on its own: transformers
exports store conv1d as [C, 1, K], and a converter that transposes conv1d
shifts the norms in the same sanitize pass, so the two signals cannot
diverge in a valid checkpoint. MTP-only drafter checkpoints are unaffected
because the mtp. filter removes all their tensors before the shift loop.
@aleroot

aleroot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Good catch, this matches: ml-explore/mlx-lm#1623 .
Ideally adding a regression covering an already-converted checkpoint that still contains mtp.* weights would be great.

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change looks good, thank you!

@davidkoski
davidkoski merged commit 28a7f30 into ml-explore:main Aug 31, 2026
3 checks passed
djandrewgibbons pushed a commit to djandrewgibbons/mlx-swift-lm that referenced this pull request Sep 1, 2026
…ensors (ml-explore#598)

An MLX-converted checkpoint may keep its mtp.* tensors for speculative
decoding. Treating their presence as proof of a raw upstream checkpoint
applies the zero-centered RMSNorm +1 shift a second time, leaving every
layernorm near 2.0 instead of 1.0 and degrading generation to garbage
tokens.

The conv1d layout identifies raw checkpoints on its own: transformers
exports store conv1d as [C, 1, K], and a converter that transposes conv1d
shifts the norms in the same sanitize pass, so the two signals cannot
diverge in a valid checkpoint. MTP-only drafter checkpoints are unaffected
because the mtp. filter removes all their tensors before the shift loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants