Skip to content

Support context, tensor, and pipeline parallelism with MinimalAsyncEP - #4089

Merged
wwwjn merged 1 commit into
mainfrom
minimal-async-ep-tp
Aug 11, 2026
Merged

wwwjn merged 1 commit into
mainfrom
minimal-async-ep-tp

Conversation

@wwwjn

@wwwjn wwwjn commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enable MinimalAsyncEP to compose with context parallelism, tensor parallelism, and pipeline parallelism.

This PR does not add backend-specific CP, TP, or PP dispatch algorithms. The required behavior comes from the common MoE and mesh contracts:

MinimalAsyncEP therefore continues to dispatch the local x_TD rows over its EP group and returns a combined tensor with the same local token shape. The common MoE sharding path handles CP and TP, while the pipeline runtime invokes the stage-local MinimalAsyncEP instances.

Buffer capacity

MinimalAsyncEP now uses the shared lifetime capacity derivation:

num_token_shards = context_parallel_degree * tensor_parallel_degree
if seq_len % num_token_shards != 0:
    raise ValueError(...)
num_max_tokens_per_rank = local_batch_size * seq_len // num_token_shards

CP and TP reduce the local token capacity because they shard the sequence dimension before MoE. The shared configuration requires seq_len to divide evenly across CP * TP; users must pad the configured sequence length when it does not. PP does not enter this calculation because it partitions model layers, not the token axis.

This replaces the backend-local local_batch_size * seq_len calculation, which overallocated once CP or TP was enabled. The shared setup also fills hidden_dim, preserves a user-specified capacity when it is large enough, and rejects an undersized capacity. MinimalAsyncEP keeps only its backend-specific dtype setup.

Changes

  • Remove the MinimalAsyncEP configuration restrictions for CP, TP, and PP.
  • Include MinimalAsyncEP in shared EP buffer-capacity configuration.
  • Add an H100 integration configuration for DP-shard=2, CP=2, TP=2, EP=8.
  • Keep the test on spmd_types until the H100 suite migrates from the default DTensor backend.

Testing

Tensor parallelism

Four H100s, 10 training steps:

DP-shard=2, TP=2, EP=4
spmd_backend=spmd_types
compile disabled
full activation checkpointing

Loss decreased from 8.06603 to 3.86079; final grad_norm was 1.6618.

Context parallelism

Four H100s, 10 training steps:

DP-shard=2, CP=2, EP=4
spmd_backend=spmd_types
compile disabled
full activation checkpointing

Loss decreased from 8.00828 to 3.87139; final grad_norm was 1.5916.

Pipeline parallelism

Four H100s with PyTorch 2.14.0.dev20260811+cu130, two optimizer steps:

DP-shard=2, PP=2, EP=2
1F1B with 8 microbatches
spmd_backend=spmd_types
compile disabled
full activation checkpointing

The run completed MinimalAsyncEP dispatch/combine, pipeline forward/backward, and PP-wide gradient-norm reduction. Loss decreased from 8.32359 to 6.38615; grad_norm changed from 3.6094 to 4.4162.

Numerical comparison against AllToAll

The standard AllToAll dispatcher and MinimalAsyncEP were run for 10 steps with the same DP-shard=2, PP=2, EP=2 topology, fused expert kernels, data, seed 42, and deterministic mode. Full-precision TensorBoard metrics show a maximum relative loss difference of 4.55e-4 and a maximum relative grad-norm difference of 2.60e-3.

MinimalAsyncEP is not expected to be bitwise identical to AllToAll: AllToAll rounds each score-weighted expert row to BF16 and then performs deterministic scatter-add in expert order, while MinimalAsyncEP accumulates the top-k rows in FP32 slot order and rounds once.

Two diagnostics verify that this difference is numerical rather than token dropping:

  • A temporary assertion reduced the active receive-row count across every stage-local EP group and required it to equal EP_size * local_tokens * top_k. It passed every forward and activation-recompute dispatch across all 10 steps.
  • Replacing only MinimalAsyncEP's top-k combine arithmetic with the AllToAll arithmetic produced the exact same step-1 loss: 8.1351776123046875 for both backends. Native MinimalAsyncEP produced 8.1351785659790039.

The exact eight-GPU DP-shard=2, CP=2, TP=2, EP=8 CI configuration was not run locally because the host has seven available H100s. CP and TP were validated independently as listed above.

Limitations

  • MinimalAsyncEP requires the spmd_types backend. The default DTensor path currently hits the same Shard(1) -> Partial(sum) limitation tracked by Default TorchTitan RL to spmd_types #4110.
  • MinimalAsyncEP requires full recomputation: full activation checkpointing for eager training or full memory policy for GraphTrainer.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 7, 2026
@wwwjn
wwwjn force-pushed the minimal-async-ep-tp branch 2 times, most recently from 5e5d73b to dfa99fb Compare August 7, 2026 23:11
@wwwjn
wwwjn requested a review from xmfan August 7, 2026 23:18
@wwwjn
wwwjn marked this pull request as ready for review August 7, 2026 23:18

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SGTM. Please wait for @xmfan 's approval.

Also cc @acisseJZhong I think the code related to padding will be gone once we move it to vllm wrapper.

@wwwjn
wwwjn force-pushed the minimal-async-ep-tp branch from dfa99fb to ff0b992 Compare August 11, 2026 14:36
Base automatically changed from unify-ep-token-dispatcher to main August 11, 2026 15:46
@wwwjn
wwwjn force-pushed the minimal-async-ep-tp branch from ff0b992 to f60eeab Compare August 11, 2026 15:46

for token_dispatcher_cfg in dispatcher_cfgs:
token_dispatcher_cfg.hidden_dim = model_config.dim
token_dispatcher_cfg.num_max_tokens_per_rank = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We size the buffer using life-time max number of local tokens, to avoid token drop.

Before this change, MinimalAsyncEP only supports TP=1 CP=1, so in pre-training:

  • Life-time max local tokens = (local_batch_size * seq_length) / (TP * CP) = local_batch_size * seq_length

After current change:

  • Life-time max local tokens = (local_batch_size * seq_length) / (TP * CP) = local_batch_size * seq_length / TP

@acisseJZhong acisseJZhong Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need

        required_num_max_tokens_per_rank = training.local_batch_size * (
            (training.seq_len + num_token_shards - 1) // num_token_shards
        )

the ceil devision? I think we already made sure the token seq len is evenly divided by TP through padding. For CP I think we didn't pad now, can we just hardcode CP=1 for now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CP is now validated, so I did not hardcode CP=1. This PR reuses the shared persistent-buffer bound rather than adding a MinimalAsyncEP-specific formula. CP and TP shard the sequence before MoE, so the maximum local rows are local_batch_size * ceil_div(seq_len, CP * TP). For the currently divisible configurations, ceil_div is identical to exact division; it also remains a valid upper bound if the sharding path yields an uneven local shard. The CP=2 run completed 10 steps, and the routed-row conservation check passed on every dispatch in the separate 10-step numerical run.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO we should not do ceil devision if we already pad to even, we should raise explicit error if it's still uneven, and user should be responsible to pad even.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right, we should check then error if uneven, given we already done padding in #4080, let me update

@wwwjn
wwwjn force-pushed the minimal-async-ep-tp branch 3 times, most recently from 1925b2f to d6b705c Compare August 11, 2026 16:57
@wwwjn wwwjn changed the title Support tensor parallelism with MinimalAsyncEP Support context, tensor, and pipeline parallelism with MinimalAsyncEP Aug 11, 2026
@wwwjn
wwwjn force-pushed the minimal-async-ep-tp branch 3 times, most recently from 550f736 to 816dfd5 Compare August 11, 2026 19:48
@wwwjn
wwwjn force-pushed the minimal-async-ep-tp branch from 816dfd5 to 79aa3e9 Compare August 11, 2026 19:50
@wwwjn wwwjn added the ciflow/h100.8 Trigger H100.8 CI label Aug 11, 2026
@wwwjn
wwwjn merged commit 15db18b into main Aug 11, 2026
26 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants