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/09 13:28:05 UTC

[GitHub] [incubator-tvm] j-paulus opened a new issue #6432: [torch] Using torch.stack causes BatchNorm not to be able to determine output shape

j-paulus opened a new issue #6432:
URL: https://github.com/apache/incubator-tvm/issues/6432


   When compiling a PyTorch model that contains `torch.stack` followed by `BatchNorm`, the BN is unable to determine the input shape. My assumption is that the return value from `stack()` is invalid, but the problem may also well be in BN.
   
   Minimal code triggering the issue:
   ```
   import torch
   from tvm import relay
   
   class TriggerBug(torch.nn.Module):
       def __init__(self):
           super(TriggerBug, self).__init__()
           self.bn = torch.nn.BatchNorm2d(2)  # input C:(N,C,H,W)
   
       def forward(self, x):
           x = torch.stack((x, x), dim=3)
           #x = torch.stack((x, x), dim=-1)  # this fails equally
           return self.bn(x)
   
   x_in = torch.randn(1, 2, 3)
   torch_model = TriggerBug()
   traced_model = torch.jit.trace(torch_model, (x_in,))
   
   mod, params = relay.frontend.from_pytorch(traced_model, [('x_in', x_in.shape)])
   ```
   
   The result is:
   
   >  mod, params = relay.frontend.from_pytorch(traced_model, [('x_in', x_in.shape)])
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/relay/frontend/pytorch.py", line 2820, in from_pytorch
   >     default_dtype=default_dtype)
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/relay/frontend/pytorch.py", line 2728, in convert_operators
   >     default_dtype=default_dtype))
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/relay/frontend/pytorch.py", line 870, in _impl
   >     channels = _infer_shape(data)
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/relay/frontend/common.py", line 486, in infer_shape
   >     out_type = infer_type(inputs, mod=mod)
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/relay/frontend/common.py", line 465, in infer_type
   >     new_mod = IRModule.from_expr(node)
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/ir/module.py", line 236, in from_expr
   >     return _ffi_api.Module_FromExpr(expr, funcs, defs)
   >   File "/Users/name/opt/anaconda3/envs/tvm/lib/python3.7/site-packages/tvm-0.7.dev1-py3.7-macosx-10.9-x86_64.egg/tvm/_ffi/_ctypes/packed_func.py", line 225, in __call__
   >     raise get_last_ffi_error()
   > tvm._ffi.base.TVMError: Traceback (most recent call last):
   >   [bt] (8) 9   libtvm.dylib                        0x000000011e44ca45 tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&) + 133
   >   [bt] (7) 8   libtvm.dylib                        0x000000011e44cd16 tvm::NodeFunctor<void (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*) const + 246
   >   [bt] (6) 7   libtvm.dylib                        0x000000011e67785a tvm::relay::ExprVisitor::VisitExpr_(tvm::relay::CallNode const*) + 330
   >   [bt] (5) 6   libtvm.dylib                        0x000000011e677248 tvm::relay::ExprVisitor::VisitExpr(tvm::RelayExpr const&) + 248
   >   [bt] (4) 5   libtvm.dylib                        0x000000011e44ca45 tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&) + 133
   >   [bt] (3) 4   libtvm.dylib                        0x000000011e44cd16 tvm::NodeFunctor<void (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*) const + 246
   >   [bt] (2) 3   libtvm.dylib                        0x000000011e47c8d8 tvm::relay::TypeVarEVisitor::VisitExpr_(tvm::ConstructorNode const*) + 56
   >   [bt] (1) 2   libtvm.dylib                        0x000000011dc4ca64 tvm::IRModuleNode::LookupTypeDef(tvm::GlobalTypeVar const&) const + 420
   >   [bt] (0) 1   libtvm.dylib                        0x000000011da5f7bf dmlc::LogMessageFatal::~LogMessageFatal() + 111
   >   File "/Users/puu/code/python/tvm/src/ir/module.cc", line 294
   > TVMError: Check failed: it != type_definitions.end(): There is no definition of static_tensor_float32_1_2_3_t
   
   TVM version: 0.7.dev1, installed from git revision 84fa62617
   PyTorch version: 1.7.0.dev20200908
   
   


----------------------------------------------------------------
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 #6432: [torch] Using torch.stack causes BatchNorm not to be able to determine output shape

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #6432:
URL: https://github.com/apache/incubator-tvm/issues/6432#issuecomment-689713830


   @j-paulus I can see where the problem is coming from. Will fix soon.


----------------------------------------------------------------
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] zhiics edited a comment on issue #6432: [torch] Using torch.stack causes BatchNorm not to be able to determine output shape

Posted by GitBox <gi...@apache.org>.
zhiics edited a comment on issue #6432:
URL: https://github.com/apache/incubator-tvm/issues/6432#issuecomment-689652572


   Thanks for reporting this. Please open the thread at https://discuss.tvm.apache.org/ for more discussions. It might be related to #6268 as well.


----------------------------------------------------------------
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] zhiics closed issue #6432: [torch] Using torch.stack causes BatchNorm not to be able to determine output shape

Posted by GitBox <gi...@apache.org>.
zhiics closed issue #6432:
URL: https://github.com/apache/incubator-tvm/issues/6432


   


----------------------------------------------------------------
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] zhiics commented on issue #6432: [torch] Using torch.stack causes BatchNorm not to be able to determine output shape

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #6432:
URL: https://github.com/apache/incubator-tvm/issues/6432#issuecomment-689652572


   Thanks for reporting this. Please open the thread at https://discuss.tvm.apache.org/ for more discussions.


----------------------------------------------------------------
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 #6432: [torch] Using torch.stack causes BatchNorm not to be able to determine output shape

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #6432:
URL: https://github.com/apache/incubator-tvm/issues/6432#issuecomment-689772525


   @j-paulus this should be fixed in https://github.com/apache/incubator-tvm/pull/6433. The following script works for me
   
   ```
   import torch
   from tvm import relay
   
   class TriggerBug(torch.nn.Module):
       def __init__(self):
           super(TriggerBug, self).__init__()
           self.bn = torch.nn.BatchNorm2d(8)  # input C:(N,C,H,W)
   
       def forward(self, x):
           x = torch.stack((x, x), dim=3)
           return self.bn(x)
   
   x_in = torch.randn(8, 8, 8)
   torch_model = TriggerBug()
   traced_model = torch.jit.trace(torch_model, (x_in,))
   
   mod, params = relay.frontend.from_pytorch(traced_model, [('x_in', x_in.shape)])
   
   print(mod["main"])
   ```
   
   Thanks for reporting many issues in the PyTorch frontend. I really appreciate them!


----------------------------------------------------------------
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