The current Pull Request has been closed by ascend-robot.
变更摘要
此 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,反映社区源文件版本变化后的补丁重新生成。


代码审查
经过仔细审查,此变更内容清晰且格式正确:
-
Patch 格式:新增的 hunk(
@@ -2571,8 +2571,8 @@)格式正确,上下文行、删除行(-)、新增行(+)均符合 unified diff 规范。行数统计(原文件 8 行、新文件 8 行)与 hunk 头一致。 -
变更内容:对
test_is_exporting测试中的两个 CPU 张量(torch.tensor(False)、torch.randn(3, 4))增加了.npu()调用,将其迁移至 NPU 设备,与同 patch 文件中其他 hunks 的适配模式(cuda→npu)保持一致。 -
语义正确性:
torch.compiler.is_exporting()是无硬件依赖的纯 Python 状态查询 API,测试中传入的张量仅作为torch.export.export()的示例输入用于 tracing,迁移至 NPU 不会改变测试的核心断言(FileCheck检查图中torch.ops.aten.sin操作的存在性)。 -
hunk 排序:新增 hunk(行 2571)正确插入在已有 hunk(行 6559)之前,符合 unified diff 按行号升序排列的要求。
-
索引更新:
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 测试适配,改动范围小、模式与已有适配一致。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 : 停止流水线


/close


【合入来源】
关联 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 动作梳理如下:
torch.compiler.is_exportingtorch.export追踪上下文的状态查询 APItest/export/test_export.py已有TestExport::test_is_exporting直接验证该 API;当前torch-npuv2.7.1 的test_upstream原本不含对应 patchtest_upstreampatch 中对test_is_exporting做最小 NPU 适配,使传入export()的张量运行在 NPU 上主要分析思路:
torch.compiler.is_exporting,确认已有test/export/test_export.py::TestExport::test_is_exporting直接专项用例。True、普通执行态返回False,API 实现无需修改。export()的张量迁移到 NPU。test_upstreampatch,不修改torch.compiler.is_exportingAPI 实现,不改变现有接口行为。修改涉及文件:
本 PR 覆盖的社区用例及验证点如下:
TestExport.test_is_exportingtorch.export追踪过程中torch.compiler.is_exporting()返回True;普通执行路径返回False;传入export()的张量运行在 NPU 上【资料变更】
不涉及本 PR。
torch.compiler.is_exporting为公开非计算类 API,资料支持情况在 master 分支统一补充。【接口变更】
不涉及。本 PR 仅补充
test_upstreampatch,不修改 API 实现,不改变现有接口行为,不新增 torch-npu 对外接口。【功能验证】
运行环境:
执行命令:
python test/export/test_export.py TestExport.test_is_exporting -v执行结果:
测试验证结论:
torch.compiler.is_exporting在 export 追踪过程中返回True,在普通执行路径返回False;【CheckList】