-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Relay][Pass] Simplify consecutive transpose/layout_transform #7656
Conversation
Thanks @comaniac for the PR! I was also working on similar approach. This solves my case too. |
Overall pretty good for me. Please let me know in case my points are not clear. Thanks! |
Thanks for the comments.
Good point. I'll add the support for it later.
Could you provide an example of this case for better illustration? Thanks. |
For example we have below case: Expected transformation: Above such cases can be multiple in a sequence as well. So we need to have a solution which can handle multiple simplification in one chain. Please let me know, in case i have not clearly expressed. Thanks! I understand we can have these points covered in follow up PRs as well. If we are not planning to do it in this PR. Suggest to add TODOs for these points in the source code, which will help in future. |
It seems to me that the current pattern already covers this case? You can refer to the test cases I added, which have a ReLU followed by transposes. Is this what you want? |
Thanks @comaniac for clarification. It is indeed supported.
|
@ANSHUMAN87 comments are addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Sorry for the delay, I was out the end of last week.
One possible extension would be to try to combine this with the simplify reshape above and target patterns like reshape->transpose->reshape or transpose->reshape->transpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @comaniac!
That's an interesting point and I just thought about it. However, reshape and transpose cannot be equivalent in any cases, because reshape just changes the definition of accessing the tensor; while transpose reorganizes the element order in memory. Even we combine them to the same patterm, we still need to deal with each case separately and result in no code reuse. Please let me know if I missed something. Thanks. |
You're right. I think a set of modular patterns is probably best |
Thanks @mbrookhart @ANSHUMAN87 |
…#7656) * [Relay][Pass] Simplify consecutive transpose/layout_transform * lint * fix * support negative * comment
…#7656) * [Relay][Pass] Simplify consecutive transpose/layout_transform * lint * fix * support negative * comment
This PR adds a simplify pattern to the SImplifyExpr pass. The pattern simplifies back-to-back transpose and layout_transform ops, which can be introduced by Relay frontends or ConvertLayout pass.
cc @mbrookhart @icemelon9 @anijain2305