The current Pull Request has been closed by Zky0803.
变更摘要
本 PR 为 torch.onnx.ONNXProgram.release 在 Torch-NPU 运行环境下新增直接单元测试(PyTorch 社区无该方法的直接用例),仅新增测试文件 test/npu/test_onnx_program_release.py(新增 3 个测试用例),不改动 API 实现。测试通过 object.__new__(torch.onnx.ONNXProgram) 构造实例并注入桩对象,覆盖 release() 的返回值、inference session 释放、临时目录清理及重复调用幂等性等行为。
主要改动
- 新增测试文件
test/npu/test_onnx_program_release.py: 基于TestCase定义TestONNXProgramRelease测试类,通过_InferenceSession、_TemporaryDirectory桩类验证release()行为,并注册import torch_npu以在 NPU 环境运行。 test_release_clears_inference_session: 使用weakref持有 session 引用,验证release()返回None、清空_inference_session和_tempdir,并在gc.collect()后弱引用失效,证明原 inference session 的强引用被解除。test_release_cleans_temporary_directory: 通过带cleanup_called标志的_TemporaryDirectory桩验证release()会调用临时目录的cleanup(),随后_tempdir与_inference_session均被置空。test_release_is_idempotent: 对同一实例连续两次调用release(),断言两次均返回None且属性保持清空状态,验证方法重复调用的幂等性。


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: huangyunlong2022, medivh-x, wangqiang160, weizhan4, 楚浩田) | ❌ (0/1)(You can also ask: zhenyu10, 王朝, zyw-hw, wangmin0104, anyrenwei) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies 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. 👍


当前仓库存在以下 保护分支 :
| 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,将立即执行同步操作
注意:
- /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 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


ascend docs pipeline is running...


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


compile


ascend docs pipeline is running...


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


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/sync


【合入来源】
任务来源:【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12)
结果记录:【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12)
【分支信息】
【复审修正】
根据 Skill 审核反馈,本 PR 已完成:
【路径选择依据】
该目标分支的 PyTorch 社区对应文件为:
目标 API 属于 ONNX exporter 模块。本次测试放在社区一致的
test/onnx/exporter/层级,并使用独立文件test_onnx_program_release.py,不再放置于通用test/npu/目录。【修改内容】
仅新增:
测试覆盖:
修正后导入:
import torch from torch_npu.testing.testcase import TestCase, run_tests本测试不创建与目标行为无关的 NPU Tensor,不修改 API 实现、
Torch-NPU C++ 或 NPU Kernel。
【变更范围】
测试文件 SHA-256:
【功能验证】
本地使用项目现有 PyTorch/Torch-NPU 2.12 运行环境进行参考验证;master 精确开发版本兼容性以修正提交触发的最新 CI 为准。
测试命令:
env -u PYTHONPATH PYTHONNOUSERSITE=1 \ <目标版本 Python> test/onnx/exporter/test_onnx_program_release.py -v测试结果:
【接口与资料变更】
不涉及公开接口签名或行为变更,不涉及 Torch-NPU C++、NPU Kernel
或公开资料修改。
【CheckList】