Repository navigation
Conversation
…odel loads The global `_MTP_ACTIVE` flag (set via `set_mtp_active` before `mlx_lm.load()`) persists after model load completes. This caused three failure modes: 1. **Model switch**: Loading a non-MTP-compatible model after an MTP-enabled one left `_MTP_ACTIVE=True`. The patched `Model.__init__` on the new model then incorrectly attached an MTP head, crashing with missing mtp.* weights. 2. **SpecPrefill draft model (BatchedEngine)**: A target model with MTP enabled leaked the flag to the draft model load, causing the same crash. 3. **SpecPrefill draft model (VLMBatchedEngine)**: Same as (2) for VLM path. Changes: - `maybe_apply_pre_load_patches()`: reset `_MTP_ACTIVE=False` at function entry before any model-specific logic, so every load starts from a known state. - `BatchedEngine._load_draft()`: snapshot current flag, disable MTP, load draft, restore flag. - `VLMBatchedEngine._load_draft()`: same snapshot/restore guard. Closes the root cause behind "Native MTP is enabled for this model but the converted weights are missing the mtp.* tensors" errors when using SpecPrefill with a Qwen3.5 draft after an MTP-enabled model was previously loaded. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Owner
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.
Summary
Fixes the process-wide
_MTP_ACTIVEflag leaking from one model load to another, which caused SpecPrefill draft model loading to crash with "Native MTP is enabled but converted weights are missing mtp.* tensors".Root cause
set_mtp_active()is only called inside_is_mtp_compatible()branch inmaybe_apply_pre_load_patches(). If the current model is not MTP-compatible, the flag is never reset. This means:Qwen3.6-27B-oQ4-mtpwithmtp_enabled=True→_MTP_ACTIVE=TrueQwen3.6-35B-A3B-UD-MLX-4bit(non-MTP) → flag staysTrueQwen3.5-0.8B-MLX-4bitas draft → patched__init__seesis_mtp_active()=True→ attaches MTP → crashFix
maybe_apply_pre_load_patches(): reset_MTP_ACTIVE=Falseat function entry so every model load starts cleanBatchedEngine._load_draft(): snapshot/restore flag around draft model loadVLMBatchedEngine._load_draft(): same snapshot/restore guardTest plan
🤖 Generated with Claude Code