Skip to content

Add pipeline parallelism for Qwen3 MoE - #1801

Merged
nastya236 merged 1 commit into
ml-explore:mainfrom
azamamirza:qwen3-moe-pipeline
Sep 1, 2026
Merged

nastya236 merged 1 commit into
ml-explore:mainfrom
azamamirza:qwen3-moe-pipeline

Conversation

@azamamirza

Copy link
Copy Markdown
Contributor

Problem

qwen3_moe has no pipeline support, so Qwen3 MoE checkpoints cannot be
split layer-wise across machines the way glm4_moe, deepseek_v3, and
other MoE models already can via PipelineMixin. (Companion to the
tensor-parallel shard() added in #1774; this adds the pipeline axis.)

Change

Follows the established glm4_moe / deepseek_v3 pattern exactly:

  • Qwen3MoeModel mixes in PipelineMixin and its __call__ gains the
    standard pipeline plumbing: recv_like from the previous rank, run
    pipeline_layers, send to the next rank with the mx.depends tie on
    the last cache, and the final all_gather broadcast. With
    pipeline_size == 1 (the default) every branch is skipped and behavior
    is unchanged.
  • Model.layers returns self.model.pipeline_layers (as in glm4_moe).
  • Adds tests/model_parallel_tests.py::test_pipeline, a structural test
    in the style of the existing test_shard: a tiny qwen3_moe config is
    pipelined on a size-1 group and must match the un-pipelined output.

Verification

Rebased onto current main (which already includes #1774 and #1787):

  • tests/model_parallel_tests.py: 2 passed, 5 subtests passed.
  • tests/test_models.py -k qwen3: 3 passed.
  • Multi-node hardware verification (2 Apple Silicon MacBooks over an RDMA
    JACCL ring, Thunderbolt 5), Qwen3-235B-A22B 4-bit, greedy, identical
    prompt: 2-node pipeline 28.41 tok/s decode, TTFT 7.23 s vs 2-node
    tensor-parallel sharding 24.56 tok/s / TTFT 11.91 s (+16% decode,
    -39% TTFT); generated text checked coherent and consistent between the
    two modes.
  • black / isort --profile=black clean.

@nastya236

Copy link
Copy Markdown
Collaborator

Thank you for your contribution, will test it as soon as possible.

@nastya236 nastya236 added the await verification This pull request is non-trivial and requires a human expert to verify its correctness. label Aug 29, 2026

@nastya236 nastya236 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Tested on 4 m5 ultra mesh.

@nastya236
nastya236 merged commit e93eaf7 into ml-explore:main Sep 1, 2026
2 checks passed
azamamirza added a commit to azamamirza/mlx-lm that referenced this pull request Sep 1, 2026
Regenerated from upstream/main e93eaf7. Both qwen3_moe patches are now
upstream (ml-explore#1774 tensor parallel, merged 2026-08-22; ml-explore#1801 pipeline, merged
2026-08-29 - the base commit itself), so this branch carries ZERO code
patches: upstream + this document + the version marker. Zero functional
divergence for the first time since the fork was created.
@azamamirza
azamamirza deleted the qwen3-moe-pipeline branch September 1, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

await verification This pull request is non-trivial and requires a human expert to verify its correctness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants