feat: Add Qwen3.6 MoE (qwen3_5_moe) GGUF export support#1397
Open
DeadByDawn101 wants to merge 2 commits into
Open
feat: Add Qwen3.6 MoE (qwen3_5_moe) GGUF export support#1397DeadByDawn101 wants to merge 2 commits into
DeadByDawn101 wants to merge 2 commits into
Conversation
Adds GGUF export support for Qwen3.6 35B-A3B and other Qwen3.5/3.6
Mixture-of-Experts models.
Changes:
- fuse.py: Add 'qwen3_5_moe' to supported model types for --export-gguf
- gguf.py: Add tensor name mappings for Qwen3.6 MoE architecture:
- Strip 'language_model.' prefix (ConditionalGeneration wrapper)
- Map switch_mlp.{gate_up,down}_proj → ffn_{gate_up,down}_exps
- Map shared_expert.{gate,down,up}_proj → ffn_{gate,down,up}_shexp
- Map shared_expert_gate → ffn_gate_inp_shexp
- Map mlp.gate → ffn_gate_inp (MoE router)
- Map linear_attn (Mamba-style SSM) tensor names
- gguf.py: Pre-process gate_proj + up_proj fusion into gate_up_proj
before name translation (Qwen3.6 stores these separately but GGUF
expects them concatenated along the intermediate_size dimension)
Background:
Qwen3.6 MoE uses a hybrid architecture (Gated DeltaNet + softmax
attention + MoE with shared experts) that has different tensor naming
conventions than Mixtral-style MoE models. The key differences are:
1. 'switch_mlp' instead of 'block_sparse_moe.experts.{n}'
2. Merged 3D expert tensors instead of per-expert 2D tensors
3. Separate gate_proj and up_proj that need pre-fusion
4. 'language_model.' prefix from the ConditionalGeneration wrapper
5. Linear attention (Mamba SSM) tensors alongside standard attention
Tested with: Qwen3.6-35B-A3B fine-tuned models fused via mlx_lm.fuse
Co-authored-by: Claude (Anthropic)
Tests added: - translate_weight_names strips language_model. prefix - translate_weight_names maps switch_mlp → ffn_*_exps - translate_weight_names maps shared_expert → ffn_*_shexp - translate_weight_names maps MoE router (mlp.gate) - translate_weight_names maps linear_attn (SSM) tensors - gate_proj + up_proj fusion produces correct gate_up_proj shape
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
Adds GGUF export support for Qwen3.6 35B-A3B and other Qwen3.5/3.6 Mixture-of-Experts models via
mlx_lm.fuse --export-gguf.Currently,
--export-ggufonly supportsllama,mixtral, andmistralmodel types. This PR addsqwen3_5_moesupport.Problem
Qwen3.6 MoE uses a unique hybrid architecture (Gated DeltaNet + softmax attention + MoE with shared experts) with tensor naming conventions that differ from Mixtral-style MoE:
switch_mlpinstead ofblock_sparse_moe.experts.{n}gate_projandup_projthat need pre-fusion for GGUFlanguage_model.prefix from theConditionalGenerationwrapperChanges
fuse.pyqwen3_5_moeto the supported model types whitelistgguf.pylanguage_model.prefix stripping: Handles theConditionalGenerationwrapper prefixgate_up_projbefore name translation (GGUF expects these fused)Testing
Tested with fine-tuned Qwen3.6-35B-A3B models:
mlx_lm.fuse --export-ggufproduces valid F16 GGUFllama-quantizeApplies To
Qwen3_5MoeForConditionalGenerationarchitecturemodel_type: qwen3_5_moeDiscovered and implemented by Gabriel Garcia / RavenX LLC