Repository navigation
[MoE] Deprecate pure TP on routed experts - #4794
Conversation
31efd58 to
93759a6
Compare
93759a6 to
c2b8f1e
Compare
c2b8f1e to
9022eee
Compare
| "padding_mask_T": padding_mask_src_layout, | ||
| }, | ||
| in_dst_shardings={ | ||
| "x_TD": desired_input_layout, |
There was a problem hiding this comment.
For EP=False, SP=True, this is dense_activation_placement(tp=spmd.R, cp=spmd.S(0))
Essentially, the routed-experts weights are already replicated with this PR, and this logic replicates the input x_TD as well. It works but I don't think we have to replicate the x_TD, it can be kept sequence sharded.. But there is a tradeoff here
- Today - everything replicated, each rank doing full computation, just an extra all gather at the beginning.
- Keep seq-sharded - each rank does local compute (faster compute), and then do a reduce-scatter for the grads (slower comms).
Should we consider this? I am asking for 2 reasons
- Just genuine curiosity of which one is better
- Having all-gather just for the shared expert (which will be TP sharded and therefore actually needs all_gather) will make my TP refactor PR somewhat cleaner.
There was a problem hiding this comment.
For EP=False, dense SP = True case if input remains sharded for routed experts:
- there will be an extra reduce scatter at the end(vs if inputs replicated, we do replicated computation and no extra comm needed)
- there will still be an all gather. The all gather just moved from the shared+routed path to only the shared expert path. But this all gather for shared expert could be overlapped by asyncTP or fused with distGEMM? (vs if inputs replicated, the all gather in the beginning for shared+routed will be fully exposed)
is my understanding correct? If so I think keeping inputs sharded might be better since we just trade one exposed all gather for one exposed reduce scatter, while each rank doing separate comp rather than duplicating comp.
There was a problem hiding this comment.
Yes, precisely, thats my understanding as well.
Caveat: The overlapping by asyncTP is true and can give you some benefit, but in my mind, thats not the main optimization. I think the main perf win should be from routed-experts working on sharded inputs and therefore computing faster.
There was a problem hiding this comment.
in titan shared expert and routed experts are computed sequentially. If we assume no asyncTP/distGEMM, then the all gather is still exposed, we need to benchmark if the reduce computation can outweigh the extra reduce scatter.
But if in most case the all gather will be almost fully overlapped/hidden with TP comp(also not every model has shared expert), then I think we just trade all gather for reduce scatter(they should have similar latency?), while enjoying the reduced comp.
There was a problem hiding this comment.
changed the routed experts input from replicate to sharded.
I benchmarked on my local H100 devgpu with no asyncTP/distGEMM.
TP=2: sharded routed input improved forward/backward time
by 1.15% (138.75 -> 137.16 ms).TP=4: it improved forward/backward time by 3.83% (143.42 ->
137.93 ms).
c762123 to
c80ac8c
Compare
|
|
||
| The diagram below shows the DTensor placement flow through the MoE layer | ||
| for all four parallelism configurations (EP on/off × SP on/off). | ||
| The diagram below shows the DTensor placement flow through the MoE layer for |
There was a problem hiding this comment.
DTensor for fwd-bwd is gone, should we migrate to spmd_types layouts
There was a problem hiding this comment.
updated the placements in the graph.
| local token shard. Keep logical capital suffixes here to avoid encoding | ||
| a specific parallel layout in these local tensor names. | ||
| sharding. Under EP, E may be a local shard of experts; without EP, | ||
| expert weights are replicated across TP. Under SP, R may be a local |
There was a problem hiding this comment.
very confusing -- when dense TP is enabled, and we don't support sparse TP, we HAVE TO enable sparse EP, i.e. TP to EP.
o/w what's the point of replicating across TP?
There was a problem hiding this comment.
got it, I will enforce TP2EP then. Previously I thought we should support the case where user specific EP=1, and dense TP on, despite it is less ideal.
| TP and their load-balancing statistics therefore require TP reduction. | ||
| """ | ||
|
|
||
| tp_shards_tokens: bool = False |
There was a problem hiding this comment.
confusing: we are deleting things, why there's need to add new field. Is it addressing previously existing bugs?
There was a problem hiding this comment.
this is to support the case EP off, dense TP on, and we still want to shard the inputs on replicate routed experts.
Should be gone if we enforce TP2EP.
| EP off, SP off: input Replicate, gate computes on all tokens, output stays | ||
| Replicate. | ||
| EP off, SP on: input Shard(0) on tokens, gate computes on the local shard, | ||
| and the output remains Shard(0). |
There was a problem hiding this comment.
EP is always on, when TP / SP is on
9fda4b1 to
e6c99b8
Compare
| _hf_sequence_parallel_placement() | ||
| if enable_sp | ||
| else _hf_activation_placement(tp=spmd.P) | ||
| else _hf_activation_placement(tp=spmd.P if enable_ep else spmd.R) |
There was a problem hiding this comment.
dense TP can't be used with sparse EP
| # Routed experts do not use dense TP. Reuse the dense TP ranks as | ||
| # EP when an MoE model has not explicitly configured EP. | ||
| if moe_configs and tp > 1 and parallelism.expert_parallel_degree == 1: | ||
| parallelism.expert_parallel_degree = tp |
There was a problem hiding this comment.
prefer to not introduce implicit casting -- it won't help anyone
just error out if ep < tp or ep > dp_shard * cp * tp
| For MoE models with tensor_parallel_degree > 1, a value of 1 automatically | ||
| selects tensor_parallel_degree. |
| enable_ep=enable_ep, | ||
| enable_sp=enable_sp, | ||
| expert_param_layout=_GROUPED_EXPERTS_PARAM_LAYOUT, | ||
| expert_param_names=_GROUPED_EXPERTS_PARAM_NAMES, |
There was a problem hiding this comment.
we might not need this arg anymore, do we?
| "w2_EDF": spmd.S(2), | ||
| "w3_EFD": spmd.S(1), | ||
| } | ||
| _GROUPED_EXPERTS_PARAM_NAMES = ("w1_EFD", "w2_EDF", "w3_EFD") |
There was a problem hiding this comment.
can we remove this from every model sharding.py?
| name: expert_param_placement_sparse() for name in expert_param_names | ||
| } | ||
| experts_input_layout = dense_sequence_parallel_placement() | ||
| else: |
There was a problem hiding this comment.
else means FSDP-only sharding on routed experts, we should reject TP by not allowing "tp" in the sharding config
There was a problem hiding this comment.
correct, now set inner_experts_sharding_config to None when enable_ep=False.
f80a43c to
b83c9b9
Compare
|
|
||
| max_context_length: int = 2048 | ||
| """Maximum logical context length used for training.""" | ||
| """Maximum logical context length used for trnaining.""" |
There was a problem hiding this comment.
wow can't believe my agent would change this out of no where.
There was a problem hiding this comment.
i guess it's trying to save my job lol
| ) | ||
| # Sequence parallelism is effective only when TP has multiple ranks. | ||
| if moe_configs and tp == 1: | ||
| parallelism.enable_sequence_parallel = False |
There was a problem hiding this comment.
does this concretely matter for anything?
There was a problem hiding this comment.
it matters because in moe_sharding.py we need to pass in enable_sp, it would be wrong if we pass in default True when tp=1.
it doesn't matter.
| if enable_sp and not enable_ep: | ||
| raise ValueError("MoE sequence parallelism requires expert parallelism") |
There was a problem hiding this comment.
I guess this is related to the other comment -- enable_sp is for dense SP right? where does it concretely matter?
There was a problem hiding this comment.
actually yeah I think you are right, passing enable_sp=True when TP=1 wouldn't matter for MoE, as we don't have tp mesh anyways. Concretely, setting TP: spmd.V would be equivalent to TP: spmd.R when tp=1.
b83c9b9 to
e83cfc0
Compare
| enable_sp: bool, | ||
| expert_param_layout: dict[str, spmd.PerMeshAxisSpmdType], | ||
| ) -> tuple[ShardingConfig, ShardingConfig]: | ||
| expert_param_names: Collection[str], |
There was a problem hiding this comment.
do we still need this? If it's for gpt-oss, we probably should have a special function for gpt-oss, rather than requiring everyone to send these fields, as most are reusing common/moe.py
|
|
||
| max_context_length: int = 2048 | ||
| """Maximum logical context length used for training.""" | ||
| """Maximum logical context length used for trnaining.""" |
There was a problem hiding this comment.
i guess it's trying to save my job lol
e83cfc0 to
dde0252
Compare
Summary
Numerics
Compared
main(ab670811b) against this PR (b83c9b925) with the DeepSeek-V3 debug model for 10 steps. Each configuration used a newly generated shared seed checkpoint,--debug.seed=42, deterministic mode, and CUDA graphs disabled on both sides.Loss and grad norm are bitwise identical across all 10 steps for both supported configurations.
EP=1, dense TP=2is no longer tested because MoE configurations now requireEP >= TP.