已合并
docs: Add torch.onnx.ONNXProgram.optimize to native_api documentation #43671
docs: Add torch.onnx.ONNXProgram.optimize to native_api documentation #43671
已合并
木路折创建于 8月4日
木路折
木路折
8月4日

【合入来源】

【修改方案】

torch.onnx.ONNXProgram.optimize 在 PyTorch 官方文档中已有收录,非私有接口。该 API 在 NPU 上已支持,但 Ascend 文档中未收录,需要补充资料。

该 API 为非计算类接口,与数据类型无关,支持情况直接使用列表格式表示。

【资料变更】

docs/zh/api/native_api 中 7 个版本目录补充 torch.onnx.ONNXProgram.optimize 的文档:

  • pytorch_2-7-1/torch-onnx.md
  • pytorch_2-9-0/torch-onnx.md
  • pytorch_2-10-0/torch-onnx.md
  • pytorch_2-11-0/torch-onnx.md
  • pytorch_2-12-0/torch-onnx.md
  • pytorch_2-13-0/torch-onnx.md
  • pytorch_2-14-0/torch-onnx.md

每个文件在 ONNXProgram.save() 条目之后新增 optimize() 条目,格式按照最新规范使用列表格式(产品支持情况),原生文档链接使用 docs.pytorch.org 域名。A2 支持,A3 支持,Ascend 950DT 支持(经 A5 服务器验证通过)。

【接口变更】

不涉及

仅修改文档资料,未修改任何业务代码。

【功能验证】

验证场景:ONNXProgram.optimize() 返回值、模型有效性、幂等性、IO 数量保持共 4 个测试。

验证方法:在 A2/A3 和 A5 (Ascend 950) 服务器上分别运行测试用例,4 个测试全部 PASSED。

A2 验证

运行命令:TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test/onnx/exporter/test_onnx_program.py -v

============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-8.3.2, pluggy-1.6.0
collecting ... collected 4 items

test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_returns_none PASSED [ 25%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_model_valid PASSED [ 50%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_idempotent PASSED [ 75%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_preserves_io_count PASSED [100%]

============================== 4 passed ===============================

A3 验证

运行命令:TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test/onnx/exporter/test_onnx_program.py -v

============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-8.3.2, pluggy-1.6.0
collecting ... collected 4 items

test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_returns_none PASSED [ 25%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_model_valid PASSED [ 50%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_idempotent PASSED [ 75%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_preserves_io_count PASSED [100%]

============================== 4 passed ===============================

A5 (Ascend 950) 验证

运行命令:TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test/onnx/exporter/test_onnx_program.py -v

============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-8.3.2, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python3
cachedir: .pytest_cache
rootdir: /tmp/pytorch_test
plugins: xdist-3.6.1
collecting ... collected 4 items

test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_idempotent PASSED [ 25%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_model_valid PASSED [ 50%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_preserves_io_count PASSED [ 75%]
test/onnx/exporter/test_onnx_program.py::ONNXProgramOptimizeTest::test_optimize_returns_none PASSED [100%]

============================== 4 passed in 4.03s ===============================

【CheckList】

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 木路折 的贡献)
木路折木路折
8月4日 创建了 pull request,commit 12cfe26a
木路折木路折
8月4日 关联了issue:【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(11)
atomgit-bot
atomgit-bot
8月4日 评论:

变更摘要

本次 PR 为 torch.onnx.ONNXProgram.optimize 在四份 PyTorch 版本对应的 native_api 文档中补齐了支持情况说明。ONNXProgram.optimize() 是 ONNXProgram 类的公开方法,用于通过常量折叠和冗余消除优化 ONNX IR 图,此前各版本文档中该类仅收录了 model_proto() 与 save() 方法,optimize() 缺失。此次变更仅涉及文档更新,未修改任何业务代码。

主要改动

  • 在多版本文档中新增 optimize() 支持情况:在 docs/zh/api/native_api/pytorch_2-7-1/torch-onnx.md、pytorch_2-11-0/torch-onnx.md、pytorch_2-12-0/torch-onnx.md、pytorch_2-13-0/torch-onnx.md 四个文件中的 ONNXProgram.save() 条目之后,统一插入 torch.onnx.ONNXProgram.optimize 的支持情况描述,标注为"支持,暂不支持 Ascend 950DT"。
  • 统一四个版本目录的文档结构:以相同的描述内容和插入位置在 PyTorch 2.7.1、2.11.0、2.12.0、2.13.0 四个版本目录下完成一致性更新,共新增 64 行文档内容。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月4日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
此处折叠了429条消息 查看更多
ascend-robot
ascend-robot成员
1 天前 评论:

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

likedislike
ascend-robotascend-robot成员
1 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
1 天前 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
1 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
AtlasAccount
AtlasAccount成员
1 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion-onetrack#419 [ commitID:35be5bfa ] 已完成
likedislike