# Remove extra reshape

**URL:** <https://discuss.tvm.apache.org/t/remove-extra-reshape/8212>\
**Category:** Development\
**Created:** [October 20, 2020, 7:55am UTC](https://discuss.tvm.apache.org/t/remove-extra-reshape/8212 "2020-10-20T07:55:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhupijuan\_lkl](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/z/cab0a1/32.png) [@zhupijuan\_lkl](https://discuss.tvm.apache.org/u/zhupijuan_lkl)\
**Post date:** [October 20, 2020, 7:55am UTC](https://discuss.tvm.apache.org/t/remove-extra-reshape/8212/1 "2020-10-20T07:55:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![haichen](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/haichen/32/246_2.png) [@haichen](https://discuss.tvm.apache.org/u/haichen)\
**Post date:** [October 30, 2020, 5:10pm UTC](https://discuss.tvm.apache.org/t/remove-extra-reshape/8212/2 "2020-10-30T17:10:36Z")

</div>

Sure, I think you can add this into the `SimplifyExpr` pass. I thought about this before, but I think that the reshape op might be inlined in the fused op.
