I have a pytorch network like this
import torch.nn as nn
import torch_scatter.scatter_max
class DGCN(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
...
torch_scatter.scatter_max(x, index, dim=0)
...
But when i want export my model to onnx, i face this error:
...
File "/usr/local/lib/python3.9/dist-packages/torch/onnx/utils.py", line 1115, in _model_to_graph
graph = _optimize_graph(
File "/usr/local/lib/python3.9/dist-packages/torch/onnx/utils.py", line 663, in _optimize_graph
graph = _C._jit_pass_onnx(graph, operator_export_type)
File "/usr/local/lib/python3.9/dist-packages/torch/onnx/utils.py", line 1909, in _run_symbolic_function
raise errors.UnsupportedOperatorError(
torch.onnx.errors.UnsupportedOperatorError: ONNX export failed on an operator with unrecognized namespace 'torch_scatter::scatter_max'.
If you are trying to export a custom operator, make sure you registered it with the right domain and version.
So, How i can do this exactly?
The
Maxreduction attribute for Scatter was recently added in ONNX opset 18 PR.Unfortunately the pytorch to onnx exporters haven't been updated accordingly.
One approach you could take is to make some changes to the Pytorch repository in a fork. You could add the following lines to symbolic_opset18.py
Note that this code was just shamelessly taken from symbolic_opset16.py, where the export of
scatter_addis implemented.