Skip to content

support aten::index.Tensor #921

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

Merged
merged 3 commits into from
Apr 5, 2022
Merged

Conversation

ruoqianguo
Copy link
Contributor

Description

aten::index.Tensor(Tensor self, Tensor?[] indices) -> (Tensor) is a complicated PyTorch function which can receive several indices. To focus on Video Swin Transformer, this version converter only supports one index. I will improve this converter in a future release.

Fixes #766

Type of change

Please delete options that are not relevant and/or add your own.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes

Signed-off-by: Ruoqian Guo <[email protected]>
Signed-off-by: Ruoqian Guo <[email protected]>

TORCHTRT_CHECK(
tensors.size() == 1,
"This version of Torch-TensorRT only supports one index in aten::index.Tensor");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you clarify what this means? Can I only do something like tensor[0] or something?

Copy link
Contributor Author

@ruoqianguo ruoqianguo Mar 10, 2022

Choose a reason for hiding this comment

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

In Pytorch, 'aten::index.Tensor' can receive several indices, like this:

x = torch.rand(5, 7, 10)
idx0 = torch.tensor([0, 0, 0, 0])
idx1 = torch.tensor([1, 1, 1, 1])
idx2 = torch.tensor([2, 2, 2, 2])
y1 = x[idx0, idx1, idx2] # result is like tensor([x[0, 1, 2], x[0, 1, 2], x[0, 1, 2], x[0, 1, 2]])
y2 = x[idx0] # result is like tensor([x[0, :, :], x[0, :, :], x[0, :, :], x[0, :, :]])

I only support one index as input currently like y2 = x[idx0]. We can only process tensors[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Pytorch, 'aten::index.Tensor' can receive several indices, like this:

x = torch.rand(5, 7, 10)
idx0 = torch.tensor([0, 0, 0, 0])
idx1 = torch.tensor([1, 1, 1, 1])
idx2 = torch.tensor([2, 2, 2, 2])
y1 = x[idx0, idx1, idx2] # result is like tensor([x[0, 1, 2], x[0, 1, 2], x[0, 1, 2], x[0, 1, 2]])
y2 = x[idx0] # result is like tensor([x[0, :, :], x[0, :, :], x[0, :, :], x[0, :, :]])

I only support one index as input currently like y2 = x[idx0]. We can only process tensors[0].

Hi @narendasan Is this explanation clear?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok can we improve this message to convey what this means

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @narendasan i have added some annotation and improved this message.

Copy link
Collaborator

@narendasan narendasan left a comment

Choose a reason for hiding this comment

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

LGTM

@narendasan narendasan merged commit 207b1b1 into pytorch:master Apr 5, 2022
@ncomly-nvidia
Copy link
Contributor

Fixes #468

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.

✨[Feature] Some operators need to be supported in Torch-TensorRT
3 participants