1

I made and trained a pytorch v1.4 model that predicts a sin() value (based on an example found on the web). Inference works. I then tried to compile it with TVM v0.8dev0 and llvm 10 on Ubuntu with a x86 cpu. I followed the TVM setup guide and ran some tutorials for onnx that do work. I mainly used existing tutorials on TVM to figure out the procedure below. Note that I'm not a ML nor DataScience engineer. These were my steps:

import tvm, torch, os
from tvm import relay
state = torch.load("/home/dude/tvm/tst_state.pt") # load the trained pytorch state
import tst
m = tst.Net()
m.load_state_dict(state) # init the model with its trained state
m.eval()

sm = torch.jit.trace(m, torch.tensor([3.1415 / 4]))  # convert to a scripted model

# the model only takes 1 input for inference hence [("input0", (1,))]
mod, params = tvm.relay.frontend.from_pytorch(sm, [("input0", (1,))])
mod.astext # outputs some small relay(?) script

with tvm.transform.PassContext(opt_level=1):
  lib = relay.build(mod, target="llvm", target_host="llvm", params=params)

The last line gives me this error that I don't know how to solve nor where I went wrong. I hope that someone can pinpoint my mistake ...

    ... removed some lines here ...
  [bt] (3) /home/dude/tvm/build/libtvm.so(TVMFuncCall+0x5f) [0x7f5cd65660af]
  [bt] (2) /home/dude/tvm/build/libtvm.so(+0xb4f8a7) [0x7f5cd5f318a7]
  [bt] (1) /home/dude/tvm/build/libtvm.so(tvm::GenericFunc::CallPacked(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const+0x1ab) [0x7f5cd5f315cb]
  [bt] (0) /home/tvm/build/libtvm.so(+0x1180cab) [0x7f5cd6562cab]
  File "/home/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
    rv = local_pyfunc(*pyargs)
  File "/home/tvm/python/tvm/relay/op/strategy/x86.py", line 311, in dense_strategy_cpu
    m, _ = inputs[0].shape
ValueError: not enough values to unpack (expected 2, got 1)
  • 1
    Usually the best palce to get answers is the TVM's official forums. my previous attempt with tvm were plagued with lots of issues, and I ultimately found them on the official forums since the devs lurk there all the time. make sure you post your question first. – Hossein Oct 25 '20 at 17:44
  • 1
    by the way if you missed the forums, [here it is](https://discuss.tvm.apache.org/) – Hossein Oct 25 '20 at 17:45
  • 1
    I found that I needed an input shape of (1, 1) to make it pass. – ml-nor-ds-dude Oct 26 '20 at 09:48

0 Answers0