Pull Request已成功合入, 合并人@ascend-robot
(感谢 cuiduo 的贡献)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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| test | ✅ zichun_ye, suhaibo (2/2) | ✅ zichun_ye (1/1) |
| torch_npu/utils | ✅ zichun_ye, suhaibo (2/2) | ✅ zichun_ye (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
cuiduo, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Linking Issue Notice
@cuiduo , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1-26.1.0 | ||
| v2.12.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| v2.12.0 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.9.0 | ||
| v2.7.1 | ||
| ci-test | ||
| sync-pr28113--to-v2.9.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


通过PR创建命令启动流水线PR-pipeline_pytorch失败:failure


Ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


compile


Ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


变更摘要
此 PR 主要为 NPU 后端初始化流程增加了日志记录能力。在 torch_npu/utils/_dynamo.py 中的 _InductorNpuRegistry.register_inductor_npu() 方法内添加了初始化日志输出,便于追踪和调试 NPU 后端的加载过程。同时,对测试文件 test/_inductor/test_add_sum.py 做了一行清理。
主要改动
- NPU 后端初始化日志: 在
_InductorNpuRegistry.register_inductor_npu()方法中新增了日志输出,当 NPU backend 被加载时记录初始化信息,提升可观测性。 - 测试文件清理: 在
test/_inductor/test_add_sum.py中移除了一行代码(推测为冗余或不必要的语句),保持测试代码整洁。


代码审查
测试文件 test_add_sum.py 的 import torch_npu 移除是安全的,因为 testutils.py(第8行)已导入 torch_npu,且该测试文件通过 from testutils import TestUtils 间接引入。测试方法中使用的 device="npu" 不受影响。
审查总结
| 文件 | 结果 |
|---|---|
test/_inductor/test_add_sum.py |
无问题(torch_npu 通过 testutils 间接导入,移除是安全的) |
torch_npu/utils/_dynamo.py |
1 个问题 |
- P2:1 个 — dvm 后端缺少
_recovery_all_npu_stream调用,疑似拆分or条件时意外遗漏
总体风险评估:中风险。该变更在 dvm 后端编译路径中移除了 NPU stream 恢复逻辑,可能导致 dvm 后端在设备已初始化后出现 stream 失效问题。建议在合入前补充回 dvm 分支的 _recovery_all_npu_stream 调用,或确认 dvm 后端是否确实不再需要此调用(并补充说明)。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


🟡 Medium Priority
原始代码中,backend=="mlir" or backend=="dvm" 共用同一代码块,其中包含 device_id = torch_npu.npu.current_device() 和 torch_npu._C._recovery_all_npu_stream(device_id) 两条关键调用。本次变更将 or 条件拆分为两个独立 if 块以分别添加日志,但 dvm 分支中丢失了这两条调用,仅保留了 _NpuBackendScope 上下文和新增的 log.info。
_recovery_all_npu_stream 的作用是重建当前 device 上所有 NPU stream(默认 stream、secondary stream 及 pool 中所有 stream)——这是设备初始化/恢复的必须步骤。该 PR 标题为 "add_npu_backend_init_log",描述中未提及要移除 dvm 的 stream recovery,且 torch_npu/_inductor 目录下也未找到 dvm 后端自行调用的替代逻辑。因此该移除高度疑似为拆分条件时意外遗漏。
失败场景:当 backend=="dvm" 且 device 此前已初始化时,dvm 编译流程将跳过 stream 重建,后续可能使用已失效的 stream 导致 NPU 运算异常或 hang。
修复方向:在 dvm 分支的 with _NpuBackendScope(backend): 块内补充回 device_id = torch_npu.npu.current_device() 和 torch_npu._C._recovery_all_npu_stream(device_id) 两行。
建议:在 dvm 分支的 with _NpuBackendScope(backend): 块内,于 log.info("Running dvm backend") 之后补充 device_id = torch_npu.npu.current_device() 和 torch_npu._C._recovery_all_npu_stream(device_id) 两行,与 mlir 分支保持一致。
|
256 | + if backend=="dvm": |
|
257 | + with _NpuBackendScope(backend): |
| 256
| - log.info("Running dvm backend") |
|
258 | + log.info("Running dvm backend") |
|
259 | + device_id = torch_npu.npu.current_device() |
|
260 | + torch_npu._C._recovery_all_npu_stream(device_id) |


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | ✅ | >>> |
| UT_X86_Part_02 | ✅ | >>> | |
| UT_ARM_A3_Part_01 | ✅ | >>> | |
| UT_ARM_A3_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | ✅ | >>> | |
| UT_inductor_Part_02 | ✅ | >>> | |
| UT_inductor_Part_03 | ✅ | >>> | |
| UT_inductor_Part_04 | ✅ | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/approve


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




【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】