[Feature] Integrate UltraEP Runtime for MoE EP Load Balancing - #2050
Open
ShilohYu wants to merge 3 commits into
Open
[Feature] Integrate UltraEP Runtime for MoE EP Load Balancing#2050ShilohYu wants to merge 3 commits into
ShilohYu wants to merge 3 commits into
Conversation
Add compile-compatible random-logits routing for balanced benchmark runs.
Integrate UltraEP as an opt-in MoE execution path for DeepEP-based expert parallel training. Supported in this initial integration: - dispatcher="deepep" with ep_size > 1 - BF16 grouped experts without expert bias - intra_layer_micro_batch == 1 - DP=1, where the EP group covers the whole world - runtime-owned redundant expert weight/grad buffers outside model parameters, optimizer state, and checkpoints - UltraEP placement/reroute, replica weight sync, fused master+replica grouped GEMM, and replica grad reduce for the single-microbatch training path Not supported yet: - intra_layer_micro_batch > 1, which needs per-microbatch replica weight/grad slots before the shared UltraEP buffers can be used safely - activation recompute with UltraEP - MTP expert layers with UltraEP - dispatcher="all2all" or dispatcher="agrs" - FP8 grouped experts - expert bias - DP>1/FSDP gradient-reduction ordering
Move UltraEP autograd hooks to decoder layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
在 MoE Expert Parallel(EP)训练中,端到端吞吐受 token 负载最高的 rank 限制。router post-gating 后产生的专家负载偏斜,会使实际吞吐与理想均衡负载下的性能产生明显差距。UltraEP 是面向 MoE 的在线专家负载均衡运行时。它根据当前 layer / microbatch 的精确 post-gating 负载规划副本,复制热点专家,并将部分 token 重路由到 runtime replica slot。
本 PR 将 UltraEP 接入 Xtuner,同时保持已有职责边界:
术语解释:router 和上层训练语义看到的是
logical expert;每个logical expert对应一个由 Xtuner 管理的master expert,并可由 UltraEP 创建多个replica expert。master expert与replica expert共同构成实际执行的physical expert;只有 dispatcher 和 expert compute 使用physical expertID。主要改动
新增可选的 UltraEP 运行时
MoEConfig.ultraep_cfg: UltraEPConfig | None;None是唯一关闭状态,默认不启用。UltraEPConfig仅承载冗余专家槽位等用户显式配置;UltraEPManagerProvider.from_xtuner_config()从MoEConfig统一派生层数和logical expert数等运行时 shape 信息。UltraEPManager;关闭时不导入或依赖 UltraEP。保留 logical routing 语义并引入 physical routing
topk_ids,供上层训练语义、auxiliary loss 和诊断使用。UltraEPLayerRuntime,负责更新 placement、异步同步master expertweight,以及生成供 dispatch 与 expert compute 使用的physical expertID。logical experts扩展为由master experts和replica experts组成的physical experts。前反向时序
MoE 主链路仍为
attention -> router -> dispatch -> experts -> combine。update_placement、异步weight_sync和reroute;权重同步weight_sync与reroute、dispatch 重叠,仅在 expert compute 前等待完成。新增双基址 Grouped GEMM
UltraEPGroupedGemm与 dual-weight Triton grouped-GEMM kernel。新增 force-balanced benchmark proxy
force_load_balance:前向使用随机 logits 构造近似均衡路由,反向保留原 router logits 的梯度。torch.compile兼容性测试。当前支持范围
当前代码仅接通并验证
dispatcher="deepep"路径,且显式限制:ep_size > 1、expert_tp_size == 1,且 logical expert 数可被 EP size 整除;intra_layer_micro_batch == 1;all2all、agrs等其他 dispatcher。端到端性能验证
实验使用单机 8×H200、EP=8(TP/DP/SP/PP=1)、DeepEP、BF16、
torch.compile,模型为 20 层 Qwen3-235B-A22B 缩小结构(32 experts、top-k=4、expert FFN 2048)。UltraEP off 与 baseline 吞吐接近。开启 UltraEP 后,相比 off:
正确性 sanity check
UltraEP on、UltraEP off 与 baseline 的 loss 曲线均稳定下降,未观察到 NaN、发散或异常拐点。