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

Fix PyTorch matmul conversion when given (2-dim, N-dim) input pair #7845

Merged
merged 13 commits into from
Apr 15, 2021
Merged

Fix PyTorch matmul conversion when given (2-dim, N-dim) input pair #7845

merged 13 commits into from
Apr 15, 2021

Conversation

yuchaoli
Copy link
Contributor

This PR change the matmul conversion in PyTorch when given (2-dim, N-dim) input pair (N>2).

Original implement conversion [2 dim matrix * 3 dim tensor] into [batch matmul], however it can be implemented by a simple [matmul] with [2 dim matrix * 2 dim matrix (reshape 3 dim tensor into 2 dim matrix)].

cc @jcf94

Copy link
Contributor

@jcf94 jcf94 left a comment

Choose a reason for hiding this comment

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

Looks good. Let's add some test on tests/python/frontend/pytorch.

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Mostly nits. Could we have a unit test to illustrate when we expect it to be a dense and others to be batch_matmul?

python/tvm/relay/frontend/pytorch.py Show resolved Hide resolved
python/tvm/relay/frontend/pytorch.py Outdated Show resolved Hide resolved
Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

LGTM. Comments are nits and feel free to ignore if no other comments need to address.

tests/python/frontend/pytorch/test_forward.py Outdated Show resolved Hide resolved
tests/python/frontend/pytorch/test_forward.py Outdated Show resolved Hide resolved
@@ -162,7 +162,7 @@ def measure_latency(model, input_shapes, output_shapes, thresh, dryruns=40):
return est


def verify_model(model_name, input_data=[], custom_convert_map={}, rtol=1e-5, atol=1e-5):
def verify_model(model_name, input_data=[], custom_convert_map={}, rtol=1e-5, atol=1e-5, expected_ops=[]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Good addition!

python/tvm/relay/frontend/pytorch.py Outdated Show resolved Hide resolved
python/tvm/relay/frontend/pytorch.py Outdated Show resolved Hide resolved
Copy link
Contributor

@wweic wweic left a comment

Choose a reason for hiding this comment

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

please resolve the rebase conflict.

@comaniac
Copy link
Contributor

@wweic it seems no conflict to the main branch? Please feel free to merge it.

@masahi masahi merged commit b24fbe7 into apache:main Apr 15, 2021
@masahi
Copy link
Member

masahi commented Apr 15, 2021

Thanks @yuchaoli @jcf94 @comaniac @wweic

mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Apr 22, 2021
…pache#7845)

* [AutoScheduler] Fix incorrectly array context device and hide info at the beginning

* Lint fix

* Lint fix

* update repo

* Fix Pytorch matmul conversion when given (2-dim, N-dim) input pair

* update measure.py

* Lint fix

* fix bug && add ut for pytorch matmul

* update ut

* Lint fix

* update commit

* Lint fix
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…pache#7845)

* [AutoScheduler] Fix incorrectly array context device and hide info at the beginning

* Lint fix

* Lint fix

* update repo

* Fix Pytorch matmul conversion when given (2-dim, N-dim) input pair

* update measure.py

* Lint fix

* fix bug && add ut for pytorch matmul

* update ut

* Lint fix

* update commit

* Lint fix
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…pache#7845)

* [AutoScheduler] Fix incorrectly array context device and hide info at the beginning

* Lint fix

* Lint fix

* update repo

* Fix Pytorch matmul conversion when given (2-dim, N-dim) input pair

* update measure.py

* Lint fix

* fix bug && add ut for pytorch matmul

* update ut

* Lint fix

* update commit

* Lint fix
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…pache#7845)

* [AutoScheduler] Fix incorrectly array context device and hide info at the beginning

* Lint fix

* Lint fix

* update repo

* Fix Pytorch matmul conversion when given (2-dim, N-dim) input pair

* update measure.py

* Lint fix

* fix bug && add ut for pytorch matmul

* update ut

* Lint fix

* update commit

* Lint fix
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
…pache#7845)

* [AutoScheduler] Fix incorrectly array context device and hide info at the beginning

* Lint fix

* Lint fix

* update repo

* Fix Pytorch matmul conversion when given (2-dim, N-dim) input pair

* update measure.py

* Lint fix

* fix bug && add ut for pytorch matmul

* update ut

* Lint fix

* update commit

* Lint fix
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.

6 participants