已合并
test(fx): add NPU coverage for PropagateUnbackedSymInts and rebind_unbacked #37265
lihaofei-2026创建于 5月31日
test(fx): add NPU coverage for PropagateUnbackedSymInts and rebind_unbacked #37265
已合并
lihaofei-2026创建于 5月31日
已删除 :symbolic-shapes-propagate-unbacked-symints-v2.9.0合入到Ascend/pytorchv2.9.0
lihaofei-2026
lihaofei-2026
5月31日

【合入来源】

如有社区issue,请关联issue链接
公开issue:https://gitcode.com/Ascend/pytorch/issues/1619

【修改方案】

  1. 一致性分析:对 torch.fx.experimental.symbolic_shapes 模块中的5个API进行torchnpu迁移适配分析,包括
    PropagateUnbackedSymInts.output
    PropagateUnbackedSymInts.placeholder
    PropagateUnbackedSymInts.run
    PropagateUnbackedSymInts.run_node
    rebind_unbacked
  2. 上游测试调研:分析PyTorch官方仓库(main分支)中这5个API的测试覆盖情况,发现上游无直接测试用例,仅有间接测试(通过 shape_prop.ShapeProp 和provenance 检查)
  3. 下游版本排查:检查v2.7.1~v2.12.0共5个下游版本,确认所有版本均缺少这5个API的测试用例
  4. 新增测试用例:在每个下游版本的 test/fx/ 目录下新建 test_fx_propagate_unbacked_symints.py 文件,覆盖全部5个API,使用NPU张量(device="npu")验证各API在NPU设备下的正确性
  5. 测试验证:所有5个版本的测试用例均已通过验证

新增用例必要性分析:

  1. PropagateUnbackedSymInts.run/run_node:上游 test/fx/test_fx_traceback.py::test_graph_provenance 通过 AOT export 路径间接覆盖,但缺少 NPU设备路径验证
  2. PropagateUnbackedSymInts.placeholder/output:继承自 torch.fx.Interpreter,上游无独立断言
  3. rebind_unbacked:上游通过 ShapeProp/FakeTensorProp/export 路径间接覆盖,但缺少 NPU 验证
    结论:属于「迁移上游间接覆盖 + NPU 设备路径补齐 + 弱覆盖补独立断言」,不是重复建设

【资料变更】

经核查官方文档目录,本次涉及的 API 属于 torch.fx.experimental 下的编译期实验性内部接口,非对外暴露的常规 Native API,无需在文档中补充登记。

【接口变更】

不涉及

【功能验证】

测试场景:验证 PropagateUnbackedSymInts 类和 rebind_unbacked 函数在NPU张量下的功能正确性
测试方法:

  1. 新增UT测试用例文件 test/fx/test_fx_propagate_unbacked_symints.py
  2. 使用 torch.tensor([1, 0, 1, 0], device="npu") 创建NPU张量
  3. 通过 torch.export.export 导出模型并获取fake tensor
  4. 在fake_mode上下文中调用各API进行验证
    测试用例覆盖:
测试函数 验证API API作用
test_propagate_unbacked_symints_run PropagateUnbackedSymInts.run 运行整个FX图,遍历所有节点执行并传播unbacked符号绑定
test_propagate_unbacked_symints_run_node PropagateUnbackedSymInts.run_node 运行单个FX节点,调用rebind_unbacked重新绑定unbacked符号
test_propagate_unbacked_symints_placeholder PropagateUnbackedSymInts.placeholder 执行placeholoder节点,从参数迭代器获取图的输入数据
test_propagate_unbacked_symints_output PropagateUnbackedSymInts.output 执行output节点,返回图的最终输出结果
test_rebind_unbacked rebind_unbacked 在重新追踪图时,建立新旧unbacked SymInts的等价关系,确保ShapeEnv一致性

本 PR 不是对上游已有测试文件进行 NPU 适配,因此不涉及 test_upstream patch 文件修改。
测试命令及结果:
python /workspace/user_data/pytorch-v2.9.0/test/fx/test_fx_propagate_unbacked_symints.py
屏幕截图 2026-05-30 125729.png

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 lihaofei-2026 的贡献)
lihaofei-2026lihaofei-2026
5月31日 创建了 pull request,commit 1a77990b
lihaofei-2026lihaofei-2026
5月31日 关联了issue:【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(13)
ascend-robotascend-robot成员
5月31日 添加了label:ascend-cla/no
ascend-robot
ascend-robot成员
5月31日 评论:

CLA Signature Guide

@lihaofei-2026 , thanks for your pull request.

The following commit(s) have not signed Contributor License Agreement (CLA).

Commit Reason
441616fa test(fx): add NPU coverage for P... it's an invalid email! please check it.

If you need to sign CLA, you can click here to sign the CLA.

If you need to check if the email is set up correctly, you can click here to do it in the FAQs.

After signing the CLA or updating the email, you must comment /check-cla to check the CLA status again.

likedislike
此处折叠了54条消息 查看更多
sunyu-xuan成员
6月4日 评论:

/lgtm

likedislike
liwei386成员
6月5日 评论:

/approve

likedislike
ascend-robotascend-robot成员
6月5日 添加了label:approvedlgtm
ascend-robotascend-robot成员
6月5日 合入了pull request
ascend-robot
ascend-robot成员
6月5日 评论:
流水线 pytorch_gitcode_PR_multiVersion#10098 [ commitID:9a329231 ] 已完成
likedislike