dkoutsou opened a new issue #6607:
URL: https://github.com/apache/incubator-tvm/issues/6607


   I have the following pytorch program
   `import torch
   import tvm
   from tvm import relay
   from tvm.contrib import graph_runtime
   
   class PytorchModel(torch.nn.Module):
       def forward(self, vector1, vector2):
           resized_vector1 = vector1.view(1, -1)
           resized_vector2 = vector2.view(-1, 1)
           matches = (resized_vector1 ==
                           resized_vector2).int().sum()
   
           return matches
   
   vector1 = torch.zeros([10], dtype=torch.int32)
   vector2 = torch.zeros([10], dtype=torch.int32)
   for i in range(10):
       vector1[i] = i
       vector2[i] = i
   
   init_model = PytorchModel()
   
   scripted_model = torch.jit.script(init_model)
   matches = scripted_model(vector1, vector2)
   
   input1_name = 'input0'
   input2_name = 'input1'
   shape_list = [(input1_name, (10,)),
                 (input2_name, (10,))]
   target = 'llvm'
   ctx = tvm.cpu()
   vector1_tvm = tvm.nd.array(vector1, ctx)
   vector2_tvm = tvm.nd.array(vector2, ctx)
   
   target = 'llvm'
   ctx = tvm.cpu()
   
   model, params = relay.frontend.from_pytorch(scripted_model, shape_list)
   with tvm.transform.PassContext(opt_level=3):
       executor = relay.create_executor("vm", mod=model, ctx=ctx, target=target)
       tvm_model = executor.evaluate()
   
   matches = tvm_model(input0=vector1_tvm, input1=vector2_tvm)`
   
   and when I run it I get the following error: 
   `WARNING:root:Untyped Tensor found, assume it is float32
   WARNING:root:Untyped Tensor found, assume it is float32
   WARNING:root:Untyped Tensor found, assume it is float32
   WARNING:root:Untyped Tensor found, assume it is float32
   WARNING:root:Untyped Tensor found, assume it is float32
   WARNING:root:Untyped Tensor found, assume it is float32
   Traceback (most recent call last):
     File "reproduce_bug.py", line 43, in <module>
       matches = tvm_model(input0=vector1_tvm, input1=vector2_tvm)
     File 
"/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/relay/backend/vm.py",
 line 265, in _vm_wrapper
       return self.vm.run(*args)
     File 
"/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/runtime/vm.py",
 line 424, in run
       return self.invoke("main", *args, **kwargs)
     File 
"/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/runtime/vm.py",
 line 406, in invoke
       return self._invoke(func_name)
     File 
"/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/_ffi/_ctypes/packed_func.py",
 line 237, in __call__
       raise get_last_ffi_error()
   tvm._ffi.base.TVMError: Traceback (most recent call last):
     [bt] (6) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(TVMFuncCall+0x65)
 [0x7f0cb751b2f5]
     [bt] (5) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x181e254)
 [0x7f0cb7575254]
     [bt] (4) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::vm::VirtualMachine::Invoke(tvm::runtime::vm::VMFunction
 const&, std::vector<tvm::runtime::ObjectRef, 
std::allocator<tvm::runtime::ObjectRef> > const&)+0xd9) [0x7f0cb75745e9]
     [bt] (3) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::vm::VirtualMachine::RunLoop()+0x2c52)
 [0x7f0cb7573692]
     [bt] (2) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::vm::VirtualMachine::InvokePacked(long,
 tvm::runtime::PackedFunc const&, long, long, 
std::vector<tvm::runtime::ObjectRef, std::allocator<tvm::runtime::ObjectRef> > 
const&)+0x23b) [0x7f0cb756f71b]
     [bt] (1) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x17d95d0)
 [0x7f0cb75305d0]
     [bt] (0) 
/home/dkoutsou/env/lib/python3.6/site-packages/tvm-0.7.dev1-py3.6-linux-x86_64.egg/tvm/libtvm.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x82)
 [0x7f0cb68e8f52]
     File "/home/dkoutsou/tvm/src/runtime/library_module.cc", line 78
   TVMError: Check failed: ret == 0 (-1 vs. 0) : Assert fail: 
(((tir.tvm_struct_get(arg0, 0, 5) == (uint8)2) && (tir.tvm_struct_get(arg0, 0, 
6) == (uint8)32)) && (tir.tvm_struct_get(arg0, 0, 7) == (uint16)1)), arg0.dtype 
is expected to be float32`
   
   My library versions are:
   `
   torch==1.6.0
   tvm==0.7.dev1
   `
   
   And I have compliled TVM using the binaries for clang and LLVM (version 10, 
for ubuntu 18.04). 
   
   Is there any way around this implicit cast? I tried to cast my vectors 
directly using `.int()` in the beginning of the `forward` function, but this 
didn't solve the issue.
   
   I would appreciate any help!
   


----------------------------------------------------------------
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:
[email protected]


Reply via email to