Merged
[refactor] 统一 DeepSeek-V4 主干与 MTP 参数精度策略 #1290
hanboyouAdd on 19 days ago
[refactor] 统一 DeepSeek-V4 主干与 MTP 参数精度策略 #1290
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for hanboyou's contribution.)19 days ago Added label: cann-cla/yes
CANN-robot
19 days ago Comments:
19 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 | ✅ xuyujun, lrwei0709 (2/2) | ✅ xuyujun (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
mystri, thanks for your pull request. All authors of the commits have signed the CLA. 👍


19 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
19 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
19 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
19 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
106 messages are collapsed here。 See more
16 days ago Added label: ci-pipeline-running
16 days ago Removed label: ci-pipeline-running
16 days ago Added label: ci-pipeline-passed
16 days ago Merged pull request
CANN-robot
16 days ago Comments:
16 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
删除 DeepSeek-V4 的全局 FQN 精度列表和复制的 MTP 分片流程,改由模块声明参数精度,通过共享 decoder FSDP 入口读取,并复用原生 MTP helper。共享部分回移上游 #5774 的运行期机制,保留显式 callback 优先级、V4.1 使用方和既有 Config 类型。
旧精度设置如何由新 API 复现
旧 V4 默认配置是 FP32 主参数、BF16 默认参数计算、FP32 梯度归约:
training.dtype = "float32" training.mixed_precision_param = "bfloat16" training.mixed_precision_reduce = "float32"旧
_dsv4_param_dtypes()对以下参数请求 FP32 override;新实现将相同选择放到直接拥有参数的模块上,覆盖主干、MTP 和根模块:_preserve_dtype_paramsHcPre/HcHead("hc_fn", "hc_base", "hc_scale")compressor_128和 indexer compressor("ape",)Linear上为("weight",);直接参数布局在 attention 上声明("attn_sink",)共享 policy 对已声明参数使用
promote_types(parameter.dtype, param_dtype)。这些参数原本存为 FP32、默认计算为 BF16 时,结果仍为 FP32;其余参数按 BF16 计算,主参数存储、optimizer 的主参数 dtype 和配置的归约 dtype 均不改写。decoder 的cast_forward_inputs=False保持不变:这里保留的是 FSDP all-gather 及前反向使用的参数精度,不代表所有 activation 或算子均改为 FP32。声明只含模块自身参数名,不含全局 FQN;共享入口递归读取声明,原生 MTP 复用同一 decoder FSDP 路径。当前 0.4.0 回移使用运行期
_preserve_dtype_params,不新增上游完整Module.Config.preserve_dtype_params配置字段。「保留」不会把 BF16 存储强制改成 FP32。受保护参数与默认计算 dtype 都为 BF16 时,旧 FP32 override 请求本就被原生 policy 拒绝;V4 继续明确拒绝该组合,通用 preserve 语义保持不变。以上是已支持配置的策略映射说明,完整训练是否比特一致仍按下方数值验收记录判定。
类型
Checklist:
如何测试
当前基线
562c53cf,候选2bacc466,目标分支dev_0.4.0。合并保留目标分支的原生注意力配置、GraphTrainer EP overlap 和本 PR 的 FSDP 精度声明。本地完整
pre-commit run --all-files与 41 项相关 CPU 单测通过。覆盖声明与 FSDP 前反向、原生 attention、GraphTrainer 并行化和模型 recipe。当前提交 CI #2858。旧基线与
2f25cb09的 CPU、CI 和历史数值材料见验证归档。测试精简保留 12 项核心策略用例,较精简前净删 80 行。精度和性能验证结果
两组均测试
562c53cf→2bacc466,基线和候选各完成 100 步且退出码为 0。两侧使用同一 checkpoint、输入顺序、初始随机状态和确定性设置。逐 rank 比较未舍入记录的比特,并核对 TensorBoard 标量。PR 随后追加
2d2bd56,只修改AGENTS.md。43 层候选的训练进程退出码为 0,8 个 rank 正常结束。外层脚本因检测到文档提交将退出码记为 1,原始退出记录和独立核对均在验证包内。0.00015807152)0.0085924864)环境为 TorchTitan 0.4.0、Torch 2.15、Torch NPU 2.15.0.dev20261105、CANN 9.3,FP32 主参数、BF16 默认计算、FP32 归约,关闭 HF32。43 层使用 FSDP8/EP8、seq2048、GA2,在 8–15 卡使用 16 MiB HCCL 缓冲区。MTP 使用 FSDP2/EP2、seq256、GA1,在 0–1 卡使用 64 MiB。
43 层首次尝试在 0–7 卡使用 64 MiB 缓冲区,候选第 2 步反向显存不足。完整对照采用上述 8–15 卡配置重跑两侧。性能未单独测量。
逐步指标、运行命令、源码版本、退出记录、完整比较报告和曲线见验证包(SHA-256
4e48288befbb92e8ab4b194fc3a6283238397502ae90967db90b708bfb5afa17)。历史
6e3c9320→fccf7d1a的 43 层记录中,grad_norm 第 68 步、loss 第 69 步首次不一致。同一历史基线复跑的逐步标量一致,严格状态仍有 indexer 差异。历史比较记录。其他信息
不回移完整 Config/build、checkpoint 导出或 RL 精度传播,不改变 GraphTrainer SimpleFSDP。普通 decoder 和 MTP 共用原生分片流程;本 PR 为 #1257 的独立精度功能拆分。