Skip to content

Add an experimental pure-JAX MPMD pipeline (DeepSeek-V3, Qwen3.5) with a Pathways mode - #6597

Open
NuojCheng wants to merge 1 commit into
mainfrom
chengnuojin-mpmd-jax
Open

NuojCheng wants to merge 1 commit into
mainfrom
chengnuojin-mpmd-jax

Conversation

@NuojCheng

@NuojCheng NuojCheng commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This adds src/maxtext/experimental/mpmd/jax/, an experimental MPMD (multiple program, multiple data) pipeline-parallel training harness for mixture-of-experts decoders: DeepSeek-V3 and the Qwen3.5 family, including Qwen3.8-2.4T-A95B. It is written in plain JAX, with no MPMD partitioner.

MaxText's own pipeline runs every stage in one SPMD program, with the stages on a mesh axis. Here every stage is its own set of jitted shard_map programs on its own sub-mesh (FSDP x EP inside a stage). A stage boundary is a device-to-device copy, and one Python thread replays a fixed schedule without blocking. The default schedule is breadth / circular; GPipe, 1F1B, interleaved, the zero-bubble ZB-H1 / ZB-H2 and others are also available. It runs:

  • in one process on a TPU VM;
  • as multi-controller JAX across hosts and slices (--distributed). Across slices the boundary is a host relay or a collective permute.
  • as one Pathways client (JAX_PLATFORMS=proxy). Every stage is local to that client and each boundary is one IFRT CopyArrays, across slices too, with no relay and no per-host launcher.
  • on NVIDIA GPUs (--platform gpu).

The layer math is a pure-JAX port of each model. The tests hold it to MaxText's own models and trainer: logits, gradients and training steps. The kernels are MaxText's (megablox, the ring of experts, the ragged sort, Lineage's layers for DeepSeek-V3's batch split) and tokamax's splash attention. The package was developed outside MaxText and is ported here at one revision.

Setup (versions, local docker Pathways, GKE), quick start, benchmark results and test commands are in the package README, src/maxtext/experimental/mpmd/jax/README.md.

Headline result: GKE, 2 x TPU7x-4x4x4, 8 DeepSeek-V3 MoE layers, PP=2 with one stage a slice, FSDP 16 x EP 8, GBS 1024.

  • This package on Pathways: 2943 ms a step, 209.8 TFLOP/s/device.
  • The pre-port implementation on multi-controller JAX with the host relay: 2859 ms a step, 216.0 TFLOP/s/device.
  • Losses match to 3.2e-6.
  • Boundary crossing (58.7 MB a device): 41–51 ms, against the relay's 50 ms. Pathways removes the relay's host work and code, but at this payload DCN is the cost.
  • Zero Bubble at PP=4, two stages a slice (FSDP 8 x EP 8, 16 microbatches): 1F1B 3621.7 ms, ZB-H2 3332.4 (−8.0%). With --zb-split-last on: ZB-H1 3477.9 (−4.0%), ZB-H2 3448.8 (−4.8%), ZB-H2 with two W buffers 3422.4 (−5.5%). The default schedule, --vv 2 breadth, gains nothing there (3626.9, +0.1%). On one TPU7x-8 breadth stays faster at four stages (8 microbatches: −13.5% against 1F1B, the best zero-bubble order −9.9%), but not at two (−4.0%, ZB-H2 −6.2%).

Companion PR: #6598 adds experimental/mpmd/partir/, the same idea through Shardy MPMD's partitioner, on Pathways only. Both PRs add the same src/maxtext/experimental/mpmd/__init__.py byte for byte, so they can merge in either order.

For reviewers

  • Size. Experimental and large: 84 files, +74.8k lines (about 35.3k source and 39.5k tests; the zero-bubble schedules are about 2.4k and 2.9k of them, the Pathways skip of the multi-controller code 0.3k and 0.6k), in one commit. The tests are in tests/unit/mpmd_test/, a directory Add experimental MPMD pipeline parallelism on Shardy MPMD, run by Pathways #6598's tests share (no file names collide). Outside these it touches only experimental/mpmd/__init__.py and one .pre-commit-config.yaml line: pylint skips the package directory and its 32 test files, as it already skips experimental/lineage. pyink, codespell and yamllint apply.
  • Zero Bubble. --schedule zbh1|zbh2 (one chunk a stage) cuts each middle chunk's backward program by data dependence (stage_ad.split_jaxpr, no model changes) into I, the input gradient, and W, the weight gradients, run later in the bubbles; --zb-split-last on (off by default) cuts the fused last chunk too, the only split at two stages; it was 0.7–3.3% faster on one TPU7x-8 but 3.5% slower for ZB-H2 at PP=4 on GKE. Memory: 1F1B's residual sets (ZB-H2 about twice them) plus up to --zb-wbuf-cap (default 1) pending W buffers a split stage, each 7.25 GiB a device for two DeepSeek-V3 MoE layers at 4096 tokens. On a TPU VM's own client, which allocates outputs at dispatch, the loop paces the I's. Not with Lineage's batch split, stash modes or --fsdp-scope repeat.
  • Not a MaxText trainer. It has its own CLI (ds_ep_pipeline), synthetic or token-file data, a constant learning rate, and no checkpointing.
  • What was left out. The out-of-tree version's deprecated options are not ported: DualPipeV, 1f1b_pairs, --sync-rs fold, --tiles published, and old aliases. Code for other MaxText revisions, or for running without MaxText, is removed.
  • Pathways mode:
    • The multi-controller code (host relay, xfer, cross-process copies, key-value agreements and barriers, per-process records and traces) stays for multi-host McJAX and multi-node GPU runs, and runs only where jax.process_count() > 1 (pathways.multi_controller()): never under Pathways, whose one client is the only process, nor on one host.
    • Under Pathways its flags are refused before the backend starts, each naming what to use instead: --distributed, --transport relay|xfer, --json-procs / --profile-procs other than leaders, --norm-reduce allreduce. ds_ep_multihost.sh exits at once.
    • --max-ahead defaults to 2 steps under Pathways, as nothing else bounds how far the client runs ahead; the wait runs beside the dispatch, so step time is unchanged.
    • The libtpu flags go to the Pathways proxy, server and worker: python3 -m maxtext.experimental.mpmd.jax.pathways flags tpu7x prints them.
    • --profile takes only a gs:// directory, and is write-probed before the run.
    • Peak HBM is not reported through the proxy.
    • The client lowers the same programs as McJAX, but the Pathways servers compile them with their own XLA and libtpu, so results differ in the last bits.
  • Tests and known jaxlib bugs. The tests use MaxText's markers only, with no conftest of their own. jaxlib 0.12.0.x / 0.12.1 XLA:CPU bugs are gated, not worked around:
    • QwenMoeVsPort's programs corrupt XLA:CPU's heap, so it skips on CPU there; MAXTEXT_MPMD_RUN_JAXLIB_CPU_CRASH=1 runs it.
    • Checks that the YNNPACK fusions break skip while the fusions are on (26 in cpu-unit), among them every bit-for-bit zero-bubble pipeline check: on MaxText's CPU runners the fusions put an RMSNorm-scale gradient up to 7.7e-5 of its leaf apart in configurations that are bit for bit on other hosts. The three-stage fp32 zero-bubble checks run there, holding gradients to a few ulps and the steps' losses and gradient norms to 1e-6.
    • The split checks hold an fp32 chunk's leaves on CPU to 4 float32 ulps of their largest value: MaxText's CPU runners gave the experts' ragged_dot weight gradients up to 1.8e-7 of the leaf apart with the fusions off, which no other host reproduced.
    • 138 tests need 8 CPU devices, 32 slow checks and the 36 tests that start several JAX processes run by hand; the README says how to run them.
  • Lineage needs typeguard==2.13.3, which MaxText's requirements leave out, so the Lineage tests skip in CI.

Tests

Run on MaxText c034bc02f (this branch's base) with jax/jaxlib 0.12.0.1. The TPU and GKE runs of the other schedules predate the zero-bubble code; on CPU this head gives those schedules' results bit for bit, from identical programs (below).

  • MaxText's cpu-unit job: 1190 selected; replicated locally, 934 passed, 256 skipped, 0 failed (jax 0.12.0.1, tokamax 0.0.18, libtpu 0.0.50.1). In this PR's first CI run the out-of-memory killer took the tests that start several JAX processes; they now run only by hand. Its runs of earlier revisions failed zero-bubble checks by a few ulps that pass on every other host; this revision skips or bounds them as above.
    • Setup: docker with no TPU visible, libtpu installed, JAX_PLATFORMS unset, 4 fake CPU devices, CI's marker expression, -n 8 on 32 cores, as CI's runner.
    • Command: XLA_FLAGS=--xla_force_host_platform_device_count=4 python3 -m pytest -n 8 -m 'cpu_only and not post_training and not integration_test' tests/unit/mpmd_test
  • 8 CPU devices with the slow checks and the multi-process tests on (the README's by-hand command, 32 cores): 1138 passed, 52 skipped, 0 failed. Of the skips:
    • 34 are the jaxlib-bug gates: the 30 YNNPACK ones pass with the fusions off, the 4 heap-corruption ones with the gate lifted, one process each;
    • 17 need Lineage, and pass with typeguard 2.13.3;
    • 1 needs tensorflow (not run).
  • Zero Bubble on CPU (8 and 16 devices, XLA:CPU's YNNPACK fusions off): ZB-H1 and ZB-H2 give the previous head's 1F1B losses, gradients, parameters and optimizer state bit for bit, 51 of 51 runs over 13 configurations (DeepSeek and Qwen at 2 to 4 stages; --zb-split-last and the fusion plan on and off; W-buffer caps 0 to 2). The other schedules are unchanged: 28 of 28 runs bit for bit, every program's stripped StableHLO identical in 35 configurations.
  • Zero Bubble on a TPU is not bit for bit, as XLA:TPU compiles each half by itself. The tests hold it to a contract measured on a TPU7x-8: every leaf of a split chunk within 3% of the fused program's; warm-up losses within 2e-3 and gradient norms within 2e-2 of 1F1B's (seen: 4.0e-4 and 6.8e-3); ZB-H2 bit for bit ZB-H1's. The 6 tpu_only tests of OnTpu and SplitBackwardOnTpu pass on McJAX and on local Pathways.
  • One controller runs no multi-controller code. pathways_test.OneController runs main in one process for every schedule (1F1B and ZB-H2 on every PR) with 40 multi-controller-only functions patched to raise, and a line trace of CPU, local Pathways and one-host McJAX runs finds none of their lines executed. Multi-process runs (CPU, 2-4 processes with --distributed) give the previous head's results process by process: the 87 multi-process tests, and 14 configurations compared bit for bit.
  • Review fixes from the out-of-tree source, ported test by test (19 findings of its PRs' reviews): --json keeps a symlinked record's link, writes /dev/stdout / /dev/stderr / a named pipe in place (a named pipe no longer hangs under --profile); a gs:// --profile / --json naming no bucket stops the run up front, and a --dry-run no longer write-probes it; --transport relay|xfer is refused with one message everywhere; xprof picks the newest trace session by name; testing.jaxlib_version reads rc builds; OnTpu skips on a multi-slice job; and several tests are tighter or no longer run out of memory maps. The previous revision's 1F1B, breadth, interleaved and zero-bubble runs are bit for bit unchanged (13 configurations).
  • Parity against MaxText's models: DeepSeek-V3 5 tests; Qwen3.5 15 tests, with bf16 logits bit-exact; maxtext_parity_test 34 tests. The numbers are identical on MaxText 4b5b24c92 and c034bc02f.
  • TPU7x-8, McJAX:
    • README quick start 2 (4 DeepSeek-V3-sized MoE layers, PP=2 x FSDP 2 x EP 2) runs 1333 ms a step, 214.4 TFLOP/s/device.
    • Zero Bubble, 4 stages of 2 such layers (FSDP 1 x EP 2, 64 experts), 8 microbatches, --zb-split-last on: 1F1B 1337.5 ms, ZB-H1 1262.0, ZB-H2 1230.6 (1205.4 with two W buffers), --vv 2 breadth 1157.3.
    • With typeguard, the 12 Lineage TPU checks pass.
  • TPU7x-8, local Pathways (docker, image 20261117-jax_0.12.0.1):
    • Native and ppermute boundaries agree bit for bit.
    • Losses are within 1.2e-3 of McJAX over the warm-up steps.
    • Zero Bubble, the same: 1F1B 1441.2 ms, ZB-H1 1369.9, ZB-H2 1332.9 (1306.7), --vv 2 breadth 1254.9.
  • Bit for bit against the out-of-tree source (TPU7x-8, McJAX, the same flags): warm-up losses and gradient norms are equal in 9 configurations: DeepSeek and Qwen at 2 and 4 stages, interleaved with pairs, the Qwen and Lineage batch splits, --data maxtext, MaxText's kernels at their defaults.
  • GKE, 2 x TPU7x-4x4x4 (Pathways, image 20261124-jax_0.12.0.1): the runs above (the zero-bubble ones on an earlier revision of this branch, one job evicted twice and resumed), and at PP=2 with 8 microbatches 1F1B 3227.6 ms, ZB-H1 3257.6 (1F1B's order without --zb-split-last; losses bit for bit).
  • Lint: pre-commit (codespell, pylint, pyink, yamllint) passes.

Not run yet:

  • multi-host McJAX jobs of this port (the McJAX GKE numbers above are the pre-port implementation's);
  • the README's gcluster command (the GKE run used xpk);
  • the gpu_only tests on a GPU;
  • OnTpu on a v6e-4 (its CPU twin passes);
  • on GKE at PP=4: --vv 1 breadth;
  • the zero-bubble schedules on TPUs other than TPU7x, or in a multi-host McJAX job (only the CPU multi-process tests).

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests and provided workload links above if applicable. (Note: New PRs get skip-ci-tests so only CPU/lint/docs checks run during review; a bot removes it after 2 approvals on a 1-commit PR to run TPU/GPU suites, or remove it yourself / ask a maintainer on fork PRs to run them sooner. On TPU7X, only the TPU tests that the PR adds or modifies run; add the run-tpu7x label to run the full TPU7X suite.)
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hi @NuojCheng, I'm running an automatic MaxText review of this pull request. You can track my progress in the logs. To request another review later, add the gemini-review label or comment @gemini-cli /review.

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

🤖 I'm sorry @NuojCheng, but I was unable to process your request. Please see the logs for more details.

@NuojCheng
NuojCheng force-pushed the chengnuojin-mpmd-jax branch 6 times, most recently from 339f61b to 8e9e165 Compare November 28, 2026 09:55
Add src/maxtext/experimental/mpmd/jax/: MPMD pipeline parallelism for
DeepSeek-V3 and the Qwen3.5 family in plain JAX. Each stage is its own
set of jitted shard_map programs on its own sub-mesh (FSDP x EP), a
stage boundary is a device-to-device copy, and one Python thread
replays a fixed schedule. It runs in one process, as multi-controller
JAX across hosts and slices, as one Pathways client (each boundary one
IFRT CopyArrays, across slices too), and on NVIDIA GPUs. The
multi-controller code runs only where jax.process_count() > 1, so never
under Pathways, which refuses its flags up front.

Schedules: breadth / circular (the default), GPipe, 1F1B, interleaved,
and the zero-bubble ZB-H1 and ZB-H2 (--schedule zbh1 / zbh2). These
cut each middle chunk's backward program by data dependence into its
input-gradient half and its weight-gradient half, which runs later, in
the bubbles; --zb-split-last on (off by default) cuts the fused last
chunk's program too. On CPU without YNNPACK fusions they give 1F1B's
gradients bit for bit; on a TPU, within a measured tolerance.

It is a training harness with its own command line (ds_ep_pipeline),
not a MaxText trainer. The layer math is a pure-JAX port of each model
that the tests hold to MaxText's; the kernels are MaxText's (megablox,
ragged sort, Lineage's layers for DeepSeek-V3's batch split) and
tokamax's. The package README covers setup, Pathways in docker and on
GKE, benchmark results and the tests, which use MaxText's markers and
skip on the jaxlib 0.12 XLA:CPU bugs they would trip. pylint skips the
two new directories.
@NuojCheng
NuojCheng force-pushed the chengnuojin-mpmd-jax branch from 8e9e165 to daf5b95 Compare November 29, 2026 17:58
@NuojCheng NuojCheng removed the skip-ci-tests Add this label to the PR to skip running CI tests label Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant