Merged
fix: restore SDC replay config validation after migration #1213
fix: restore SDC replay config validation after migration #1213
Merged
jiangna1111Add on 26 days ago
jiangna1111
jiangna1111Collaborators
26 days ago

描述

本次适配恢复 #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 相关的其他说明。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for jiangna1111's contribution.)
jiangna1111jiangna1111Collaborators
26 days ago Created pull request, commit 1f63157a
atomgit-bot
atomgit-botCollaborators
26 days ago Comments:

变更摘要

本 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。
likedislike
Incorrect?
atomgit-bot
atomgit-botCollaborators
26 days ago Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
26 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
26 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 ✅ lrwei0709, hwcaifubi (2/2) ✅ lrwei0709 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
52 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
24 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
24 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
24 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
1Fire41Fire4Collaborators
23 days ago Associated issue: [RFC] TorchTitan v0.4.0 分阶段升级规划与进度跟踪
CANN-robot
CANN-robotCollaborators
23 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike