已关闭
test(fx): add ShapeEnv API tests without upstream coverage #36393
小辉懂编程创建于 5月21日关闭于 5月22日
test(fx): add ShapeEnv API tests without upstream coverage #36393
已关闭
小辉懂编程创建于 5月21日关闭于 5月22日
小辉懂编程
5月21日

What type of PR is this?

/kind test

What does this PR do / why do we need it?

This PR adds tests for ShapeEnv APIs that do not have direct upstream test coverage in PyTorch v2.10.0.

Covered APIs:

  • torch.fx.experimental.symbolic_shapes.ShapeEnv.get_pruned_guards
  • torch.fx.experimental.symbolic_shapes.ShapeEnv.is_unbacked_symint

These APIs are Python-level symbolic shape utilities. They are used for ShapeEnv guard pruning and unbacked SymInt identification, and do not involve NPU operator kernels, device-side numerical computation, stream/event management, memory management, or distributed communication.

Which issue(s) this PR fixes?

Related to Torch-NPU API completion work for ShapeEnv APIs.

Modification summary

Modified file:

test/fx/test_symbolic_shapes.py

Changes:

  • Added import sympy.
  • Added test_shape_env_get_pruned_guards to verify ShapeEnv.get_pruned_guards returns a list for unbacked SymInt input.
  • Added test_shape_env_is_unbacked_symint to verify ShapeEnv.is_unbacked_symint returns True for symbols created by create_unbacked_symint, and False for a regular SymPy symbol.

Upstream test coverage analysis

PyTorch v2.10.0 official tests were checked for the target APIs.

Result:

API Official upstream test coverage
ShapeEnv.get_pruned_guards No direct upstream test found
ShapeEnv.is_unbacked_symint No direct upstream test found

Therefore, this PR adds Torch-NPU self-written tests for these two APIs.

Relationship with v2.9.0 work

This PR follows the same test strategy as the v2.9.0 ShapeEnv self-written test PR:

https://gitcode.com/Ascend/pytorch/pull/36356

Test result

Attempted to run:

TORCH_DEVICE_BACKEND_AUTOLOAD=0 python3.11 test/fx/test_symbolic_shapes.py

Result:

Traceback (most recent call last):
  File "/workspace/pytorch/test/fx/test_symbolic_shapes.py", line 5, in <module>
    import torch_npu
  File "/workspace/pytorch/torch_npu/__init__.py", line 15, in <module>
    import torch_npu.utils.patch_getenv
  File "/workspace/pytorch/torch_npu/utils/__init__.py", line 12, in <module>
    from torch_npu.npu.utils import get_cann_version
  File "/workspace/pytorch/torch_npu/npu/__init__.py", line 158, in <module>
    from .utils import (obfuscation_initialize, obfuscation_calculate, obfuscation_finalize,
  File "/workspace/pytorch/torch_npu/npu/utils.py", line 11, in <module>
    import torch_npu._C
ModuleNotFoundError: No module named 'torch_npu._C'

Explanation:

The failure occurs during import torch_npu, before entering the added test cases. The current Web IDE environment is a Torch-NPU source checkout without the built torch_npu._C extension loaded. This is an environment/build artifact issue, not a failure of the added ShapeEnv test logic.

Special notes for reviewers

  • This PR only adds test coverage for APIs without direct upstream coverage.
  • It does not modify API implementation.
  • It does not involve NPU kernel behavior or numerical computation.
  • ShapeEnv.produce_guards and ShapeEnv.get_nontrivial_guards are handled separately through an upstream test adaptation patch.
  • ShapeEnv.ignore_fresh_unbacked_symbols already has upstream coverage and is device-independent; for v2.9.0 this was explained in issue #2046.
likedislike
当前Pull Request已关闭, 关闭人@小辉懂编程
小辉懂编程小辉懂编程
5月21日 创建了 pull request,commit cd0541ab
ascend-robot
ascend-robot成员
5月21日 评论:

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: huangjingwei, hbhu_bin, 陈豪, adrian07110, wangqiang160) ❌ (0/1)(You can also ask: wangmin0104, zichun_ye, li_jing_hw, wangqiang160, anyrenwei)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
ascend-robotascend-robot成员
5月21日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
5月21日 评论:

当前仓库存在以下 保护分支 :

Protected Branch Version Release
master
v2.11.0
v2.10.0
v2.9.0
v2.7.1
v2.12.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
小辉懂编程
小辉懂编程
5月21日 评论:

compile

likedislike
ascend-robotascend-robot成员
5月21日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
5月21日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
5月21日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
5月21日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
5月21日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
5月21日 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
5月21日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
5月21日 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
5月21日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
5月21日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
5月21日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
5月21日 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
5月21日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
5月21日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
5月21日 评论:
流水线 PR-pipeline_pytorch#24892 已完成
阶段 任务名 状态 详情
编译构建 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 🛑 >>>
流水线 PR-pipeline_pytorch ✅ >>>
此流水线已支持下列评论快捷指令,仅PR创建者评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
小辉懂编程小辉懂编程
5月22日 关闭了 pull request