Merged
[fix] Fix DeepSeek V4.1 Inductor fullgraph compilation with CP and forced MoE load balancing #1456
1Fire4Add on 3 days ago
[fix] Fix DeepSeek V4.1 Inductor fullgraph compilation with CP and forced MoE load balancing #1456
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for 1Fire4's contribution.)3 days ago Added label: stat/needs-squash
3 days ago Added label: cann-cla/yes
CANN-robot
3 days ago Comments:
3 days ago Comments:
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 | ✅ zhaowei1936, zzyyjj012 (2/2) | ✅ zhaowei1936 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
hitwdy, thanks for your pull request. All authors of the commits have signed the CLA. 👍


3 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
3 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
118 messages are collapsed here。 See more
2 days ago Added label: approved
zzyyjj012
2 days ago Comments:
2 days ago Comments:
/lgtm


2 days ago Added label: lgtm
2 days ago Merged pull request
CANN-robot
2 days ago Comments:
2 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
问题背景
DeepSeek V4.1 同时启用 CP(
doc_chunk)、Inductor 和强制 MoE 负载均衡时,模型以fullgraph=True编译。CP all-to-all 的 split 随 microbatch 的文档边界变化,Dynamo 为具体的 Python 整数值建立 guard,例如recv_split[0] == 2584。不同结构的 TransformerBlock 又共用 checkpoint wrapper 的 Dynamo 缓存,编译变体叠加至recompile_limit=32,训练在首步完成前抛出FailOnRecompileLimitHit。窗口 KV 交换还有一种边界情况。如果某个 rank 无需接收远端 key,Inductor 生成的激活检查点重算代码可能省略该 rank 的窗口 all-to-all。同组其他 rank 仍执行这次通信,导致反向卡住。
解决方案
isolate_recompiles=True,隔离不同层的 Dynamo 编译缓存。类型
Checklist:
如何测试
deepseek_v4_1_flash_40layers_16experts_text,数据为tests/assets/c4_test。启用 FP8、CP=2、DP shard=4、DP replicate=1、EP=8、doc_chunk、local batch=1、global batch=32、序列长度 4096,以及--debug.moe-force-load-balance --compile.enable --compile.components model --compile.backend inductor。doc_chunk和doc_zigzag的前向与反向。精度和性能验证结果
8 卡 FP8、Inductor fullgraph、强制 MoE 负载均衡,CP=1(DP shard=8)和 CP=2(DP shard=4)均完成 20 步。按仓库
loss_compare.py的默认close阈值,本次 20 步对比 PASS。误差曲线以 CP=1 为基线。底部红色虚线标出最大相对误差上限 ±0.5%。
阈值为平均绝对误差 ≤ 0.02、最大和平均相对误差各 ≤ 0.5%。两组使用相同初值(8 个 rank 的参数和缓冲区逐字节一致)。先打包再按 DP 切分,逐步核对了 640 条样本的输入、位置和标签。
强制均衡路由使用本地 token 序号。按两种 CP 布局重放路由规则,72.85% 的 token 位置(含 padding)对应的专家列表不同,因此指标反映两种训练配置的整体差异。两组使用同一套 CANN 9.3.0 运行库和编译环境,其中 3 处 ops-nn 头文件目录取自同版本的较早构建。
仓库数值对齐指南中的完整验证及性能对比待补充。
其他信息
本 PR 涉及 3 个产品文件和 1 个测试文件,沿用现有的
fullgraph判定和公开编译开关语义。