已合并
docs: add support status for torch.fx.experimental.symbolic_shapes APIs #36822
docs: add support status for torch.fx.experimental.symbolic_shapes APIs #36822
已合并
xuanzhi-2026创建于 5月26日
xuanzhi-2026
5月26日

【合入来源】

【任务背景】

本 PR 对应 pytorch-vllm 开源实习项目中的 Torch-NPU API 一致性对齐任务,公开 issue:
https://gitcode.com/Ascend/pytorch/issues/1628

本 PR 是该 issue 的资料补齐 PR,用于在 docs/zh/native_apistorch-fx.md 支持矩阵中补充 torch.fx.experimental.symbolic_shapes 相关 API 的支持状态。同组交付 PR 如下:

【API 功能介绍】

API 功能说明
torch.fx.experimental.symbolic_shapes.ShapeEnv.size_hint 对确定的符号表达式或 sympy 表达式求可用于动态 shape guard/约束判断的整型 hint;allow_none 控制无法求值时是否允许返回 None
torch.fx.experimental.symbolic_shapes.ShapeEnv.suppress_guards ShapeEnv 提供的上下文管理器,用于在局部代码块内临时抑制 guard 记录,避免辅助求值过程额外生成 guards。
torch.fx.experimental.symbolic_shapes.ShapeEnvSettings ShapeEnv 的配置数据结构,保存动态 shape 相关开关,例如 scalar output、dynamic output shape、duck shape、deferred runtime assert 等行为配置。
torch.fx.experimental.symbolic_shapes.StatefulSymbolicContext 带状态的符号上下文,保存 tensor_source 以及 ShapeEnv/source/symbol 的缓存,用于同一张量符号化过程中的符号复用。
torch.fx.experimental.symbolic_shapes.StatelessSymbolicContext 无状态符号上下文,记录 dynamic_sizesdynamic_stridesconstraint_sizesconstraint_strides 等输入元信息,用于创建符号尺寸时描述动态维约束。

【上游社区测试情况】

已基于当前分支基线检索 test 目录中的相关覆盖情况:

  • 上游/基线中存在部分间接覆盖,例如 StatelessSymbolicContext 在 dynamo export/subclass 场景中被使用,ShapeEnvSettings 出现在 public API allowlist 中。
  • 未发现覆盖本任务 5 个 API 的集中直接 UT,尤其缺少 ShapeEnv.size_hintShapeEnv.suppress_guardsShapeEnvSettings 字段构造、StatefulSymbolicContext/StatelessSymbolicContext 默认状态的直接行为断言。
  • 因此同组测试 PR 在各目标分支补充了自写 UT;本 PR 只负责同步资料支持状态。

【修改方案】

docs/zh/native_apis 当前已有的 PyTorch 版本目录中,向 torch-fx.md 支持矩阵追加上述 5 个 API,支持状态标记为“是”,限制与说明为“-”,表示与原生 API 支持度保持一致。

本 PR 覆盖以下资料文件:

docs/zh/native_apis/pytorch_2-7-1/torch-fx.md
docs/zh/native_apis/pytorch_2-9-0/torch-fx.md
docs/zh/native_apis/pytorch_2-10-0/torch-fx.md
docs/zh/native_apis/pytorch_2-11-0/torch-fx.md
docs/zh/native_apis/pytorch_2-12-0/torch-fx.md

【完备性分析】

  • 当前 docs/zh/native_apis 下存在的 PyTorch 版本目录均已补充这 5 个 API 支持状态。
  • 每个版本目录均追加同一组 API,链接指向对应 PyTorch 版本的官方文档页面。
  • 本 PR 仅变更资料支持矩阵,不涉及 API 功能实现、NPU 算子开发、跨仓接口或运行时行为变更。
  • 当前结论:不需要新增 API 实现;需要新增测试用例,已由同组测试 PR 覆盖;需要资料补齐,已在本 PR 完成。

【资料变更】

涉及资料变更。补充 torch.fx.experimental.symbolic_shapes 相关 API 的支持状态说明。

【接口变更】

不涉及。未修改跨仓接口或客户可见接口行为。

【功能验证】

本 PR 仅涉及资料更新,已确认提交只包含资料文件变更:

docs/zh/native_apis/pytorch_2-7-1/torch-fx.md
docs/zh/native_apis/pytorch_2-9-0/torch-fx.md
docs/zh/native_apis/pytorch_2-10-0/torch-fx.md
docs/zh/native_apis/pytorch_2-11-0/torch-fx.md
docs/zh/native_apis/pytorch_2-12-0/torch-fx.md

已基于最新 upstream/v2.7.1 解决资料文件冲突并重新推送,当前提交为:

e3ec8d460 docs: add support status for symbolic shapes APIs
5 files changed, 25 insertions(+)

本地校验:

git diff --check
# 无输出,表示未发现空白格式问题

每个 torch-fx.md 文件均包含 5 个目标 API 条目,未残留冲突标记。

PR 状态复查结果:

mergeable: true
conflict_passed: true
ci_state_passed: true

【测试效果 / 日志说明】

  • 本 PR 为资料补齐,不新增可执行测试代码。
  • 同组测试 PR 已在各目标分支验证新增 5 个 API 用例均通过。
  • 资料冲突已通过重新基于最新 v2.7.1 底座 cherry-pick 单个文档提交解决,当前 PR 分支保持 squash 后的单提交形态。

【CheckList】

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 xuanzhi-2026 的贡献)
Xxuanzhi-2026
5月26日 创建了 pull request,commit b783f852
Xxuanzhi-2026
5月26日 关联了issue:【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(22)
ascend-robot
ascend-robot成员
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
docs lyx324521, huangjingwei, chenrayray (3/2) huangjingwei (1/1)

💡 Tip:

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

likedislike
ascend-robotascend-robot成员
5月26日 添加了label:ascend-cla/yes
此处折叠了120条消息 查看更多
ascend-robotascend-robot成员
7月8日 添加了label:lgtm
Jingwei Huang
Jingwei Huang成员
7月8日 评论:

/approve

likedislike
ascend-robotascend-robot成员
7月8日 添加了label:approved
ascend-robotascend-robot成员
7月8日 合入了pull request
ascend-robot
ascend-robot成员
7月8日 评论:
流水线 pytorch_gitcode_PR_multiVersion#12191 [ commitID:e3ec8d46 ] 已完成
likedislike