Closed
[v2.12.0]test: add NPU test for ONNXProgram.release #43597
Zky0803Add on Aug 2Closed at Aug 21
[v2.12.0]test: add NPU test for ONNXProgram.release #43597
Closed
Zky0803Add on Aug 2Closed at Aug 21
Zky0803
Zky0803
Aug 2

【合入来源】

任务来源:【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12)

结果记录:【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12)

【分支信息】

目标分支:v2.12.0
源分支:pr/onnx-program-release-v2.12.0
最新官方基线:544c4771f34a999f92845ff2a7b9ddeaa9522c58
修正前 Commit:4791052df00a1045fd2637b9561bd237c40cb656
修正后 Commit:1ccaeb02cb3c6a0bdac21a7a917b3c925d85aa9a

【复审修正】

根据 Skill 审核反馈,本 PR 已完成:

1. test/npu/test_onnx_program_release.py
   → test/onnx/exporter/test_onnx_program_release.py
2. 删除未使用的 import torch_npu  # noqa: F401

【路径选择依据】

该目标分支的 PyTorch 社区对应文件为:

test/onnx/exporter/test_onnx_program.py

目标 API 属于 ONNX exporter 模块。本次测试放在社区一致的
test/onnx/exporter/ 层级,并使用独立文件
test_onnx_program_release.py,不再放置于通用 test/npu/ 目录。

【修改内容】

仅新增:

test/onnx/exporter/test_onnx_program_release.py

测试覆盖:

test_release_clears_inference_session
test_release_cleans_temporary_directory
test_release_is_idempotent

修正后导入:

import torch
from torch_npu.testing.testcase import TestCase, run_tests

本测试不创建与目标行为无关的 NPU Tensor,不修改 API 实现、
Torch-NPU C++ 或 NPU Kernel。

【变更范围】

ahead_count=1
behind_count=0
changed_files=A test/onnx/exporter/test_onnx_program_release.py
worktree=<clean>

测试文件 SHA-256:

d9587191b1be9cf3f158bbdcc8d81ff747a9f9bddde931e5ebb55a7c275a1bc1

【功能验证】

使用 v2.12.0 对应 Torch-NPU 运行环境完成验证。

测试命令:

env -u PYTHONPATH PYTHONNOUSERSITE=1 \
    <目标版本 Python> test/onnx/exporter/test_onnx_program_release.py -v

测试结果:

test_release_cleans_temporary_directory ... ok
test_release_clears_inference_session ... ok
test_release_is_idempotent ... ok

Ran 3 tests in 2.505s

OK
test_exit_code=0

【接口与资料变更】

不涉及公开接口签名或行为变更,不涉及 Torch-NPU C++、NPU Kernel
或公开资料修改。

【CheckList】

likedislike
The current Pull Request has been closed by Zky0803.
Zky0803Zky0803
Aug 2 Created pull request, commit a5b5dd00
Zky0803Zky0803
Aug 2 Associated issue: 【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12),【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12)
atomgit-bot
atomgit-bot
Aug 2 Comments:

变更摘要

本 PR 为 torch.onnx.ONNXProgram.release 方法补充直接单元测试,新增测试文件 test/npu/test_onnx_program_release.py。由于该方法不接收 Tensor、不执行 NPU 数值计算、不涉及 NPU Kernel,因此仅新增测试覆盖,不修改 API 实现。测试通过 object.__new__ 构造 torch.onnx.ONNXProgram 实例,并借助自定义的 _InferenceSession、_TemporaryDirectory 模拟对象,验证 release() 的返回值、内部状态清理及重复调用幂等性。

主要改动

  • 新增 test_release_clears_inference_session 用例: 验证 release() 返回 None、_inference_session 与 _tempdir 被置空,并通过 weakref 配合 gc.collect() 确认原 inference session 的强引用被解除。
  • 新增 test_release_cleans_temporary_directory 用例: 验证 release() 调用后临时目录对象的 cleanup() 方法被触发(cleanup_called 置为 True),且 _inference_session、_tempdir 均被清空。
  • 新增 test_release_is_idempotent 用例: 验证对已释放的 ONNXProgram 重复调用 release() 仍返回 None,且内部状态保持清空,确保方法幂等。
  • 新增测试辅助类 _InferenceSession 与 _TemporaryDirectory: 用于模拟 release 逻辑所操作的对象,其中 _TemporaryDirectory.cleanup() 记录调用状态以便断言,支撑上述三个测试用例。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 2 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
ascend-robotascend-robotCollaborators
Aug 2 Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
Aug 2 Comments:

CLA Signature Pass

Zky0803, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robot
ascend-robotCollaborators
Aug 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


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
test ❌ (0/2)(You can also ask: 陈豪, probiotics_53, guoqi1024, senzhen-town, 楚浩田) ❌ (0/1)(You can also ask: liujunzhu, chenrayray, crazyDannyBoy, guoqi1024, 褚博宁)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

Zky0803, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robot
ascend-robotCollaborators
Aug 2 Comments:

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

Protected Branch Version Release
master
v2.7.1
v2.9.0
v2.11.0
v2.12.0
v2.10.0
v2.7.1-26.1.0
v2.9.0-26.1.0
v2.11.0-26.1.0
v2.10.0-26.1.0
v2.12.0-26.1.0
ci-test

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
ascend-robotascend-robotCollaborators
Aug 2 Added label: ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Aug 2 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Aug 2 Added label: docs-ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Aug 2 Comments:

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

likedislike
ascend-robotascend-robotCollaborators
Aug 2 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 2 Added label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Aug 2 Removed label: ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 2 Added label: ci-pipeline-passed
ascend-robot
ascend-robotCollaborators
Aug 2 Comments:
流水线 PR-pipeline_pytorch#53281 [ commitID:4791052d ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 ✅ >>>
Build_ARM ✅ >>>
Build_LibTorch_x86 ✅ >>>
Build_LibTorch_ARM ✅ >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison ✅ >>>
编码安全与规范检查 codecheck_pre-commit ✅ >>>
check_error ✅ >>>
lintrunner ✅ >>>
开源片段检查 SCA ✅ >>>
开发者测试 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, shawnylee233, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
Zky0803Zky0803
Aug 3 Pre merge succeeded (commit_id: bb387fe855cbfc375a058f9dadf820691092b90f)
Zky0803Zky0803
Aug 3 Force-pushed 3 commits:544c4771-2 commits from branch v2.12.0,1ccaeb02-test: add NPU test for ONNXProgram.release
Zky0803Zky0803
Aug 3 Pre merge succeeded (commit_id: b205f850a9e1cc9307c4d3127d5550503fce15c6)
ascend-robotascend-robotCollaborators
Aug 3 Removed label: ci-pipeline-passed
Zky0803
Zky0803
Aug 3 Comments:

compile

likedislike
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Aug 3 Removed label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Aug 3 Added label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 3 Added label: ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:

ascend docs pipeline is running...

likedislike
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:

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

likedislike
ascend-robotascend-robotCollaborators
Aug 3 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 3 Added label: docs-ci-pipeline-success
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:

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

likedislike
ascend-robotascend-robotCollaborators
Aug 3 Removed label: ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 3 Added label: ci-pipeline-failed
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:
流水线 PR-pipeline_pytorch#53331 [ commitID:1ccaeb02 ] 运行失败
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 🕚 >>>
Build_ARM 🕚 >>>
Build_LibTorch_x86 🕚 >>>
Build_LibTorch_ARM 🕚 >>>
Build_X86_torchair 🕚 >>>
Build_ARM_torchair 🕚 >>>
patch_test 🕚 >>>
恶意代码检查 Antipoison ✅ >>>
编码安全与规范检查 codecheck_pre-commit ❌ >>>
check_error ✅ >>>
lintrunner ✅ >>>
开源片段检查 SCA ✅ >>>
开发者测试 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, shawnylee233, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
Zky0803Zky0803
Aug 3 Modify description of pull request
Zky0803
Zky0803
Aug 3 Comments:

compile

likedislike
ascend-robotascend-robotCollaborators
Aug 3 Removed label: ci-pipeline-failed
ascend-robotascend-robotCollaborators
Aug 3 Added label: ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Aug 3 Removed label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Aug 3 Added label: docs-ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:

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

likedislike
ascend-robotascend-robotCollaborators
Aug 3 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 3 Added label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Aug 3 Removed label: ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 3 Added label: ci-pipeline-passed
ascend-robot
ascend-robotCollaborators
Aug 3 Comments:
流水线 PR-pipeline_pytorch#53343 [ commitID:1ccaeb02 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 ✅ >>>
Build_ARM ✅ >>>
Build_LibTorch_x86 ✅ >>>
Build_LibTorch_ARM ✅ >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison ✅ >>>
编码安全与规范检查 codecheck_pre-commit ✅ >>>
check_error ✅ >>>
lintrunner ✅ >>>
开源片段检查 SCA ✅ >>>
开发者测试 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, shawnylee233, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
Zky0803
Zky0803
Aug 3 Comments:

/sync

likedislike
Zky0803Zky0803
Aug 21 Close pull request