In current relay pass, we can merge two consecutive reshape op by SimplifyExpr
pass. Sometimes, We may produce useless reshape op in the process of importing models. For example:
#[version = "0.0.5"]
def @main(%Placeholder: Tensor[(1, 3, 227, 227), float32], %conv1/weights: Tensor[(96, 3, 11, 11), float32], %conv1/biases: Tensor[(96), float32]) -> Tensor[(1, 96, 55, 55), float32] {
%0 = nn.conv2d(%Placeholder, %conv1/weights, strides=[4, 4], padding=[0, 0, 0, 0], channels=96, kernel_size=[11, 11]) /* ty=Tensor[(1, 96, 55, 55), float32] */;
%1 = nn.bias_add(%0, %conv1/biases) /* ty=Tensor[(1, 96, 55, 55), float32] */;
%2 = reshape(%1, newshape=[1, 96, 55, 55]) /* ty=Tensor[(1, 96, 55, 55), float32] */;
nn.relu(%2) /* ty=Tensor[(1, 96, 55, 55), float32] */
}
We can see that the output of %2
have the same shape with %1
, then the reshape op is useless…
In order to deal with this problem, we have extended the functionality of SimplifyExpr
pass, and now it will remove the useless reshape op. Do you think it is necessary for me to propose a pr? @haichen