已关闭
test(fx): add ShapeEnv API tests (self-written + upstream patch) for v2.7.1 #36524
小辉懂编程创建于 5月22日关闭于 7月4日
test(fx): add ShapeEnv API tests (self-written + upstream patch) for v2.7.1 #36524
已关闭
当前Pull Request已关闭, 关闭人@小辉懂编程
5月22日 关联了issue:[API补齐] ShapeEnv.ignore_fresh_unbacked_symbols NPU适配无需修改说明
ascend-robot
5月22日 评论:
5月22日 评论:
ascend-robot
5月22日 评论:
5月22日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| test | ❌ (0/2)(You can also ask: ffmh, 陈豪, zichun_ye, wasd1111222, TonyYA) | ❌ (0/1)(You can also ask: guoqi1024, medivh-x, adrian07110, chujinjin, zichun_ye) |
| test_upstream | ❌ (0/2)(You can also ask: wangqiang160, wjlflyer, culechan, chengpeng25, huangjingwei) | ❌ (0/1)(You can also ask: wangmin0104, wasd1111222, chenrayray, zichun_ye, sunyu-xuan) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
gehui-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月22日 添加了label:ascend-cla/yes
此处折叠了700条消息 查看更多
6月30日 添加了label:docs-ci-pipeline-success
6月30日 删除了label:ci-pipeline-running
6月30日 添加了label:ci-pipeline-passed
ascend-robot
6月30日 评论:
6月30日 评论:
流水线 PR-pipeline_pytorch#39991 [ commitID:47797a5a ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | ✅ | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | ✅ | >>> |
| UT_X86_Part_02 | ✅ | >>> | |
| 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 : 停止流水线


7月4日 关闭了 pull request
【关联任务】
【合入来源】
请勿携带内部流程信息。
【背景与目标】
完善 Torch-NPU 对
torch.fx.experimental.symbolic_shapes.ShapeEnv下 5 个 API 在 NPU 环境下的兼容性验证。torch.fx.experimental.symbolic_shapes.ShapeEnv.produce_guardstest_mega_guard/test_guards_equaltorch.fx.experimental.symbolic_shapes.ShapeEnv.get_nontrivial_guardstest_guards_equaltorch.fx.experimental.symbolic_shapes.ShapeEnv.get_pruned_guardstest_shape_env_get_pruned_guardstorch.fx.experimental.symbolic_shapes.ShapeEnv.is_unbacked_syminttest_shape_env_is_unbacked_syminttorch.fx.experimental.symbolic_shapes.ShapeEnv.ignore_fresh_unbacked_symbolstest_shape_env_ignore_fresh_unbacked_symbols【上游社区用例分析】
cd /workspace/pytorch_v2.7.1 grep -rn "produce_guards\|get_nontrivial_guards\|get_pruned_guards\|is_unbacked_symint\|ignore_fresh_unbacked_symbols" test/ --include="*.py"produce_guards/get_nontrivial_guardstest/test_proxy_tensor.py的test_mega_guard(行 1821)、test_guards_equal(行 1889)有覆盖,但运行在 CPU 路径get_pruned_guards/is_unbacked_syminttest/无直接用例ignore_fresh_unbacked_symbolstest_control_flow.py中间接使用)结论:
produce_guards/get_nontrivial_guards通过 patch 做 NPU 路径适配;另外 3 个 API 上游缺失或验证不充分,需新增自写用例。【修改方案】
1. 自写测试:
test/fx/test_symbolic_shapes.py与上游
test/fx/路径一致, 8 个测试方法(TestCase+run_tests):test_shape_env_get_pruned_guardsShapeEnv.get_pruned_guardslist类型test_shape_env_is_unbacked_symintShapeEnv.is_unbacked_syminttest_shape_env_ignore_fresh_unbacked_symbolsShapeEnv.ignore_fresh_unbacked_symbolstest_is_accessor_node_with_call_methodis_accessor_nodetest_is_accessor_node_with_call_functionis_accessor_nodetest_is_concrete_int_with_literal_and_device_shapeis_concrete_int/is_symbolic.size()test_is_concrete_float_with_literal_and_symbolic_valueis_concrete_float/is_symbolictest_is_concrete_bool_with_literal_and_symbolic_valueis_concrete_bool/is_symbolic代码规范(六.8):
torch → torch.fx → torch.testing → sympydevice_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu",张量.to(device_type)切 NPUself.assert*,无print/try/except2. 上游 patch:
test_upstream/test/test_proxy_tensor.py.patch覆盖
test_mega_guard(行 1821)和test_guards_equal(行 1889),最小化修改:test_mega_guardtorch.randn(16), torch.randn(8)→ 各加.npu()test_guards_equal_traceshadow(inps用torch.randn(arg).npu()),调用点 0 改动git diff在 PyTorch v2.7.1 官方源码上生成(六.5)trace_on_device、不引入新函数名3. 多版本合入
每个分支 1 个 squash 提交:
【资料变更】
不涉及本 MR。文档由独立资料 PR #37392 单独合入 v2.7.1,一次性刷新 5 个版本目录的
torch-fx.md。【接口变更】
不涉及。仅新增测试代码,不修改
torch_npu或 PyTorch 任何接口。【功能验证】
测试环境:Ascend 910B4 / PyTorch 2.7.1 / torch_npu / CANN 8.5.0 / Python 3.11.13
cd /tmp && python3.11 /workspace/pytorch/test/fx/test_symbolic_shapes.py测试结果:8 tests OK
Patch 验证:
cd /workspace/pytorch_v2.7.1 patch -p1 --dry-run < /workspace/pytorch/test_upstream/test/test_proxy_tensor.py.patch所有 hunk 应用成功,无冲突。
【CheckList】