[Relay][ONNX] Batch_matmul to dense optimization#8440
Merged
comaniac merged 2 commits intoapache:mainfrom Jul 13, 2021
Merged
Conversation
comaniac
requested changes
Jul 9, 2021
Contributor
comaniac
left a comment
There was a problem hiding this comment.
Otherwise LGTM. Do we need a test case for this?
b5e4207 to
e83d9b9
Compare
Contributor
Author
|
@comaniac Thanks for the valuable comments. I found the Pytorch implementation https://github.com/apache/tvm/blob/main/python/tvm/relay/frontend/pytorch.py#L1624 cannot handle dynamic shapes. So I added this optimization based on the ONNX implementation. For some reason, the weight matrix of nn.dense must be static for the tvm codegen to work correctly, though using libs like mkl works just fine. I created an issue for this #8441. |
Contributor
|
Thanks @ymwangg |
ylc
pushed a commit
to ylc/tvm
that referenced
this pull request
Sep 29, 2021
* [ONNX]Add batch_matmul to dense optimization * Add extra check to avoid unnecessary reshape Co-authored-by: Ubuntu <ubuntu@ip-172-31-14-16.us-west-2.compute.internal>
zxy844288792
pushed a commit
to zxy844288792/tvm
that referenced
this pull request
Mar 4, 2022
* [ONNX]Add batch_matmul to dense optimization * Add extra check to avoid unnecessary reshape Co-authored-by: Ubuntu <ubuntu@ip-172-31-14-16.us-west-2.compute.internal>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR copied the Pytorch matmul implementation that adopts the batch_matmul to dense optimization, which significantly improves the performance of some matmul ops in bert models such as [4, 128, 768] x [768, 768] when using cublas or tensorrt.