Merged
feat: adapt signed SDC replay in NPU Trainer #1155
feat: adapt signed SDC replay in NPU Trainer #1155
Merged
jiangna1111Add on Nov 2
jiangna1111
jiangna1111Collaborators
Nov 2

描述

  • 适配 torchtitan #4333/#4334 上游的SDC特性接入,并在patch中将重放的 uint64 摘要按位视为 int64,解决 Ascend NPU 报错,复用上游重放流程。
  • 仅补充与现有 NPU SDC 的互斥校验。

类型

Checklist:

如何测试

远端兼容环境复用已有 UT,3 passed:

python -m pytest -q \
  tests/unit_tests/extensions/torchtitan/test_trainer.py::test_trainer_config_revalidates_after_swap_optimizer_override \
  tests/unit_tests/test_sdc.py::test_trainer_initializes_sdc_once_after_model_setup \
  tests/unit_tests/test_sdc.py::test_trainer_failed_backward_does_not_advance_gradient_accumulation

CPU replay 与上游 GraphTrainer replay recipe 的 NPU 配置校验已通过,保留上游 graphs 重放次数约束。

  • 单 NPU replay:2 次前后向、8 个 int64 摘要,含 empty/None/CPU RNG 检查。
  • GraphTrainer:Llama3 debugmodel/SDPA/seq_len=32,开启 aot_fx_trace 训练 2 步;构图 1 次、图内前后向 4 次、优化器更新 2 次,两步 replay 均匹配(每次 54 个 int64 摘要)。使用已有 rope.asc_complex NPU override,禁用 cudagraph_pass,输入为合成 token。

其他信息

  • 临时 patch 的上游修复 PR合入后删除。
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for jiangna1111's contribution.)
jiangna1111jiangna1111Collaborators
Nov 2 Created pull request, commit 147b5a4b
atomgit-bot
atomgit-botCollaborators
Nov 2 Comments:

变更摘要

本 PR 将上游 TorchTitan 的 SDC replay(静默数据损坏重放)能力适配到本仓 NPU Trainer:新增实例级 adapter install_npu_sdc_adapter,复用上游 SDCReplayer 的 replay 状态机,仅替换实例的 _signature 方法,把官方 uint64 摘要按位 view 为 int64 后再搬到目标设备,以规避 NPU 对无符号整型 collective 的限制并保留完整 64 位内容。同时在 TrainerEx 中增加默认关闭、显式开启的配置校验与接线,禁止不支持的组合;并补充一条单元测试与一条短 NPU 集成回归用例,用于验证开启/关闭 replay 时训练结果一致。

主要改动

  • 新增 NPU 签名 adapter:torchtitan_npu/extensions/torchtitan/observability/sdc_replayer.py 新增 _npu_signature 与 install_npu_sdc_adapter,对 loss、CPU/加速器 RNG 状态、buffer 与梯度逐项生成 schema 与 digest,空张量和 None 统一记为 0,复杂张量转 torch.view_as_real,并对哈希结果先 .view(torch.int64) 再跨设备搬运。
  • Trainer 接线与配置校验:TrainerEx.Config._validate_npu_sdc_replay 在启用 sdc_replayer 时校验并拒绝 compile、流水并行、CUDA Graph 关闭之外的情形、CPU offload、anticipatory、EMA、sdc.gradient_enabled/with_checksum/hccl_mode、非 AdamW 优化器、非 DCPCheckpointManager.Config 检查点以及三类 optimizer override,并校验 NPU_ASD_CONFIG/NPU_ASD_ENABLE 必须处于关闭状态。
  • Trainer 初始化流程接入:TrainerEx.__init__ 在量化与模型初始化前调用 config._validate_npu_sdc_replay(),并在 super().__init__ 之后对已构造的 self.sdc_replayer 安装 NPU adapter。
  • Graph Trainer 显式拒绝:GraphTrainerEx.__init__ 在 config.sdc_replayer is not None 时抛出 ValueError,避免在图捕获路径下启用 replay。
  • 新增测试与集成套件:新增单测 test_signature_preserves_all_64_bits_as_signed_digests 验证摘要为 int64 且不经过数值化 uint64 转换;新增 tests/integration_tests/sdc_replay.py 与 sdc_replay_config.py(ReplayValidationTrainer 校验 batch/token/optimizer 调用与状态哈希一致性),并在 run_tests.py 注册 sdc_replay 套件、为 dsv4_sdc_replay_ga2 放开 checkpoint/EMA 迁移拦截。
likedislike
Incorrect?
atomgit-bot
atomgit-botCollaborators
Nov 2 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Nov 2 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Nov 2 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 ✅ hwcaifubi, lrwei0709 (2/2) ✅ hwcaifubi (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
85 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
29 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
29 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
29 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