PReLU dimension mismatch error when converting ONNX model to TVM

Hi, I try to convert a pytorch model to tvm via onnx intermediate model following this tutorial, but fail at prelu operation convertion which reports a dimension mismatch error:

tensor type Tensor[(128), float32] has 1 dimensions, while Tensor[(128, 1, 1), float32] has 3 dimensions; unable to unify: `Tensor[(128), float32]` and `Tensor[(128, 1, 1), float32]

My pytorch version is 1.2, and onnx version is 1.5 which tvm is the latest master branch (15ae9780). I also have tried to update onnx to 1.6 but nothing helps. Here is my simplest example to replicate this error. I don’t know which commit of tvm is compatible for my onnx model and that’s really confusing.

import torch
from torch import nn
import tvm
from tvm import relay
import numpy as np
import onnx

class test_model(nn.Module):
    def __init__(self):
        super(test_model, self).__init__()
        self.l1 = nn.Sequential(nn.Conv2d(3, 64, (3, 3), 2, 1, bias=False), 
        self.l2 = nn.Sequential(nn.Conv2d(64, 128, (3, 2), 2, 1, bias=False),
        self.l3 = nn.Sequential(nn.Flatten(),
                                nn.Linear(128*8*8, 128))
    def forward(self, x):
        x = self.l1(x)
        x = self.l2(x)
        x = self.l3(x)
        return x    

model = test_model()
inputs = torch.ones(1,3,32,32)
torch.onnx.export(model, inputs, "test.onnx")

input_shape=(1, 3, 32, 32)
onnx_model = onnx.load("test.onnx")
net, params = relay.frontend.from_onnx(model, shape={input_node: input_shape})
1 Like

same question to me.

tensor type `Tensor[(64), float32]` has 1 dimensions, while `Tensor[(64, 1, 1), float32]` has 3 dimensions; unable to unify: `Tensor[(64), float32]` and `Tensor[(64, 1, 1), float32]`;

ONNX should add flatten() for alpha_tensor like tflite frontend. i.e.

For ONNX, we don’t do it.

So, there is a bug?~~~

same problem~ version 0.7_dev

nn.prelu(%1, %v336) tensor type Tensor[(64), float32] has 1 dimensions, while Tensor[(64, 1, 1), float32] has 3 dimensions; unable to unify: Tensor[(64), float32] and Tensor[(64, 1, 1), float32];

modify the onnx file, let all prelu slope flatten is ok.

tvm should add the flatten() operation as tflite frontend in onnx. It is a bug~

Maybe you can refer it.