Can not import relay in tvm runtime

I built and installed tvm runtime
when I tried to import relay I got the following error

    from tvm import relay
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-aarch64.egg/tvm/relay/__init__.py", line 24, in <module>
    from . import expr_functor
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-aarch64.egg/tvm/relay/expr_functor.py", line 24, in <module>
    from .op import Op
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-aarch64.egg/tvm/relay/op/__init__.py", line 20, in <module>
    from .op import get, register, register_schedule, register_compute, register_gradient, \
  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.dev0-py3.5-linux-aarch64.egg/tvm/relay/op/op.py", line 19, in <module>
    import topi
ImportError: No module named 'topi'

but I can not install topi because make runtime does not build libtvm_topi.so.

Do we need relay for runtime?

I just saw that some people use relay.load_param_dict during the inference:

params = relay.load_param_dict(bytearray(open(path_param, "rb").read()))
m.set_input(**params)

we can probably replace it with

params = bytearray(open(path_param, "rb").read())
m.load_params(params)

What you think?

Yes. We can load params with module method.

code example

import numpy as np
import tvm
import time
 
from tvm.contrib import graph_runtime
 
data_shape = (1, 3, 512, 512)
loaded_json = open("yolo_graph.json").read()
loaded_lib = tvm.module.load("yolo_lib.tar")
loaded_params = bytearray(open("yolo_param.params", "rb").read())
input_data = tvm.nd.array(np.random.uniform(size=data_shape).astype("float32"))
 
ctx = tvm.gpu(0)
module = graph_runtime.create(loaded_json, loaded_lib, ctx)
module.load_params(loaded_params)
...

Hi, I’m new to TVM. I also met this problem when trying out demo/tutorials.

I install the docker image demo_gpu with build.sh by following

./tvm/docker/build.sh demo_gpu /bin/bash

then I run relay_quick_start.py under tutorials/get_started and get this error when trying import relay.

>>> from tvm.relay import testing
Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/tvm/python/tvm/relay/__init__.py", line 26, in <module>
    from . import expr_functor

  File "/usr/tvm/python/tvm/relay/expr_functor.py", line 24, in <module>
    from .op import Op

  File "/usr/tvm/python/tvm/relay/op/__init__.py", line 20, in <module>
    from .op import get, register, register_schedule, register_compute, register_gradient, \

  File "/usr/tvm/python/tvm/relay/op/op.py", line 19, in <module>
    import topi

ModuleNotFoundError: No module named 'topi'

ENV description:

ubuntu : 16.04
docker : 19.03.11

Finally, I found the reason is in `docker/install/install_tvm_gpu.sh’

# checkout a hash-tag
git checkout 4b13bf668edc7099b38d463e5db94ebc96c80470

The default installation script to install tvm_gpu checkout a hash-tag of 2019, which do not contain the topi package.

So I comment on this line and rebuild the docker image. This helps me solve the problem.