已合并
test: add test cases for torch.onnx.ONNXProgram.model_proto #43579
木路折创建于 8月2日
test: add test cases for torch.onnx.ONNXProgram.model_proto #43579
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 木路折 的贡献)8月2日 关联了issue:【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(10)
atomgit-bot
8月2日 评论:
8月2日 评论:
变更摘要
本 PR 为 torch.onnx.ONNXProgram.model_proto 接口新增独立的测试用例文件 test/onnx/exporter/test_onnx_program.py(新增 87 行)。该接口是 ONNXProgram 类的 @property,用于将 dynamo-based ONNX exporter 导出的 IR 模型序列化为 onnx.ModelProto protobuf 对象;PyTorch 官方缺少对该接口的直接测试,本次新增的 TestONNXProgramModelProto 测试类通过 5 个用例分别验证其返回值有效性、图结构、producer_name、protobuf 序列化能力及多输入多输出场景,并支持在 NPU 加速器(torch.accelerator)与 CPU 设备上运行。
主要改动
- 新增测试类
TestONNXProgramModelProto:在test/onnx/exporter/test_onnx_program.py中新增基于common_utils.TestCase的测试类,通过torch.onnx.export(..., dynamo=True)导出模型后访问model_proto进行断言。 - 验证返回对象有效性:
test_model_proto_returns_valid_proto断言model_proto非空且ir_version > 0,确认返回的是有效的onnx.ModelProto对象。 - 验证单输入单输出图结构:
test_model_proto_graph_structure断言proto.graph.input与proto.graph.output长度均为 1,校验基础模型的 graph 结构。 - 验证
producer_name与序列化能力:test_model_proto_producer_name断言producer_name == "pytorch";test_model_proto_serialization断言proto.SerializeToString()结果非空。 - 验证多输入多输出场景:
test_model_proto_multiple_inputs_outputs对双输入双输出模型断言graph.input与graph.output数量均为 2,扩展了对复杂模型结构的覆盖。


不准确?
ascend-robot
8月2日 评论:
8月2日 评论:
atomgit-bot
8月2日 评论:
8月2日 评论:
此处折叠了114条消息 查看更多
19 天前 删除了label:ci-pipeline-running
19 天前 添加了label:ci-pipeline-passed
ascend-robot
19 天前 评论:
19 天前 评论:
流水线 PR-pipeline_pytorch#62702 [ commitID:1346efbb ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| Build_X86_213 | 🛑 | >>> | |
| Build_ARM_213 | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| check_error | ✅ | >>> | |
| lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | 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 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_01_213 | 🛑 | >>> | |
| UT_ARM_A2_Part_02_213 | 🛑 | >>> | |
| UT_ARM_A2_Part_03_213 | 🛑 | >>> | |
| UT_inductor_Part_01_213 | 🛑 | >>> | |
| UT_inductor_Part_02_213 | 🛑 | >>> | |
| UT_inductor_Part_03_213 | 🛑 | >>> | |
| UT_inductor_Part_04_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04_213 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01_213 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_02_213 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


19 天前 合入了pull request
ascend-robot
19 天前 评论:
19 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14328 [ commitID:1346efbb ] 已完成


【合入来源】
关联 issue: https://gitcode.com/Ascend/pytorch/issues/3489
任务分类:用例补齐(PyTorch 官方缺少对 torch.onnx.ONNXProgram.model_proto 的直接测试)
该 API 虽为纯 Python 序列化属性,但验证必须先经 torch.onnx.export(dynamo=True) 在 NPU 上完成 dynamo 导出,验证链路依赖 NPU,故在 test 目录新增用例看护该流程。
【修改方案】
一、API 功能说明
torch.onnx.ONNXProgram.model_proto是ONNXProgram类的@property,返回ir.serde.serialize_model(self.model),即将 dynamo-based ONNX exporter 导出的 IR 模型序列化为onnx.ModelProtoprotobuf 对象。该 API 为非计算类接口,不涉及 NPU 数据类型计算,仅做纯 Python 序列化操作。二、测试用例完备性说明
PyTorch 官方
test/onnx/exporter/目录中没有直接针对model_proto的测试用例。test_onnx_program.py仅测试rename_axes;test_api.py和test_input_observer.py中仅将.model_proto作为工具间接使用,未验证其返回值结构、序列化能力等核心功能。本次新增test/onnx/exporter/test_onnx_program.py,直接验证:onnx.ModelProto对象(ir_version > 0);三、NPU 适配
测试涉及 Tensor 创建与 ONNX 导出,所有 Tensor 通过
device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu"迁移到 NPU,确保导出流程在 NPU 上执行。【资料变更】
【接口变更】
【功能验证】
python test/onnx/exporter/test_onnx_program.pyRan 5 tests in 9.949s, OK【CheckList】