-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnsupportedOperatorError: aten::scatter_reduce when include_self=False #126660
Comments
MLP is a fc layer, which is import torch
import torch.nn as nn
import torch.nn.functional as F
import onnx
import onnxruntime as ort
# MLP
class MLP(nn.Module):
def __init__(
self,
in_channel,
out_channel,
hidden=64,
bias=True,
activation="relu",
norm="layer",
):
super(MLP, self).__init__()
# define the activation function
if activation == "relu":
act_layer = nn.ReLU
elif activation == "relu6":
act_layer = nn.ReLU6
elif activation == "leaky":
act_layer = nn.LeakyReLU
elif activation == "prelu":
act_layer = nn.PReLU
else:
raise NotImplementedError
# define the normalization function
if norm == "layer":
norm_layer = nn.LayerNorm
elif norm == "batch":
norm_layer = nn.BatchNorm1d
else:
raise NotImplementedError
# insert the layers
self.linear1 = nn.Linear(in_channel, hidden, bias=bias)
self.linear1.apply(self._init_weights)
self.linear2 = nn.Linear(hidden, out_channel, bias=bias)
self.linear2.apply(self._init_weights)
self.norm1 = norm_layer(hidden)
self.norm2 = norm_layer(out_channel)
self.act1 = act_layer(inplace=True)
self.act2 = act_layer(inplace=True)
self.shortcut = None
if in_channel != out_channel:
self.shortcut = nn.Sequential(
nn.Linear(in_channel, out_channel, bias=bias),
norm_layer(out_channel)
)
# self.layers = nn.Sequential(
# self.linear1,
# self.norm1,
# self.act1,
# self.linear2,
# self.norm2,
# )
@staticmethod
def _init_weights(m):
if isinstance(m, nn.Linear):
torch.nn.init.xavier_uniform_(m.weight)
m.bias.data.fill_(0.01)
def forward(self, x):
# print("\nMLP")
out = self.linear1(x)
out = self.norm1(out)
out = self.act1(out)
out = self.linear2(out)
out = self.norm2(out)
# print("\nx {} \nout {}".format(x.shape, out.shape))
# out = self.layers(x)
# print(self.shortcut)
if self.shortcut:
out += self.shortcut(x)
else:
out += x
# print("\nx {} \nout {}".format(x.shape, out.shape))
return self.act2(out)```
it can be directly export as onnx |
scatter_reduce should be supported after/include opset_version=16: pytorch/torch/onnx/symbolic_opset16.py Line 120 in b40fb2d
What do you get when you export it with 16? Please try a newer version of PyTorch. It looks like you are using torch==2.0.0, which is too old. opset 11 is indeed not supporting scatter_reduce. |
thanks for reply, opset 16 doesn't work either. I will update my torch version to the newest version and try again. |
another error occured
|
uninstall torch-sparse and reinstall torch-sparse solves the first two UserWarning, the following TraceWarning I will try to figure out. A higher version pytorch truely supports operator aten::scatter_reduce, but there is still an error. |
Hi @LTsommer, Unfortunately, include_self=False is not supported in ONNX spec: onnx/onnx#5100. You would have to modify the model code to get around with that. |
馃悰 Describe the bug
Hello, experts,
recently I am trying to export .pt model to .oonx model by function torch.onnx.export, but an error occured: "torch.onnx.errors.UnsupportedOperatorError: Exporting the operator 'aten::scatter_reduce' to ONNX opset version 11 is not supported.". I have tried different opset version from 11 - 18, it still doesn't work. Actually aten::scatter_reduce is not explicit used in the code, so I guess it is called in another function.
the code is as follows:
The error imfomation is as follows:
Traceback (most recent call last):
File "
/Desktop/Studien/VN/core/model/layers/subgraph.py", line 141, in/opt/anaconda3/envs/torch/lib/python3.9/site-packages/torch/onnx/utils.py", line 506, in exporttorch.onnx.export(
File "
_export(
File "
/opt/anaconda3/envs/torch/lib/python3.9/site-packages/torch/onnx/utils.py", line 1548, in _export/opt/anaconda3/envs/torch/lib/python3.9/site-packages/torch/onnx/utils.py", line 1117, in _model_to_graphgraph, params_dict, torch_out = _model_to_graph(
File "
graph = _optimize_graph(
File "
/opt/anaconda3/envs/torch/lib/python3.9/site-packages/torch/onnx/utils.py", line 665, in _optimize_graph/opt/anaconda3/envs/torch/lib/python3.9/site-packages/torch/onnx/utils.py", line 1901, in _run_symbolic_functiongraph = _C._jit_pass_onnx(graph, operator_export_type)
File "
raise errors.UnsupportedOperatorError(
torch.onnx.errors.UnsupportedOperatorError: Exporting the operator 'aten::scatter_reduce' to ONNX opset version 11 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues.
The packae installed in my virtual env:
The text was updated successfully, but these errors were encountered: