Skip to content

[UNITY][Pass] Remove redundant reshape#15806

Merged
Lunderberg merged 4 commits intoapache:unityfrom
sjain58:remove_redundant_reshape
Sep 27, 2023
Merged

[UNITY][Pass] Remove redundant reshape#15806
Lunderberg merged 4 commits intoapache:unityfrom
sjain58:remove_redundant_reshape

Conversation

@sjain58
Copy link
Contributor

@sjain58 sjain58 commented Sep 22, 2023

In Mobilenet float32, we see this sequence of ops:

%179 = squeeze(%178, axis=[2, 3]) /* ty=Tensor[(1, 1001), float16] span=MobilenetEdgeTPU/Logits/Squeeze:0:0 /;
%180 = reshape(%179, newshape=[-1, 1001]) / ty=Tensor[(1, 1001), float16] span=MobilenetEdgeTPU/Predictions/
Reshape:0:0 */;

which later gets transformed to

lv171 = R.call_tir(cls.primfunc_hmx_conv2d26_add20, (lv169, metadata["relax.expr.Constant"][116], metadata["relax.expr.Constant"][117]), out_sinfo=R.Tensor((1, 1001, 1, 1), dtype="float16"))
lv172: R.Tensor((1, 1001), dtype="float16") = R.reshape(lv171, R.shape([1, 1001]))
lv173: R.Tensor((1, 1001), dtype="float16") = R.reshape(lv172, R.shape([1, 1001]))

We can eliminate the redundant reshape.

lv171 = R.call_tir(cls.primfunc_hmx_conv2d26_add20, (lv169, metadata["relax.expr.Constant"][116], metadata["relax.expr.Constant"][117]), out_sinfo=R.Tensor((1, 1001, 1, 1), dtype="float16"))
lv173: R.Tensor((1, 1001), dtype="float16") = R.reshape(lv171, R.shape([1, 1001]))

Copy link
Contributor

@Lunderberg Lunderberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes, and I like the implementation! I just have a couple of nitpicks remaining on it.

(FYI, it looks like the CI is currently stalled on lint checks, with an unused import tvm.)

Copy link
Contributor

@Lunderberg Lunderberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes, and looks good to me!

@Lunderberg Lunderberg merged commit f78d9ed into apache:unity Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants