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

[Torch] Various updates for PyTorch frontend #7348

Merged
merged 9 commits into from
Jan 27, 2021
Merged

Conversation

masahi
Copy link
Member

@masahi masahi commented Jan 27, 2021

This PR adds various updates to the PyTorch frontend, to fully support the recent transformer based object detection model from facebook, DETR https://github.com/facebookresearch/detr. After this PR, DETR runs on TVM and gets the correct results. TVM with auto scheduled GPU conv2d and batched matmul is 1.4x faster than PyTorch in my environment.

Also added various missing ops reported by hummingbird projects. @interesaaat

  • Adds support for ops requested by hummingbird project: logical_and, masked_select, sort and argsort. masked_select requires VM to run.
  • Adds support for cumsum and masked_fill op, to enable importing DETR https://github.com/facebookresearch/detr. cumsum is also requested by hummingbird.
  • Fix negative indexing using mode="wrap" in Relay take op. Without this, the result doesn't match with DETR.
  • Remove explicit broadcast_to before batch_matmul. Without it, memory usage blows up during constant evaluation of DETR. This is the same issue as [Topi] Allow batch_matmul to broadcast along batch dimension. #6616, please see the explanation there.
  • Add torch.nn.Transformer to the tests.

Since torch.sort returns both sorted values and indices while the Relay one doesn't, torch.sort conversion is not efficient, especially for multidimensional input (currently does both sort and argsort!). Suggestions for a better implementation are welcome. UPDATE: fixed

please review @siju-samuel @jwfromm @kevinthesun @t-vi

Copy link
Member

@siju-samuel siju-samuel left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@t-vi t-vi 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!

Since torch.sort returns both sorted values and indices while the Relay one doesn't, torch.sort conversion is not efficient, especially for multidimensional input (currently does both sort and argsort!). Suggestions for a better implementation are welcome.

I think gather is the direct equivalent of how you use take on 1d. Maybe it's worth fixing this in this PR.

@masahi
Copy link
Member Author

masahi commented Jan 27, 2021

@t-vi Thanks, I think I tried gather before but for some reason I got wrong results, so I gave up gather. I tried again now, and it worked :) I don't know what I was doing, but I'm happy now.

@masahi masahi merged commit 59e0a4a into apache:main Jan 27, 2021
@masahi
Copy link
Member Author

masahi commented Jan 27, 2021

Thanks @siju-samuel @t-vi

alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 11, 2021
* add conversion for detr

* remove explicit broadcast_to before batched matmul

* use take with wrap mode

* add test for transformer and negative indices

* add sort and argsort

* add logical_and

* support masked_select

* add gpu targets to masked_select test

* improve sort conversion
electriclilies pushed a commit to electriclilies/tvm that referenced this pull request Feb 18, 2021
* add conversion for detr

* remove explicit broadcast_to before batched matmul

* use take with wrap mode

* add test for transformer and negative indices

* add sort and argsort

* add logical_and

* support masked_select

* add gpu targets to masked_select test

* improve sort conversion
Lokiiiiii pushed a commit to Lokiiiiii/tvm that referenced this pull request Mar 2, 2021
* add conversion for detr

* remove explicit broadcast_to before batched matmul

* use take with wrap mode

* add test for transformer and negative indices

* add sort and argsort

* add logical_and

* support masked_select

* add gpu targets to masked_select test

* improve sort conversion
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2021
* add conversion for detr

* remove explicit broadcast_to before batched matmul

* use take with wrap mode

* add test for transformer and negative indices

* add sort and argsort

* add logical_and

* support masked_select

* add gpu targets to masked_select test

* improve sort conversion
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.

3 participants