Repository navigation
Fix qwen3_moe sanitize() function's layer-0 MoE assumption - #1875
Merged
Merged
Conversation
…ints sanitize() gated expert-weight stacking on whether layer 0's raw expert keys were present. Under pipeline sharding a rank only downloads its own local layers' weight files, so a raw checkpoint can have no layer-0 key at all even though the rank's own local layers still need stacking. Switched to a presence-based scan over whichever layers are actually in the weights dict.
The comment described a pipeline-sharded partial-download scenario that a review found unreachable in practice: that loading path requires an MLX-converted (already-stacked) checkpoint and errors before any partial download happens. The real bug is architectural: whether layer 0 is an MoE layer is config-driven, so a layer-0-only gate is wrong regardless of sharding.
twallgren
added a commit
to twallgren/mlx-lm
that referenced
this pull request
Sep 10, 2026
…tion Same fix as qwen3_moe.py (ml-explore#1875): the comment described an unreachable pipeline-sharded partial-download scenario. The real bug is architectural — whether layer 0 is an MoE layer is config-driven, so a layer-0-only gate is wrong regardless of sharding.
twallgren
added a commit
to twallgren/mlx-lm
that referenced
this pull request
Sep 11, 2026
…tion Same fix as qwen3_moe.py (ml-explore#1875): the comment described an unreachable pipeline-sharded partial-download scenario. The real bug is architectural — whether layer 0 is an MoE layer is config-driven, so a layer-0-only gate is wrong regardless of sharding.
michalk8
approved these changes
Sep 14, 2026
michalk8
left a comment
Collaborator
There was a problem hiding this comment.
Thanks a lot, I've added your fix to rest of the models.
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.
The issue this is addressing:
qwen3_moe.py's sanitize() function decides whether to stack MoE weights by checking for a fixed key on layer 0. If layer 0 isn't a MoE layer then that key won't exist and the gate will end up skipping the stacking for every layer.
Seems like all of the Qwen3 MoE configs that are out right now have a MoE layer at layer 0 so they're not affected by this bug, but that could change so we should be prepared for that situation.
The solution:
Changed qwen3_moe.py's sanitize check from a fixed layer-0 check to presence-based detection across whichever local MoE layers actually exist in the checkpoint.