Skip to content

[torch] slice with Var Length fails #7546

@apivovarov

Description

@apivovarov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions