已合并
test(fx): add testcases for torch.fx.experimental.symbolic_shapes APIs v2.12.0 #36818
xuanzhi-2026创建于 5月26日
test(fx): add testcases for torch.fx.experimental.symbolic_shapes APIs v2.12.0 #36818
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 xuanzhi-2026 的贡献)5月26日 创建了 pull request,commit a587d4cc
5月26日 关联了issue:【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(22)
ascend-robot
5月26日 评论:
5月26日 评论:
ascend-robot
5月26日 评论:
5月26日 评论:
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 | ✅ 李伟, huangjingwei (2/2) | ✅ 李伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
xuanzhi-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月26日 添加了label:ascend-cla/yes
此处折叠了103条消息 查看更多
Jingwei Huang
6月16日 评论:
6月16日 评论:
/lgtm


6月16日 添加了label:approvedlgtm
6月16日 合入了pull request
ascend-robot
6月16日 评论:
6月16日 评论:
流水线 pytorch_gitcode_PR_multiVersion#10813 [ commitID:a2faf85d ] 已完成


【合入来源】
【任务背景】
本 PR 对应 pytorch-vllm 开源实习项目中的 Torch-NPU API 一致性对齐任务,公开 issue:
https://gitcode.com/Ascend/pytorch/issues/1628
本 PR 是
v2.12.0分支的用例补齐 PR,目标是补齐torch.fx.experimental.symbolic_shapes下 5 个 API 的直接验证用例。同组交付 PR 如下:【API 功能介绍】
torch.fx.experimental.symbolic_shapes.ShapeEnv.size_hintallow_none控制无法求值时是否允许返回None。torch.fx.experimental.symbolic_shapes.ShapeEnv.suppress_guardsShapeEnv提供的上下文管理器,用于在局部代码块内临时抑制 guard 记录,避免辅助求值过程额外生成 guards。torch.fx.experimental.symbolic_shapes.ShapeEnvSettingsShapeEnv的配置数据结构,保存动态 shape 相关开关,例如 scalar output、dynamic output shape、duck shape、deferred runtime assert 等行为配置。torch.fx.experimental.symbolic_shapes.StatefulSymbolicContexttensor_source以及 ShapeEnv/source/symbol 的缓存,用于同一张量符号化过程中的符号复用。torch.fx.experimental.symbolic_shapes.StatelessSymbolicContextdynamic_sizes、dynamic_strides、constraint_sizes、constraint_strides等输入元信息,用于创建符号尺寸时描述动态维约束。【上游社区测试情况】
已基于当前分支基线检索
test目录中的相关覆盖情况:StatelessSymbolicContext在 dynamo export/subclass 场景中被使用,ShapeEnvSettings出现在 public API allowlist 中。ShapeEnv.size_hint、ShapeEnv.suppress_guards、ShapeEnvSettings字段构造、StatefulSymbolicContext/StatelessSymbolicContext默认状态的直接行为断言。test/fx目录新增自写 UT,而不是搬运现有上游 patch。【修改方案 / 用例开发思路】
在
test/fx/test_symbolic_shapes_api.py中新增 5 个直接测试用例:test_shape_env_size_hint:构造ShapeEnv,验证sympy.Integer(8)可返回 size hint8,并检查签名中包含expr、allow_none,且allow_none默认值为False。test_shape_env_suppress_guards:验证ShapeEnv.suppress_guards()可作为上下文管理器使用,并在上下文内完成size_hint求值。test_shape_env_settings:通过dataclasses.fields获取当前版本支持字段,只对当前版本存在的字段构造ShapeEnvSettings,保证跨版本稳定;随后断言配置值可正确保留。test_stateless_symbolic_context:以DimDynamic.DUCK构造StatelessSymbolicContext,验证dynamic_sizes、默认dynamic_strides、constraint_sizes、constraint_strides。test_stateful_symbolic_context:以ConstantSource("x")构造StatefulSymbolicContext,验证tensor_source、空 symbol cache 和动态维配置。【完备性分析】
torch.fx.experimental.symbolic_shapes的 Python 层符号 shape 元信息/上下文能力,不涉及新增 NPU 算子,也不改变跨仓接口或运行时计算逻辑。v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0和master;资料支持状态由 PR 36822 单独补齐。【资料变更】
不涉及。本 PR 仅补充测试用例;资料支持状态已通过独立资料 PR 提交:
https://gitcode.com/Ascend/pytorch/pull/36822
【接口变更】
不涉及。未修改跨仓接口或客户可见接口行为。
【功能验证】
验证新增 5 个目标 API 测试用例,执行命令如下:
cd /workspace/user_data python3 torch-npu-v2.12.0/test/fx/test_symbolic_shapes_api.py \ TestSymbolicShapesAPI.test_shape_env_size_hint \ TestSymbolicShapesAPI.test_shape_env_suppress_guards \ TestSymbolicShapesAPI.test_shape_env_settings \ TestSymbolicShapesAPI.test_stateless_symbolic_context \ TestSymbolicShapesAPI.test_stateful_symbolic_context执行结果如下:
【测试效果 / 日志说明】
ci-pipeline-passed、docs-ci-pipeline-success。【CheckList】