已合并
test: 补齐torch.fx.experimental.symbolic_shapes NPU 适配验证与统一运行脚本 #36872
cuiyunhao-2026创建于 5月27日
test: 补齐torch.fx.experimental.symbolic_shapes NPU 适配验证与统一运行脚本 #36872
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 cuiyunhao-2026 的贡献)5月27日 创建了 pull request,commit dd1dc25f
5月27日 关联了issue:【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(19)
ascend-robot
5月27日 评论:
5月27日 评论:
ascend-robot
5月27日 评论:
5月27日 评论:
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
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| test | ✅ chenrayray, huangjingwei (2/2) | ✅ chenrayray (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
cuiyunhao-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月27日 添加了label:ascend-cla/yes
此处折叠了201条消息 查看更多
7月6日 删除了label:ci-pipeline-running
7月6日 添加了label:ci-pipeline-passed
ascend-robot
7月6日 评论:
7月6日 评论:
流水线 PR-pipeline_pytorch#41615 [ commitID:586d8b30 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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月6日 合入了pull request
ascend-robot
7月6日 评论:
7月6日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch/issues/1625
【修改方案】
完善 Torch-NPU 对
torch.fx.experimental.symbolic_shapes.ShapeEnv类 5 个 API 在 NPU 环境下的兼容性验证,覆盖以下 API:1. 上游社区用例情况分析
在 PyTorch 上游仓库(github.com/pytorch/pytorch)中搜索这 5 个 API:
format_guards:仅在test/functorch/test_aotdispatch.py(第10150行)和test/test_proxy_tensor.py(第1963行)中间接调用,无直接 API 验证用例freeze:上游 test/ 目录下无任何ShapeEnv.freeze()的直接调用freeze_runtime_asserts:上游 test/ 目录下无任何调用get_axioms:上游 test/ 目录下无任何直接调用(仅在torch/_inductor/sizevars.py等内部使用)get_implications:上游 test/ 目录下无任何直接调用(仅在symbolic_shapes.py内部被其他方法调用)上游
test/fx/目录下不存在test_symbolic_shapes.py文件,该文件为 torch-npu 社区自建。结论:5 个 API 均属于上游"无直接用例"场景,按 1.3 规范自写用例,提交到 torch-npu 的 test 目录。
2. NPU 适配方案
5 个 API 均为
ShapeEnv类的纯 Python 方法,操作 sympy 符号表达式与内部状态,不涉及张量计算和 NPU 算子调用,在 NPU 上行为与 CPU 完全一致,无需做任何 NPU 适配修改。3. 新增测试用例
在已有
test/fx/test_symbolic_shapes.py的TestShapeEnvNPU类中追加 5 个测试方法:test_torch_fx_experimental_symbolic_shapes_ShapeEnv_format_guardstest_torch_fx_experimental_symbolic_shapes_ShapeEnv_freezetest_torch_fx_experimental_symbolic_shapes_ShapeEnv_freeze_runtime_assertstest_torch_fx_experimental_symbolic_shapes_ShapeEnv_get_axiomstest_torch_fx_experimental_symbolic_shapes_ShapeEnv_get_implications4. API 补齐
不需要。5 个 API 均为纯 Python 方法,在 NPU 上运行结果与 CPU 完全一致。
5. 多版本分支合入
文档 PR:https://gitcode.com/Ascend/pytorch/pull/36879
【资料变更】
涉及。
torch.fx.experimental.symbolic_shapes下的 5 个 API 实际已支持,但docs/zh/native_apis中缺少对应文档。v2.7.1 分支资料变更内容:
docs/zh/native_apis/pytorch_2-7-1/torch-fx-experimental-symbolic_shapes.md、pytorch_2-9-0/torch-fx-experimental-symbolic_shapes.md、pytorch_2-10-0/torch-fx-experimental-symbolic_shapes.md、pytorch_2-11-0/torch-fx-experimental-symbolic_shapes.md、pytorch_2-12-0/torch-fx-experimental-symbolic_shapes.mdPyTorch-*.md,添加子模块链接API 支持情况:
资料 PR 仅合入 v2.7.1 分支,刷新 pytorch_2-7-1、pytorch_2-9-0、pytorch_2-10-0、pytorch_2-11-0、pytorch_2-12-0 五个版本的 API 支持情况。v2.9.0 及以后分支无
docs/zh/native_apis目录,无需处理。【接口变更】
不涉及(无新增/修改对外 C++ 或 Python 接口,仅新增测试与文档)
【功能验证】
1. 测试环境
2. 测试命令
cd <pytorch-repo-root> python test/fx/test_symbolic_shapes.py3.测试结果

4.与上游用例的关系
【CheckList】