Pull Request has been successfully merged by CANN-robot.
(Thank you for jiangna1111's contribution.)变更摘要
本 PR 旨在恢复 #1171 升级迁移后丢失的 SDC replay 配置互斥校验,并为新的 TrainingEngine replay 结果契约与 signed 摘要补充回归测试。核心改动是在 TrainerEx 初始化阶段重新接入 validate_sdc_replay_config,使 sdc_replayer 启用时对 sdc 检测配置进行校验;同时在配置单测中覆盖 Trainer / GraphTrainer 与多种检测器组合的拒绝/接受场景,并新增 SDCReplayer 的签名与整步累加行为测试。
主要改动
- 恢复 replay 与 SDC 检测的互斥校验:
torchtitan_npu/extensions/torchtitan/trainer.py从torchtitan_npu.extensions.components.sdc引入validate_sdc_replay_config,并在TrainerEx初始化中当self.sdc_replayer is not None时调用该校验,与validate_anticipatory_config并列执行。 - 配置层拒绝检测器与 replay 同时启用:
tests/unit_tests/config/test_configs.py新增参数化用例,组合Trainer/GraphTrainer与 typed/native 的gradient、hccl检测方式,断言ConfigManager().parse_args在--sdc.gradient-enabled、--sdc.hccl-mode或NPU_ASD_CONFIG/NPU_ASD_ENABLE开启检测时抛出对应ValueError。 - 配置层接受检测器关闭时的 replay: 同一测试文件新增用例验证检测全部关闭时 replay 配置可正常解析,并校验
config.sdc_replayer.num_replays == 2、config.sdc.gradient_enabled is False、config.sdc.hccl_mode == 0,同时确认返回的配置类型与所选 trainer 一致。 - 新增 signed replay 签名与整步结果回归测试: 新增
tests/unit_tests/patches/torchtitan/observability/test_sdc_replayer.py,验证SDCReplayer.run_fwd_bwd在num_replays=2下执行三次且 RNG 状态一致、返回ForwardBackwardResult、梯度按完整累加恢复、loss_metrics透传以及digests均为torch.int64。 - 覆盖哈希高位与空/缺失 buffer 的签名行为: 同文件另一用例断言
loss的原始哈希高位(>= 2**63)在签名中被正确处理为有符号值(raw_hash - 2**64),且空 buffer 与值为None的 buffer 摘要均为 0。


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 | ✅ lrwei0709, hwcaifubi (2/2) | ✅ lrwei0709 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
jiangna1111, 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.


描述
本次适配恢复 #1155 已有、在 dev0.4.0 配置迁移 #1171 后遗漏调用的 SDC replay 兼容性校验。当前 NPU 适配不支持 replay 与梯度/HCCL SDC 检测或 torch-npu 原生 SDC 检测同时启用,因此需要在配置初始化阶段检查 config.sdc 和相关环境变量,提前拒绝不兼容组合并给出明确提示。单独启用检测或 replay 的合法配置保持不变。
同时补充通过真实 ConfigManager 入口执行的最小回归测试,覆盖冲突配置拒绝和合法配置接受,避免后续升级或重构再次遗漏校验调用。测试保护的是本仓 NPU 适配的配置约束,不重复验证上游 replay 算法,也不限制未来由上游等价实现替代本地校验。
类型
Checklist:
如何测试
简要描述测试方案,并附上自验证记录。
相关 CPU 单测:84 passed;Ruff、format、编译、OAT、架构及重复代码检查通过。
完整 pre-commit 的 10 项 Pyrefly 错误与基线一致,额外规则检查无新增问题。
精度和性能验证结果
不涉及
其他信息
在这里可以添加任何与这个 Pull Request 相关的其他说明。