Pull Request has been successfully merged by CANN-robot.
(Thank you for wanlinan's contribution.)变更摘要
本 PR 旨在让上游 experiments/graph_trainer 的 EP overlap pass 能在 Ascend NPU 上支撑 DeepSeek-V4 图:上游存在四处缺陷,会在 chunk / 调度阶段直接抛错或产出成环的调度图。本提交在 torchtitan_npu/patches/torchtitan/ 下新增四个临时补丁并在 patches/torchtitan/__init__.py 中注册(随 import torchtitan_npu 自动 apply),同时新增可 trace 的 token dispatcher 并配套将 moe_token_unpermute 反向改为 v2 内核,使 EP overlap 可在 NPU 上启用。
主要改动
- 新增可 trace 的 EP token dispatcher:在
torchtitan_npu/override/common/token_dispatcher.py中新增NPUTraceableLocalDispatchMetadata/NPUTraceableAllToAllDispatchMetadata元数据类与NPUTraceableAllToAllTokenDispatcher——dispatch通过稳定的argsort/gather计算inverse_indices_N、保持 token 数符号化,combine复用npu_moe_token_unpermute完成 local combine,并提供 override 入口npu_graph_trainer_token_dispatcher供配置选用。 moe_token_unpermute反向适配 v2 内核:_npu_moe_token_unpermute_backward改用torch_npu.npu_moe_token_unpermute_grad_v2,probs非None时恒保存permuted_tokens,并记录permuted_tokens_size_0/permuted_tokens_dtype,使 permuted 行数在 chunk 后为符号量时仍可 trace(原零占位、按probs.requires_grad分支的写法被移除)。- 补丁
graph_trainer_ep_chunk_concretization:把 placeholder 符号 hint 收集限定在与 EP chunk 符号连通的连通分量内,对无法推导 base hint 的 extent 跳过而非抛错(真实 hint 冲突仍抛错),并只改写含 chunk 符号的值,避免将 per-batch 尺寸冻结进图或对无关动态维抛错。 - 补丁
graph_trainer_ep_overlap_shape_queries与graph_trainer_ep_ready_nodes_dedup:前者在调度前剥离 token exchange 输出上aten.sym_size.int查询误继承的EP_token_exchange标注(否则被调度器判为非法标注节点而抛错);后者在_ready_nodes中引入selected集合按节点去重,避免同一节点同时进入两个 chunk 候选集后被串成顺序边、导致调度图成环使拓扑排序失败。 - 补丁
graph_trainer_ep_shape_live_out:当 dispatch all-to-all 为被切分区域 live-out 且使用者均为首维 size query 时,把位于 producer region root 内的 dim-0 size query 用户路由到 chunk 侧并跳过物化;残余场景改用torch.ops.aten.cat沿 token 维拼接两个 chunk 值重建(token 数在 chunk 间可加),并写入chunked_materialization_proof元信息。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/torchtitan-npu | ✅ panchao-gitcode, 张德鹏 (2/2) | ✅ 张德鹏 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wanlinan, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


上游 experiments/graph_trainer 的 EP overlap pass 在 DeepSeek-V4 图上无法运行:
四处上游缺陷会在 chunk / 调度阶段直接抛错或产出成环的调度图。本提交补齐这些缺陷并提供可 trace 的 token dispatcher,使 EP overlap 可在 Ascend NPU 上启用。
patches/torchtitan/ 新增四个临时补丁(随 import torchtitan_npu 自动 apply):