Add pipeline parallel support for Qwen3 MoE and MiniMax models#1138
Open
qubitcontracting wants to merge 2 commits intoml-explore:mainfrom
Open
Add pipeline parallel support for Qwen3 MoE and MiniMax models#1138qubitcontracting wants to merge 2 commits intoml-explore:mainfrom
qubitcontracting wants to merge 2 commits intoml-explore:mainfrom
Conversation
Adds PipelineMixin to Qwen3MoeModel and MiniMaxModel, enabling pipeline parallel inference across multiple nodes. Changes per model: - Inherit PipelineMixin for pipeline-aware layer splitting - Use pipeline_layers instead of layers in forward pass - Add distributed recv/send between pipeline ranks - Add all_gather so all ranks have final output for lm_head - Add make_cache() returning KV cache only for this rank's layers (prevents cache-layer count mismatch that causes GPU timeout) For Qwen3 MoE, also passes return_array=True to create_attention_mask which is required when the mask flows through distributed ops. Depends on PipelineMixin from pipeline.py. When pipeline_size == 1 (single node), all distributed ops are skipped and behavior is identical to the original code. Tested with: - Qwen3-235B-A22B-Instruct 8-bit (94 layers, 3 nodes) - Qwen3-Coder-480B-A35B-Instruct 4-bit (94 layers, 3 nodes) - MiniMax-M2.5-8bit (80 layers, 3 nodes) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- KVCache() takes no arguments in 0.31.2 (was head_dim, num_kv_heads) - Add make_cache() to outer Model class that delegates to inner model (make_prompt_cache calls model.make_cache(), not model.model.make_cache()) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 pipeline parallel support (PipelineMixin) to Qwen3 MoE and MiniMax model architectures.
Changes
mlx_lm/models/qwen3_moe.pyQwen3MoeModelextendsPipelineMixinrecv_like→ pipeline_layers →send→all_gather→normmake_cache()returns KV cache entries only for this rank's layersmlx_lm/models/minimax.pymake_cache()delegation from outer Model classTesting