已开启
test(dynamo): cover assume_constant_result on NPU #42033
2501_93637465创建于 7月18日
test(dynamo): cover assume_constant_result on NPU #42033
已开启
合并受阻
7月18日 创建了 pull request,commit 6190314c
7月18日 关联了issue:【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(93),[API一致性] torch.compiler.assume_constant_result NPU兼容性测试补齐
7月18日 关联了issue:【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(93),[API一致性] torch.compiler.assume_constant_result NPU兼容性测试补齐
atomgit-bot
7月18日 评论:
7月18日 评论:
变更摘要
本次 PR 为 torch.compiler.assume_constant_result API 新增 NPU 兼容性功能测试,验证该 API 在 Ascend NPU 设备上的行为正确性。主要验证 API 返回原函数对象、NPU Tensor 可被 torch.compile 正常捕获、编译后连续执行结果一致,以及被标记函数的结果在编译期间被视为常量仅计算一次。
主要改动
- 新增测试文件
test/dynamo/test_assume_constant_result.py:为torch.compiler.assume_constant_result添加独立的 NPU 单元测试,包含TestAssumeConstantResult测试类和一个test_assume_constant_result测试方法。 - 验证 API 返回原函数对象:通过
self.assertIs(marked_constant_scale, constant_scale)断言assume_constant_result的返回值与原函数是同一对象。 - 验证 NPU Tensor 编译执行正确性:使用
torch.compile(fn, backend="eager", fullgraph=True)编译函数,传入 NPU Tensor 并连续执行两次,分别验证结果与预期值一致。 - 验证常量函数仅计算一次:通过在
constant_scale中维护call_count计数器,断言编译执行后call_count == 1,确认被标记函数在编译期间被视为常量,仅调用一次。 - 同步 NPU 执行以捕获异步错误:在断言前调用
torch_npu.npu.synchronize(),确保 NPU 异步执行完成,使异步报错能被测试及时捕获。


ascend-robot
7月18日 评论:
7月18日 评论:
atomgit-bot
7月18日 评论:
7月18日 评论:
代码审查
审查总结
审查覆盖文件:
test/dynamo/test_assume_constant_result.py— 已审查(发现 1 个 P3 可选改进项)
问题统计:
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 0 |
| P3 | 1 |
整体风险评估:低风险。
该测试文件逻辑正确,API 使用得当,与代码库中现有的 NPU 测试风格一致。device_type 的模块级获取方式、torch._dynamo.reset() 的调用模式、backend="eager" 的使用、torch_npu.npu.synchronize() 的同步保证、以及 call_count == 1 对常量只计算一次的核心验证均无问题。唯一发现的是张量断言方式可改进以获得更好的失败诊断信息(P3,可选)。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


此处折叠了139条消息 查看更多
17 天前 添加了label:docs-ci-pipeline-success
17 天前 删除了label:ci-pipeline-running
17 天前 添加了label:ci-pipeline-passed
ascend-robot
17 天前 评论:
17 天前 评论:
流水线 PR-pipeline_pytorch#62167 [ commitID:39b7c260 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_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-robot
17 天前 评论:
17 天前 评论:
The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


【合入来源】
任务来源:https://gitcode.com/Ascend/pytorch/issues/2990
关联 Issue:https://gitcode.com/Ascend/pytorch/issues/3036
Fixes #3036
API:
torch.compiler.assume_constant_result目标分支:
v2.12.0【修改方案】
PyTorch 官方社区已在
test/dynamo/test_decorators.py中提供torch.compiler.assume_constant_result的功能测试。按照 API 一致性指南 1.1 类要求,本 PR 不再新增独立测试文件,
而是在以下路径提交由
git diff生成的 NPU 适配 patch:test_upstream/test/dynamo/test_decorators.py.patch适配内容:
torch_npu。不涉及 API 或算子实现代码修改。
PyTorch 上游已有 assume_constant_result 测试场景,因此本 PR 不新增独立的 test/ 测试文件,而是在 test_upstream/test/dynamo/test_decorators.py.patch 中对上游测试补充 NPU Tensor 适配。
Patch 保留上游原有测试逻辑,仅将测试 Tensor 迁移到 NPU,用于验证现有上游场景在 Ascend NPU 环境下的兼容性。
【资料变更】
API 支持资料由 PR !42850 统一更新,覆盖 PyTorch 2.7.1、2.9.0、
2.10.0、2.11.0 和 2.12.0。
【接口变更】
不涉及接口定义变更,仅适配 PyTorch 官方测试在 NPU 上运行。
【功能验证】
python -m py_compilegit diff --check【CheckList】