Closed
test(export): add NPU adaptation for torch.compiler.is_exporting testcase #42197
makun-2026Add on Jul 20Closed at Aug 17
test(export): add NPU adaptation for torch.compiler.is_exporting testcase #42197
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.7.1 的 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.7.1、torch-npu 2.7.1

执行命令:

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 e588f741
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 适配。在已有的 test_upstream/test/export/test_export.py.patch 补丁基础上,新增对 test_is_exporting 用例中 CPU 张量的 .npu() 转换,使测试用例在 NPU 环境下可正常运行。torch.compiler.is_exporting 本身为纯 Python 状态查询 API,无设备依赖,无需修改实现。

主要改动

  • test_export.py.patch 新增张量 NPU 适配:在 test_is_exporting 测试用例的 export() 调用中,对 torch.tensor(False) 和 torch.randn(3, 4) 分别追加 .npu() 调用,确保输入张量位于 NPU 设备上。
  • 补丁行号偏移更新:原补丁文件的 index 行从 c7e70ad..4c0aa5c 更新为 c7e70ad..7b18e86,反映社区源文件版本变化后的补丁重新生成。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 20 Comments:

代码审查

经过仔细审查,此变更内容清晰且格式正确:

  1. Patch 格式:新增的 hunk(@@ -2571,8 +2571,8 @@)格式正确,上下文行、删除行(-)、新增行(+)均符合 unified diff 规范。行数统计(原文件 8 行、新文件 8 行)与 hunk 头一致。

  2. 变更内容:对 test_is_exporting 测试中的两个 CPU 张量(torch.tensor(False)、torch.randn(3, 4))增加了 .npu() 调用,将其迁移至 NPU 设备,与同 patch 文件中其他 hunks 的适配模式(cuda → npu)保持一致。

  3. 语义正确性:torch.compiler.is_exporting() 是无硬件依赖的纯 Python 状态查询 API,测试中传入的张量仅作为 torch.export.export() 的示例输入用于 tracing,迁移至 NPU 不会改变测试的核心断言(FileCheck 检查图中 torch.ops.aten.sin 操作的存在性)。

  4. hunk 排序:新增 hunk(行 2571)正确插入在已有 hunk(行 6559)之前,符合 unified diff 按行号升序排列的要求。

  5. 索引更新:index c7e70ad..4c0aa5c → index c7e70ad..7b18e86,反映了 patch 内容变更后的新 blob hash,属于正常更新。

未发现任何逻辑错误、格式问题、安全风险或回归风险。


审查结论:

文件 审查结果
test_upstream/test/export/test_export.py.patch 无问题
  • 各优先级问题数:P0: 0, P1: 0, P2: 0, P3: 0
  • 整体风险判定:低 — 此变更为标准的 NPU 测试适配,改动范围小、模式与已有适配一致。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
Incorrect?
124 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-failed
ascend-robot
ascend-robotCollaborators
Aug 13 Comments:
流水线 PR-pipeline_pytorch#60536 [ commitID:58773a7b ] 运行失败
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 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