Pull Request已成功合入, 合并人@CANN-robot
(感谢 zzyyjj012 的贡献)变更摘要
本 PR 基于「代码结构规范刷新和重构」建立 torchtitan-npu 的目标 Agent 规则体系与目标架构说明(新增根目录及各目标目录的 AGENTS.md、目标架构文档和架构提案,并将各 Agent 入口统一到根规则),同时配套新增 pre-commit 检查以防止多个 extensions/torchtitan 模块对同一上游完整目标直接做 monkey-patch。本 PR 只定义目标布局和开发守则,不迁移历史生产代码,不改变训练、checkpoint 或数值语义;TORCHTITAN_NPU_DISABLE_EXTENSIONS 与 TORCHTITAN_NPU_DISABLE_COMPONENTS 被明确标注为待迁移时实现的目标接口,当前不可用。
主要改动
- 新增 pre-commit 钩子
extension-patch-ownership:在.pre-commit-config.yaml的本地 hooks 中新增该检查项,以python3 scripts/check_extension_patch_ownership.py作为入口,并在 pre-commit 阶段执行(pass_filenames: false)。 - 新增检查脚本
scripts/check_extension_patch_ownership.py:通过 AST 解析 extensions 根目录下所有 Python 文件,识别对上游目标(torch、torch_npu、torchtitan)的 monkey-patch 赋值;仅允许extensions/torchtitan下的模块进行 patch 且每个上游目标只能有一个所有者,拒绝组件层(components)的 patch、同一目标的重复所有者以及经 import alias 赋值的替换方式。 - 新增单元测试
tests/unit_tests/tooling/test_extension_patch_ownership.py:覆盖三种场景——单个torchtitan所有者通过检查、重复上游所有者被拒绝、组件层 monkey-patch 与 import alias 用法均被拒绝。


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, xuyujun (2/2) | ✅ lrwei0709, xuyujun (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zzyyjj012, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
本 PR 对 torchtitan-npu 的目录结构和仓库开发规则和PR 代码结构规范刷新和重构进行阶段性整理,使代码归属、自动注入边界和第三方适配层更加明确,方便后续开发者及 Agent 理解和维护代码。
本次修改以目录迁移、导入路径调整和文档补充为主,不改变训练流程、配置默认值、量化 recipe、算子实现或数值逻辑。
规则与架构说明
AGENTS.md,明确目录职责、依赖方向、注入顺序和测试分层。docs/architecture.md,统一说明patches → extensions的目标注入关系。TORCHTITAN_NPU_DISABLE_EXTENSIONS与TORCHTITAN_NPU_DISABLE_COMPONENTS目前只是目标接口,尚未实现,不能作为运行时配置使用。目录迁移
torchtitan_npu/distributed/:HF32 配置 helper 原样迁入extensions/torchtitan/trainer.py。compile/sdc_checksum.py迁入extensions/compile/。interfaces/torchao_converter.py迁入extensions/adaptor/torchao/converter.py;adaptor/统一纳入 extensions 层。scripts/迁入tools/,删除patches/torchtitan/scripts/的无调用转发层。patches/workaround/:Torch NPU workaround 迁入patches/torch_npu/,eager_flex.py迁入extensions/torchtitan/。extensions/torchtitan/镜像目录,将有明确上游 owner 的 Trainer、components、FSDP、EP process group、graph trainer、TorchFT、profiler 和工具扩展迁入对应路径。兼容性
extensions/adaptor/保持按需导入,不加入 extensions 包入口的自动导入链。类型
Checklist:
如何测试
完整 UT 过程中发现的两个
test_trainer.py模块名冲突已经通过将 TorchFT 测试重命名为test_torchft_trainer.py修复。其他信息