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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[torch.jit.script] Support tensor indexing after an Ellipsis #34837

Open
alanhdu opened this issue Mar 16, 2020 · 3 comments
Open

[torch.jit.script] Support tensor indexing after an Ellipsis #34837

alanhdu opened this issue Mar 16, 2020 · 3 comments
Labels
enhancement Not as big of a feature, but technically not a bug. Should be easy to fix oncall: jit Add this issue/PR to JIT oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects

Comments

@alanhdu
Copy link
Contributor

alanhdu commented Mar 16, 2020

馃殌 Feature

Support Tensor indexing after an ellipsis: right now the following code:

@torch.jit.script
def zero_diag(inputs: torch.Tensor) -> torch.Tensor:
    dim = inputs.shape[-1]
    inputs[..., torch.range(0, dim), torch.range(0, dim)] = 0

fails with:

Ellipses followed by tensor indexing is currently not supported:
  File "<ipython-input-105-deac139d15e2>", line 4
def zero_diag(inputs: torch.Tensor) -> torch.Tensor:
    dim = inputs.shape[-1]
    inputs[..., torch.range(0, dim), torch.range(0, dim)] = 0
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE

Motivation

For our application, we would like to manipulate the diagonal of a batch of matrices, which is most easily expressed by manipulating inputs[..., range(N), range(N)]. Unfortunately, Torch does not currently support this when using torch.jit.script.

Another use-case is to vectorize a batch of symmetric matrices: ideally, we could do something like:

ind = torch.triu_indices(N, N)
vectors = matrices[..., ind[0], ind[1]]

cc @suo

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Mar 16, 2020
@ailzhang ailzhang added the enhancement Not as big of a feature, but technically not a bug. Should be easy to fix label Mar 17, 2020
@ailzhang
Copy link
Contributor

Thanks @alanhdu for the feature request! @driazati IIRC you have a list of language features we'll be adding, does this fall into our plan?

@ailzhang ailzhang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Mar 17, 2020
@vfdev-5
Copy link
Collaborator

vfdev-5 commented Jun 30, 2020

Various padding mode of tensor can be also implemented with tensor indexing. And it would be very nice to have jit support for that too.

@gmagogsfm gmagogsfm added this to Need triage in JIT Triage via automation Apr 4, 2021
@gmagogsfm gmagogsfm moved this from Need triage to Pending in JIT Triage Apr 4, 2021
@Abhijit-2592
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Not as big of a feature, but technically not a bug. Should be easy to fix oncall: jit Add this issue/PR to JIT oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
JIT Triage
  
Pending
Development

No branches or pull requests

5 participants