Custom Symbolic Function Registration for ONNX Error 路 Issue #105160 路 pytorch/pytorch 路 GitHub

您所在的位置:网站首页 BLOCK17红酒 Custom Symbolic Function Registration for ONNX Error 路 Issue #105160 路 pytorch/pytorch 路 GitHub

Custom Symbolic Function Registration for ONNX Error 路 Issue #105160 路 pytorch/pytorch 路 GitHub

2024-07-10 03:46| 来源: 网络整理| 查看: 265

馃悰 Describe the bug

The register_custom_op_symbolic function, part of torch.onnx does not see to be working properly for me. I am following this simple example found in the documentation using a contributed operator thats part of onnxruntime-gpu. I noted that the ONNX unit tests do not check the functionality using a custom namespace, so I am assuming this doc example is correct. I tried to do some digging into the torch/_ops.py but was not able to follow how ops are dynamically created.

I am running in the Nvidia PyTorch container 23.06, only additional install I do is pip install onnxruntime-gpu.

I cannot get the symbolic operation to register properly (I can't call it from torch.ops). Here's a minimal example (based on the example in the docs linked above):

# Create custom symbolic function import torch from torch.onnx.symbolic_helper import parse_args @parse_args('v', 'i') def symbolic_foo_forward(g: torch.Graph, input: torch.Value, ndim: int): output = g.op( "com.microsoft::Rfft", input, normalized_i=0, onesided_i=1, signal_ndim_i=ndim, ) return output # Register custom symbolic function from torch.onnx import register_custom_op_symbolic register_custom_op_symbolic('custom_ops::foo_forward', symbolic_foo_forward, 9) class FooModel(torch.nn.Module): def __init__(self, ndim): super(FooModel, self).__init__() self.ndim = ndim def forward(self, input1): # Calling custom op return torch.ops.custom_ops.foo_forward(input1, self.ndim) dummy_input1 = torch.randn(3,3,3) model = FooModel(1) torch.onnx.export(model, (dummy_input1), 'model.onnx')

The error is related to accessing the symbolic ops in PyTorch, so I am guessing its an issue with this register function. I would expect torch.ops.custom_ops.foo_forward to be callable since I registered the operator.

=========== Diagnostic Run torch.onnx.export version 2.1.0a0+4136153 =========== verbose: False, log level: Level.ERROR ======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ======================== Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/torch/_ops.py", line 709, in __getattr__ op, overload_names = torch._C._jit_get_operation(qualified_op_name) RuntimeError: No such operator custom_ops::foo_forward The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/workspace/gh-forks/modulus/fft_testing.py", line 32, in torch.onnx.export(model, (dummy_input1), 'model.onnx') File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 507, in export _export( File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1567, in _export graph, params_dict, torch_out = _model_to_graph( File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1124, in _model_to_graph graph, params, torch_out, module = _create_jit_graph(model, args) File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1000, in _create_jit_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 904, in _trace_and_get_graph_from_model trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph( File "/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py", line 1268, in _get_trace_graph outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py", line 127, in forward graph, out = torch._C._create_graph_by_tracing( File "/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py", line 118, in wrapper outs.append(self.inner(*trace_inputs)) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1488, in _slow_forward result = self.forward(*input, **kwargs) File "/workspace/gh-forks/modulus/fft_testing.py", line 27, in forward return torch.ops.custom_ops.foo_forward(input1, self.ndim) File "/usr/local/lib/python3.10/dist-packages/torch/_ops.py", line 713, in __getattr__ raise AttributeError( AttributeError: '_OpNamespace' 'custom_ops' object has no attribute 'foo_forward'

Any help would be appreciated, thanks!

Versions [pip3] numpy==1.22.2 [pip3] pytorch-quantization==2.1.2 [pip3] torch==2.1.0a0+4136153 [pip3] torch-tensorrt==1.5.0.dev0 [pip3] torchdata==0.7.0a0 [pip3] torchtext==0.16.0a0 [pip3] torchvision==0.16.0a0 [pip3] triton==2.1.0 [conda] Could not collect


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3