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

Nested advanced indexing returns dimensions in the wrong order #773

Closed
zdevito opened this issue May 2, 2022 · 0 comments · Fixed by #777
Closed

Nested advanced indexing returns dimensions in the wrong order #773

zdevito opened this issue May 2, 2022 · 0 comments · Fixed by #777
Labels
actionable It is clear what should be done for this issue high priority These issues are at the top of mind for us.

Comments

@zdevito
Copy link
Contributor

zdevito commented May 2, 2022

from functorch import vmap
import torch
e = torch.rand(7, 4)
idx = torch.LongTensor([0, 1, 2, 3, 4, 5]).view(2, 3, 1)

# simple reference implementation for comparison
def _fake_vmap(f, in_dims=0):
    def w(input):
        r = [f(input.select(in_dims, i)) for i in range(input.size(in_dims))]
        return torch.stack(r, in_dims)
    return w

def with_vmap(_vmap):
    def g(idx_):
        def f(e_):
            return e_[idx_]
        return _vmap(f, in_dims=1)(e)
    r = _vmap(_vmap(g))(idx)
    return r

a = with_vmap(vmap)
b = with_vmap(_fake_vmap)
print(a.size(), b.size())
assert a == b

Produces:

torch.Size([4, 2, 3, 1]) torch.Size([2, 3, 1, 4])
Traceback (most recent call last):
  File "v.py", line 25, in <module>
    assert a == b
RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 1
@zou3519 zou3519 added actionable It is clear what should be done for this issue high priority These issues are at the top of mind for us. labels May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable It is clear what should be done for this issue high priority These issues are at the top of mind for us.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants