You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/09/07 07:46:12 UTC
[GitHub] [incubator-tvm] j-paulus opened a new issue #6407: Bug: Reshape with dynamic size in torch model failing as the dynamic shape expression is not evaluated
j-paulus opened a new issue #6407:
URL: https://github.com/apache/incubator-tvm/issues/6407
When trying to compile a pytorch model that has a reshape() where one or more of the sizes is a result from a computation, the computation is not evaluated properly, but provided as-is to int() cast. And this fails.
A small example triggering the error:
```
import torch
from tvm import relay
class TriggerBug(torch.nn.Module):
def __init__(self):
super(TriggerBug, self).__init__()
def forward(self, x):
x_shape = x.shape
return x.reshape((x_shape[0] * x_shape[1], x_shape[2]))
x_in = torch.randn(2, 3, 4)
torch_model = TriggerBug()
traced_model = torch.jit.trace(torch_model, x_in)
input_name = 'x_in'
shape_list = [(input_name, x_in.shape)]
mod, params = relay.frontend.from_pytorch(traced_model, shape_list)
```
The result:
>
> Traceback (most recent call last):
> File "/Users/name/code/python/torch2tvm_reshape_bug.py", line 30, in <module>
> mod, params = relay.frontend.from_pytorch(traced_model, shape_list)
> File "/Users/name/opt/anaconda3/envs/env/lib/python3.8/site-packages/tvm-0.7.dev1-py3.8-macosx-10.9-x86_64.egg/tvm/relay/frontend/pytorch.py", line 2825, in from_pytorch
> ret = convert_operators(_get_operator_nodes(graph.nodes()),
> File "/Users/name/opt/anaconda3/envs/env/lib/python3.8/site-packages/tvm-0.7.dev1-py3.8-macosx-10.9-x86_64.egg/tvm/relay/frontend/pytorch.py", line 2734, in convert_operators
> relay_out = relay_op(inputs, _get_input_types(op_node, outputs,
> File "/Users/name/opt/anaconda3/envs/env/lib/python3.8/site-packages/tvm-0.7.dev1-py3.8-macosx-10.9-x86_64.egg/tvm/relay/frontend/pytorch.py", line 1138, in _impl
> return _op.transform.reshape(data, new_shape)
> File "/Users/name/opt/anaconda3/envs/env/lib/python3.8/site-packages/tvm-0.7.dev1-py3.8-macosx-10.9-x86_64.egg/tvm/relay/op/transform.py", line 226, in reshape
> tempshape.append(int(shape))
> TypeError: int() argument must be a string, a bytes-like object or a number, not 'Call'
The problem is that the contents of `newshape` is a list `[CallNode(Op(multiply), [Constant(2), Constant(3)], (nullptr), []), 4]`, the first element is of type `tvm.relay.expr.Call`, and this is not evaluated but provided to the `int()` cast as-is.
TVM version 0.7.dev1 cloned from git on 03.09.2020.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-tvm] j-paulus commented on issue #6407: Bug: Reshape with dynamic size in torch model failing as the dynamic shape expression is not evaluated
Posted by GitBox <gi...@apache.org>.
j-paulus commented on issue #6407:
URL: https://github.com/apache/incubator-tvm/issues/6407#issuecomment-688284068
Applying the patch locally seems to fix the issue. Thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-tvm] masahi commented on issue #6407: Bug: Reshape with dynamic size in torch model failing as the dynamic shape expression is not evaluated
Posted by GitBox <gi...@apache.org>.
masahi commented on issue #6407:
URL: https://github.com/apache/incubator-tvm/issues/6407#issuecomment-688254421
Thanks, should be fixed by https://github.com/apache/incubator-tvm/pull/6411
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-tvm] j-paulus closed issue #6407: Bug: Reshape with dynamic size in torch model failing as the dynamic shape expression is not evaluated
Posted by GitBox <gi...@apache.org>.
j-paulus closed issue #6407:
URL: https://github.com/apache/incubator-tvm/issues/6407
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org