已合并
add_npu_backend_init_log #39399
cuiduo创建于 6月26日
add_npu_backend_init_log #39399
已合并
cuiduo创建于 6月26日
cuiduo
cuiduo成员
6月26日

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

【修改方案】

修复dvm后端stream报错的问题,增加使用后端提示信息

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

UT已通过

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 cuiduo 的贡献)
cuiduocuiduo成员
6月26日 创建了 pull request,commit 66719ae8
ascend-robotascend-robot成员
6月26日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
6月26日 评论:

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

likedislike
ascend-robotascend-robot成员
6月26日 添加了label:needs-issue
ascend-robot
ascend-robot成员
6月26日 评论:

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 .

likedislike
ascend-robot
ascend-robot成员
6月26日 评论:

当前仓库存在以下 保护分支

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,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
ascend-robot
ascend-robot成员
6月26日 评论:

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

likedislike
ascend-robot
ascend-robot成员
6月26日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
6月26日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
6月26日 评论:

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

likedislike
ascend-robotascend-robot成员
6月26日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
6月26日 添加了label:docs-ci-pipeline-success
cuiduo
cuiduo成员
6月26日 评论:

compile

likedislike
ascend-robotascend-robot成员
6月26日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
6月26日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
6月26日 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
6月26日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
6月26日 评论:

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

likedislike
ascend-robotascend-robot成员
6月26日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
6月26日 添加了label:docs-ci-pipeline-success
atomgit-bot
atomgit-bot
6月26日 评论:

变更摘要

此 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 中移除了一行代码(推测为冗余或不必要的语句),保持测试代码整洁。
likedislike
atomgit-bot
atomgit-bot
6月26日 评论:

代码审查

测试文件 test_add_sum.pyimport 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

💬 仅评论

likedislike
atomgit-bot
atomgit-bot6月26日进行代码检视1
torch_npu/utils/_dynamo.py
@@ -253,1 +254,3 @@
253- 
254+ if backend=="dvm":
255+ with _NpuBackendScope(backend):
256+ log.info("Running dvm backend")
atomgit-bot
atomgit-bot6月26日评论:

🟡 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)
应用建议
likedislike
ascend-robotascend-robot成员
6月26日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
6月26日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
6月26日 评论:
流水线 PR-pipeline_pytorch#39392 [ commitID:3f2f57d5 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 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 >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
cuiduocuiduo成员
6月26日 修改了pull request 的描述
此处折叠了6条事件消息 查看更多
cuiduocuiduo成员
6月27日 修改了pull request 的描述
zichun_ye
zichun_ye成员
6月27日 评论:

/approve

likedislike
ascend-robotascend-robot成员
6月27日 添加了label:approved
cuiduocuiduo成员
6月27日 解决了最后一个问题
suhaibo成员
6月27日 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
6月27日 添加了label:lgtm
ascend-robotascend-robot成员
6月27日 合入了pull request
ascend-robot
ascend-robot成员
6月27日 评论:

Pull Request 已合并或已关闭。

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

likedislike
ascend-robot
ascend-robot成员
6月27日 评论:
流水线 pytorch_gitcode_PR_multiVersion#11417 [ commitID:3f2f57d5 ] 已完成
likedislike