Repository navigation
Support context, tensor, and pipeline parallelism with MinimalAsyncEP - #4089
Conversation
5e5d73b to
dfa99fb
Compare
tianyu-l
left a comment
There was a problem hiding this comment.
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.
dfa99fb to
ff0b992
Compare
ff0b992 to
f60eeab
Compare
|
|
||
| for token_dispatcher_cfg in dispatcher_cfgs: | ||
| token_dispatcher_cfg.hidden_dim = model_config.dim | ||
| token_dispatcher_cfg.num_max_tokens_per_rank = ( |
There was a problem hiding this comment.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
You are right, we should check then error if uneven, given we already done padding in #4080, let me update
1925b2f to
d6b705c
Compare
550f736 to
816dfd5
Compare
816dfd5 to
79aa3e9
Compare
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:
RoutedExpertsoperate on a local sequence shard and return that local layout.MinimalAsyncEP therefore continues to dispatch the local
x_TDrows 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:
CP and TP reduce the local token capacity because they shard the sequence dimension before MoE. The shared configuration requires
seq_lento divide evenly acrossCP * 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_lencalculation, which overallocated once CP or TP was enabled. The shared setup also fillshidden_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
DP-shard=2, CP=2, TP=2, EP=8.spmd_typesuntil the H100 suite migrates from the default DTensor backend.Testing
Tensor parallelism
Four H100s, 10 training steps:
Loss decreased from
8.06603to3.86079; finalgrad_normwas1.6618.Context parallelism
Four H100s, 10 training steps:
Loss decreased from
8.00828to3.87139; finalgrad_normwas1.5916.Pipeline parallelism
Four H100s with PyTorch
2.14.0.dev20260811+cu130, two optimizer steps:The run completed MinimalAsyncEP dispatch/combine, pipeline forward/backward, and PP-wide gradient-norm reduction. Loss decreased from
8.32359to6.38615;grad_normchanged from3.6094to4.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=2topology, fused expert kernels, data, seed 42, and deterministic mode. Full-precision TensorBoard metrics show a maximum relative loss difference of4.55e-4and a maximum relative grad-norm difference of2.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:
EP_size * local_tokens * top_k. It passed every forward and activation-recompute dispatch across all 10 steps.8.1351776123046875for both backends. Native MinimalAsyncEP produced8.1351785659790039.The exact eight-GPU
DP-shard=2, CP=2, TP=2, EP=8CI configuration was not run locally because the host has seven available H100s. CP and TP were validated independently as listed above.Limitations
spmd_typesbackend. The default DTensor path currently hits the sameShard(1) -> Partial(sum)limitation tracked by Default TorchTitan RL to spmd_types #4110.