Closed
test(export): add NPU adaptation for torch.compiler.is_exporting testcase #42199
makun-2026Add on Jul 20Closed at Aug 17
test(export): add NPU adaptation for torch.compiler.is_exporting testcase #42199
Closed
makun-2026Add on Jul 20Closed at Aug 17
makun-2026
Jul 20

【合入来源】

关联 issue:

【修改方案】

本 PR 在 test_upstream/test/export/test_export.py.patch 中补充 torch.compiler.is_exporting 的 API 一致性验证用例适配。

torch.compiler.is_exporting 用于判断当前是否处于 torch.export 追踪上下文,属于公开的非计算类 Python 状态查询 API。

任务 API 功能、社区用例情况与本 PR 动作梳理如下:

API 功能说明 社区用例情况 / 缺失分析 本 PR 动作
torch.compiler.is_exporting 判断当前是否处于 torch.export 追踪上下文的状态查询 API PyTorch 官方 test/export/test_export.py 已有 TestExport::test_is_exporting 直接验证该 API;当前 torch-npu v2.11.0 的 test_upstream 原本不含对应 patch 在对应 test_upstream patch 中对 test_is_exporting 做最小 NPU 适配,使传入 export() 的张量运行在 NPU 上

主要分析思路:

  1. 在 PyTorch 官方社区检索 torch.compiler.is_exporting,确认已有 test/export/test_export.py::TestExport::test_is_exporting 直接专项用例。
  2. 该 API 为公开非计算类状态查询接口,核心验证点是 export 追踪态返回 True、普通执行态返回 False,API 实现无需修改。
  3. 本 PR 仅对社区已有用例做最小 NPU 适配:保持用例结构不变,将传入 export() 的张量迁移到 NPU。
  4. 本 PR 仅补充 test_upstream patch,不修改 torch.compiler.is_exporting API 实现,不改变现有接口行为。

修改涉及文件:

test_upstream/test/export/test_export.py.patch

本 PR 覆盖的社区用例及验证点如下:

测试方法 覆盖验证点
TestExport.test_is_exporting torch.export 追踪过程中 torch.compiler.is_exporting() 返回 True;普通执行路径返回 False;传入 export() 的张量运行在 NPU 上

【资料变更】

不涉及本 PR。torch.compiler.is_exporting 为公开非计算类 API,资料支持情况在 master 分支统一补充。

【接口变更】

不涉及。本 PR 仅补充 test_upstream patch,不修改 API 实现,不改变现有接口行为,不新增 torch-npu 对外接口。

【功能验证】

运行环境:

操作系统:Ubuntu 22.04.5 LTS
昇腾硬件信息:910B4
CANN软件版本:9.0.0
深度学习框架版本:torch 2.11.0、torch-npu 2.11.0

执行命令:

python test/export/test_export.py TestExport.test_is_exporting -v

执行结果:

Ran 1 test

OK

测试验证结论:

  1. torch.compiler.is_exporting 在 export 追踪过程中返回 True,在普通执行路径返回 False;
  2. API 行为与 PyTorch 社区一致;
  3. 用例中涉及张量的部分运行在 NPU 上;
  4. 本 PR 不修改 API 实现,不涉及接口变更。

【CheckList】

likedislike
The current Pull Request has been closed by ascend-robot.
makun-2026makun-2026
Jul 20 Created pull request, commit b8bcbc27
makun-2026makun-2026
Jul 20 Associated issue: 【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(96)
atomgit-bot
atomgit-bot
Jul 20 Comments:

变更摘要

此 PR 为 torch.compiler.is_exporting 的测试用例增加 NPU(昇腾)适配。torch.compiler.is_exporting 本身是纯 Python 状态查询 API,无需硬件适配,但测试用例中的输入张量需要迁移到 NPU 设备上才能正常运行。该变更是对已有 patch 文件 test_upstream/test/export/test_export.py.patch 的补充,将 test_is_exporting 用例中传给 export() 的两个输入张量从 CPU 改为 NPU 设备。

主要改动

  • 测试输入张量迁移至 NPU:将 test_is_exporting 用例中 export() 调用的第一个参数从 torch.tensor(False) 改为 torch.tensor(False).npu()。
  • 随机张量迁移至 NPU:将同一 export() 调用的第二个参数从 torch.randn(3, 4) 改为 torch.randn(3, 4).npu()。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 20 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
106 messages are collapsed here。 See more
ascend-robotascend-robotCollaborators
Aug 13 Removed label: ci-pipeline-running
ascend-robotascend-robotCollaborators
Aug 13 Added label: ci-pipeline-passed
ascend-robot
ascend-robotCollaborators
Aug 13 Comments:
流水线 PR-pipeline_pytorch#60540 [ commitID:3f076c20 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 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, WSs_321]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
makun-2026
makun-2026
Aug 17 Comments:

/close

likedislike
ascend-robotascend-robotCollaborators
Aug 17 Close pull request