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] slice with Var Length fails #7546

Closed
apivovarov opened this issue Feb 27, 2021 · 0 comments · Fixed by #7549
Closed

[torch] slice with Var Length fails #7546

apivovarov opened this issue Feb 27, 2021 · 0 comments · Fixed by #7549

Comments

@apivovarov
Copy link
Contributor

apivovarov commented Feb 27, 2021

torch.slice works fine for fixed ranges (e.g. a[0:2]). If instead of particular number I use Var for Length (just for Length) (e.g. a[0, L] then from_pytorch fails.

The code to reproduce the issue:

import torch
import tvm
from tvm import relay
        
class Net(torch.nn.Module):
    def __init__(self):
        super(Net, self).__init__()
    def forward(self, values, length):
        return values[0:length]


net = Net()
a = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
len = torch.tensor(2)
net(a, len)

traced_net = torch.jit.trace(net, (a, len))

shape_list = [("input0", [3,3]),("input1", []),]
mod, params = relay.frontend.from_pytorch(traced_net, shape_list)

Error:

>>> mod, params = relay.frontend.from_pytorch(traced_net, shape_list)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pivovaa/workspace/tvm/python/tvm/relay/frontend/pytorch.py", line 3180, in from_pytorch
    ret = converter.convert_operators(_get_operator_nodes(graph.nodes()), outputs, ret_name)[0]
  File "/Users/pivovaa/workspace/tvm/python/tvm/relay/frontend/pytorch.py", line 2601, in convert_operators
    relay_out = relay_op(
  File "/Users/pivovaa/workspace/tvm/python/tvm/relay/frontend/pytorch.py", line 403, in slice
    if target_begin == 0 and target_end >= index_size_limit and stride == 1:
  File "/Users/pivovaa/workspace/tvm/python/tvm/relay/expr.py", line 84, in __ge__
    raise TypeError('convert "%s" with `const` first' % str(other))
TypeError: convert "9223372036854775807" with `const` first

@masahi

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 a pull request may close this issue.

1 participant