Skip to content
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

[GraphOptimizer] Optimize consecutive non-inverse transposes #2335

Merged
merged 4 commits into from Feb 4, 2019
Merged

[GraphOptimizer] Optimize consecutive non-inverse transposes #2335

merged 4 commits into from Feb 4, 2019

Conversation

Squadrick
Copy link
Contributor

@Squadrick Squadrick commented Feb 2, 2019

Description

  • Before: GraphOptimizer would only combine consecutive tranposes if the resultant was an identity transpose.
  • After: GraphOptimizer combines all consecutive tranposes, including non-inverse pairs.

Testing

  • mergeNonInverseTransposes replaces dontCancelTwoTransposesIfNotMatching unit test in GraphOptzTest.cpp.
  • The unit test checks that multiple consecutive non-inverse transposes are combined into a single transpose node.

Documentation

  • Documentation has been updated in docs/Optimizations.md under graph optimization.

Issues

* Two consecutive non-inverse transposes are fused in `sinkCode()`
* Replace `dontCancelTwoTransposesIfNotMatching` unittest with
`mergeNonInverseTransposes`
@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Contributor

@jfix71 jfix71 left a comment

Choose a reason for hiding this comment

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

@Squadrick Thanks for the PR! Looks like it was very clean to implement.

I believe that this new functionality subsumes the other optimization that checks if two transposes reverse each other. Therefore you should be able to remove it along with isIdentityShuffle(mask1, mask2).

lib/Optimizer/GraphOptimizer.cpp Outdated Show resolved Hide resolved
tests/unittests/GraphOptzTest.cpp Outdated Show resolved Hide resolved
tests/unittests/GraphOptzTest.cpp Show resolved Hide resolved
tests/unittests/GraphOptzTest.cpp Show resolved Hide resolved
Copy link
Contributor

@jackm321 jackm321 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!
Please use the PULL_REQUEST_TEMPLATE.md format.
Also, like @jfix71 said, you should be able to remove the isIdentityShuffle(mask1, mask2) logic because transposed that are inverses of each other should be combined by your logic to a single identity then removed.

lib/Optimizer/GraphOptimizer.cpp Outdated Show resolved Hide resolved
@nadavrot
Copy link
Contributor

nadavrot commented Feb 3, 2019

Nice work @Squadrick !

* Add documentation about combining multiple consecutive tranposes

* Remove redundant combining of tranposes that result in an identity

* Add comments in the test case, clearly showing intermediate tensor
dims
@Squadrick
Copy link
Contributor Author

Hey, guys. I made the requested changes, and I've also updated the documentation.

@jackm321 I've updated the PR to follow the specified templated.

Copy link
Contributor

@jfix71 jfix71 left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks @Squadrick.

I left one nit to resolve, and additionally it looks like our CI is breaking because the isIdentityShuffle() that you removed a call to is no longer used.

Once you remove the unused isIdentityShuffle() and fix the nit we can land this.

tests/unittests/GraphOptzTest.cpp Outdated Show resolved Hide resolved
* `isIdentityShuffle()` is not longer required, and is removed.

* Add period at end of comment
@Squadrick
Copy link
Contributor Author

@jfix71 Removed isIdentityShuffle(), and fixed the nit. Could you take a look?

Copy link
Contributor

@jfix71 jfix71 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks again @Squadrick!

@jfix71 jfix71 merged commit e2f93ae into pytorch:master Feb 4, 2019
@Squadrick Squadrick deleted the consecutive-transposes branch February 5, 2019 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants