Repository navigation
Qwen3.5: don't shift norm weights just because a checkpoint has MTP tensors - #598
Merged
Merged
Conversation
…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.
Contributor
|
Good catch, this matches: ml-explore/mlx-lm#1623 . |
davidkoski
approved these changes
Aug 31, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good, thank you!
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.
3 of 5 tasks
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.
MLX-converted Qwen3.5 checkpoints that retain their
mtp.*tensors (e.g. for speculative decoding) generate garbage tokens.sanitize(weights:)in bothMLXLLM/Models/Qwen35.swiftandMLXVLM/Models/Qwen35.swiftapplies the zero-centered RMSNorm+1shift whenThe
hasMTPWeightsterm assumes MTP tensors only occur in raw upstream checkpoints. That doesn't hold: a converted checkpoint (conv1d already[.., .., 1], norms already shifted, metadataformat: "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_layernormmean ≈ 0.97, i.e. already shifted) — the only difference is the presence ofmtp.*keys.Change: drop
hasMTPWeightsfrom the condition in both files.hasUnsanitizedConv1dalone 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 — themtp.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:)withformat == "mlx", the LLM classes don't — this PR fixes the shared heuristic instead of duplicating that gate.