Open
【API一致性任务】torch.onnx.OnnxRegistry.opset_version API 一致性验证结论 #3635
zhouzirui1234Add on Aug 3
Aug 3 Modify description of issue
Aug 3 Modify description of issue
Aug 3 Modify description of issue
Aug 3 Modify description of issue
Aug 3 Modify description of issue
Aug 3 Modify description of issue
-
Aug 3 Comments:
Aug 3 Comments:
我要认领这个任务


Aug 5 Modify description of issue
7 event messages are collapsed here。 See more
Aug 13 Added label: event: api-consistencybot-triaged
TorchNPU-Bot
Aug 13 Comments:
Aug 13 Comments:
检测到社区任务相关 issue,自动添加标签:event: api-consistency


Aug 18 Change title to "【API一致性任务】torch.onnx.OnnxRegistry.opset_version API 一致性验证结论", originally titled "【API一致性任务】[社区任务] torch.onnx.OnnxRegistry.opset_version API 一致性验证结论".
Aug 18 Change title to "【API一致性任务】torch.onnx.OnnxRegistry.opset_version API 一致性验证结论", originally titled "【API一致性任务】[社区任务] torch.onnx.OnnxRegistry.opset_version API 一致性验证结论".
Aug 18 Modify description of issue
Aug 18 Added label: help-wanted
TorchNPU-Bot
Aug 18 Comments:
Aug 18 Comments:
检测到社区任务相关 issue,自动添加标签:event: api-consistency、help-wanted


Aug 18 Modify description of issue
Aug 18 Modify description of issue
Aug 18 Modify description of issue
群青世界
Aug 27 Comments:
Aug 27 Comments:
验证成功后,资料支持情况是否需要修改


Aug 27 Modify description of issue
Aug 27 Associated pull request
zhouzirui1234
Aug 27 Comments:
Aug 27 Comments:


Sep 4 Modify description of issue
torch.onnx.OnnxRegistry.opset_version处理说明任务 issue:https://gitcode.com/Ascend/pytorch/issues/3496
一、处理结论
本任务按“官方无直接用例、纯 Python 非硬件属性”处理:不需要 torch-npu 实现补齐,不新增自写测试,也不新增
test_upstreampatch。七版本核查结果如下:
torch.onnx.OnnxRegistry是公开 API,opset_version为只读属性;实际创建 Registry 后读取结果为整数18,内部状态一致性和只读语义均通过。torch.onnx公开导出OnnxRegistry。✘,与真实功能结果不一致,不能继续得出“资料无需修改”的结论;该资料状态需要更正为✔。因此,本 Issue 可以关闭代码与测试补齐路径,但资料状态仍有明确待更正项。
二、API 功能
目标 API:
在 PyTorch v2.7.1 中,
OnnxRegistry保存 ONNX 导出所需的函数注册信息,opset_version返回 Registry 当前面向的 ONNX opset 版本。接口行为:
int;_opset_version;PyTorch v2.7.1 官方实现:
@property def opset_version(self) -> int: """The ONNX opset version the exporter should target.""" return self._opset_version三、PyTorch 官方用例检查
3.1 官方源码与公共导出检查
核查版本:
执行命令:
cd pytorch git checkout v2.7.1 grep -n "OnnxRegistry" torch/onnx/__init__.py grep -n -A6 -B3 "def opset_version" \ torch/onnx/_internal/_exporter_legacy.py执行结果:
结果确认 v2.7.1 中目标类由
torch.onnx公开导出,属性实现只返回 Python 实例状态。3.2 官方测试目录检索
执行命令:
cd pytorch grep -RIn \ "OnnxRegistry.opset_version" \ test \ --include="*.py" grep -RInE \ "OnnxRegistry.*opset_version|opset_version.*OnnxRegistry" \ test \ --include="*.py"执行结果:
官方 ONNX 测试中存在普通
opset_version参数测试,但没有针对torch.onnx.OnnxRegistry.opset_version属性本身的直接用例,不能把同名参数测试误认为目标 API 已覆盖。3.3 API 类型与 NPU 适配判断
目标属性只返回 Python 整数,不包含 Tensor 输入输出、设备迁移、NPU 算子、Kernel、torch-npu API、设备硬编码或分布式通信。因此应在 Issue 中验证实际 Python 行为,不应为满足形式新增 NPU Tensor 或 torch-npu 专项测试。
四、运行环境
五、功能验证
5.1 验证场景
v2.7.1 验证以下实际行为:
torch.onnx.OnnxRegistry可从公共命名空间访问;opset_version返回 Pythonint且大于 0;_opset_version一致;AttributeError,确认属性只读;后续六个版本验证当前 torch/torch-npu 版本、
torch.onnx是否公开OnnxRegistry,以及直接访问时的错误类型。5.2 核心验证代码
registry = torch.onnx.OnnxRegistry() assert isinstance(registry.opset_version, int) assert registry.opset_version > 0 assert registry.opset_version == registry._opset_version try: registry.opset_version = registry.opset_version + 1 except AttributeError: read_only = True else: read_only = False assert read_only custom_function = op.Abs registry.register_op( custom_function, "review_namespace", "review_abs", ) registered = registry.get_op_functions( "review_namespace", "review_abs", ) assert registered[0].onnx_function is custom_function assert registered[0].is_custom is True5.3 v2.7.1
执行命令:
cd /root source /usr/local/Ascend/ascend-toolkit/set_env.sh >/dev/null 2>&1 PYTHONPATH=/root/api-consistency-validation/deps/onnxscript \ /root/api-consistency-validation/envs/v2.7.1/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry.py执行结果:
结论:目标属性实际读取成功,返回
18,类型、内部值一致性和只读语义均符合官方实现。5.4 v2.9.0
执行命令:
cd /root source /usr/local/Ascend/ascend-toolkit/set_env.sh >/dev/null 2>&1 /root/api-consistency-validation/envs/v2.9.0/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry_status.py执行结果:
结论:PyTorch v2.9.0 已不再从
torch.onnx公开导出目标类。5.5 v2.10.0
执行命令:
cd /root source /usr/local/Ascend/ascend-toolkit/set_env.sh >/dev/null 2>&1 /root/api-consistency-validation/envs/v2.10.0/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry_status.py执行结果:
结论:PyTorch v2.10.0 已不再公开导出目标类。
5.6 v2.11.0
执行命令:
cd /root source /usr/local/Ascend/ascend-toolkit/set_env.sh >/dev/null 2>&1 /root/api-consistency-validation/envs/v2.11.0/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry_status.py执行结果:
结论:PyTorch v2.11.0 已不再公开导出目标类。
5.7 v2.12.0
执行命令:
cd /root source /usr/local/Ascend/ascend-toolkit/set_env.sh >/dev/null 2>&1 /root/api-consistency-validation/envs/v2.12.0/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry_status.py执行结果:
结论:PyTorch v2.12.0 已不再公开导出目标类。
5.8 v2.13.0
执行命令:
cd /root source /usr/local/Ascend/cann-9.1.0-beta.1/set_env.sh >/dev/null 2>&1 /root/api-consistency-validation/envs/v2.13.0/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry_status.py执行结果:
结论:PyTorch v2.13.0 同样不再公开导出目标类。
5.9 master
执行命令:
cd /root source /usr/local/Ascend/ascend-toolkit/set_env.sh >/dev/null 2>&1 /root/api-consistency-validation/envs/master/bin/python \ /root/api-consistency-validation/probes/probe_onnx_registry_status.py执行结果:
结论:当前 master 同样不再公开导出目标类。
5.10 A5(Ascend 950PR)补充验证
运行环境:
分支验证环境:
PyTorch 官方用例检查
执行命令:
cd /root if rg -n 'OnnxRegistry\.opset_version|OnnxRegistry.*opset_version|opset_version.*OnnxRegistry|OnnxRegistry\.register_op|OnnxRegistry.*register_op|register_op.*OnnxRegistry' /root/onnxregistry-950pr-validation/sources/pytorch-v2.7.1/test; then echo DIRECT_OFFICIAL_MATCHES=FOUND; exit 1; else echo DIRECT_OFFICIAL_MATCHES=0; echo result=PASS; fi执行结果:
说明:PyTorch v2.7.1 官方
test/目录没有直接调用torch.onnx.OnnxRegistry.opset_version或torch.onnx.OnnxRegistry.register_op的用例;同名register_op测试属于旧接口,未作为本 PR 的目标官方用例。按照社区分类规则,不新增自写测试,使用官方实现对应的功能探针补充支持证据。v2.7.1 功能与 950PR 环境验证
环境初始化:
source /usr/local/Ascend/cann-9.1.0-beta.3/set_env.sh >/dev/null 2>&1执行命令:
cd /root PYTHONNOUSERSITE=1 /root/onnxregistry-950pr-validation/envs/v2.7.1/bin/python /root/onnxregistry-950pr-validation/tests/probe_onnx_registry_950.py执行结果:
A5 补充验证结论:
Ascend950PR_9579、NPU Tensor 创建成功,opset_version与register_op的目标语义全部通过、退出码 0。torch.onnx.OnnxRegistry,因此不在这些版本人为补回或验证已移除 API。六、资料检查
执行命令:
grep -n -A8 -B3 \ "torch.onnx.OnnxRegistry.opset_version" \ docs/zh/api/native_api/pytorch_2-7-1/torch-onnx.md执行结果:
检查结论:v2.7.1 资料已收录目标 API,但三个产品支持单元格均为
✘。该属性在 v2.7.1 中已真实实例化并验证通过,而且功能与设备无关,现有资料状态与证据冲突,需要更正为✔。后续版本的公共类已经移除,不应人为补回该条目。七、最终结论
opset_version返回值18OnnxRegistry不存在✘更正为✔最终处理方式:本 Issue 给出七版本源码、官方用例、功能和资料证据;不提交代码 PR或测试 PR,不新增
test_upstreampatch。资料更正项不能写成“无需修改”,应在获准的资料流程中单独处理。