Closed
【API一致性任务】[Usage]: torch.compiler.is_exporting 官方用例无需NPU适配 #4101
makun-2026Add on Aug 17Closed at Sep 18
Aug 17 associated Kanban: FrameworkPTAdapter 版本issue看板
Aug 17 Added label: help-wantedevent: api-consistencybot-triaged
TorchNPU-Bot
Aug 17 Comments:
Aug 17 Comments:
检测到社区任务相关 issue,自动添加标签:event: api-consistency、help-wanted


Aug 17 Modify description of issue
Aug 17 Modify description of issue
Aug 27 Modify description of issue
Aug 27 Modify description of issue
Aug 27 Modify description of issue
Sep 8 Modify description of issue
Sep 18 Close issue
Sep 18 changed custom state from TODO to CLOSED
Sep 18 Added label: resolved
关联任务:https://gitcode.com/Ascend/pytorch/issues/2993
原三版本验证环境(Ascend 310P3)
2.7.1+cpu,torch_npu2.7.1.post82.11.0+cu130,torch_npu2.11.02.12.0+cu130,torch_npu2.12.0一、API功能
torch.compiler.is_exporting用于查询当前执行是否处于torch.export追踪上下文:追踪过程中返回True,普通执行路径返回False。该接口为纯Python状态查询API,不接收或返回Tensor,不执行算子,不依赖NPU kernel或输入Tensor所在设备。
二、PyTorch社区用例情况
PyTorch官方社区已有直接专项用例:
该用例在
torch.export追踪期间调用torch.compiler.is_exporting(),并直接检查:aten.sin和higher_order.cond节点;torch.cond的true分支包含预期的aten.sin和aten.sub节点;torch.cond的false分支包含预期的aten.sin和aten.add节点。三个版本官方原始用例中的输入为:
torch.tensor(False) torch.randn(3, 4)目标API只查询export追踪状态,输入Tensor设备不改变该状态查询逻辑。
三、NPU适配分析
此前曾在
test_upstream/test/export/test_export.py.patch中尝试将辅助输入Tensor迁移到NPU。重新核对后确认:torch.compiler.is_exporting本身没有Tensor入参和device入参;因此,按照最新版《TorchNPU API一致性说明文档》
1.1②,本任务无需提交NPU适配patch,采用Issue说明方式交付。四、Ascend 310P3验证方法与结果
执行的测试均来自未应用torch-npu patch的PyTorch官方
test/export/test_export.py:python test/export/test_export.py TestExport.test_is_exporting -vv2.7.1,commite2d141dbde55c2a4370fac5165b0561b6af4798bRan 1 test in 0.325s,exit 0v2.11.0,commit70d99e998b4955e0049d13a98d77ae1b14db1f45Ran 1 test in 10.114s,exit 0v2.12.0归档,SHA256f2b4a82ccb4dc4f10335d459c8d694724d5f89560ae593fb57d543e2ad41c7cfRan 1 test in 6.114s,exit 0运行截图:
验证日志证据包:
task96-original-upstream-validation.tar.gzSHA256:
14876b5fce8593c778842bd21d820f56bf99236273c7fbb38d6f6fb48b19feea五、Ascend950PR A5补充验证
5.1 验证环境
Ascend950PR_9579openEuler 24.03 SP3(Linux6.6.0-132.0.0.111.oe2403sp3.x86_64)9.1.03.12.14本次实际设备输出为
Ascend950PR_9579,因此仅按该实际设备型号记录A5验证结果,不表述为已在Ascend 950DT实测。5.2 验证方法与证据口径
目标API不接收Tensor或device参数,也不执行NPU kernel。A5补充验证分为两部分:
执行命令:
python test/export/test_export.py TestExport.test_is_exporting -vNPU smoke仅用于证明A5设备环境有效,不作为目标API覆盖;目标API覆盖结论来自未修改的PyTorch官方测试。
5.3 逐版本结果
2.7.1+cpu2.7.1.post8Ran 1 test in 0.419s、OK、退出码02.11.0+cpu2.11.0Ran 1 test in 2.095s、OK、退出码02.12.0+cu1302.12.0Ran 1 test in 2.039s、OK、退出码0A5运行截图:
A5完整证据包:
46bed96ab16e4967bc1faa1d0ba98c06.gz
2d6a4671deb2ff647b146c68210b6a2448ee8bd8f55a03d8f3012442b82e78f6证据包包含三个版本各自的环境日志、真实NPU smoke完整日志、官方目标测试完整日志、未修改测试源码、源码来源、源码SHA256、目标测试位置及三版本汇总,并已通过
sha256sum -c校验。六、验证结论
torch.compiler.is_exporting直接专项测试,覆盖目标API在export追踪期间的核心行为;Ascend950PR_9579 + CANN 9.1.0环境完成真实NPU smoke及未修改官方目标测试,均为Ran 1 test、OK、退出码0;test_upstreampatch,也不新增硬件无关的test/用例;Ascend950PR_9579设备陈述,不表述为Atlas A2、Atlas A3或Ascend 950DT逐硬件实测;七、相关PR处理
按最新规则关闭以下不再需要的测试PR: