@broccoli Yes it should. Could you provide more information about your environment?
@vinx13 ok then I found out the problem, the libtvm_topi.so
lib is not installed/copied in the lib/python3.5/site-packages/topi
.
I’m using python setup.py bdist_wheel
from the wheel
package to build, distribute and install the whl in different virtual environments.
When using python setup.py install
as documented the library is actually copied (to lib/python3.5/site-packages/topi-0.6.dev0-py3.5.egg/topi/libtvm_topi.so
) and it works.
Maybe https://github.com/dmlc/tvm/blob/605b5e6074f01317b4afe03fc2fe5f58f1b36d89/topi/python/topi/cpp.py#L32 should be changed to report an error if nothing was found?
Or assert that _LIB
https://github.com/dmlc/tvm/blob/605b5e6074f01317b4afe03fc2fe5f58f1b36d89/topi/python/topi/cpp.py#L42 is not None
?
Did this Question been closed?I have the same problem
It doesn’t work in my case , I use “from …cpp.image import resize” successful in deformable_conv2d.py, but error for ‘bilinear_sample_nchw’.
Ok
This problem did related to the libtvm_topi.so, do 'export LD_LIBRARY_PATH=/lib/python3.5/site-packages/ topi-0.6.dev0-py3.5.egg/topi
then it works.
I met the same problem on windows, hope anyone who solved the problem on windows could give me some hints, thank you in advance
Try: On windows, instead of setting LD_LIBRARY_PATH, you need to set PATH environment variable.
Same issue, tvm, nnvm and topi were installed after the build
~/tvm/python$ sudo python3 setup.py install
~/tvm/nnvm/python$ sudo python3 setup.py install
~/tvm/topi/python$ sudo python3 setup.py install
But model compilation fails
Traceback (most recent call last):
File "./compile.py", line 84, in <module>
from tvm import relay
File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/__init__.py", line 27, in <module>
from . import expr_functor
File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/expr_functor.py", line 24, in <module>
from .op import Op
File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.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.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/op/op.py", line 19, in <module>
import topi
File "/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi/__init__.py", line 43, in <module>
from . import nn
File "/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi/nn/__init__.py", line 23, in <module>
from .deformable_conv2d import *
File "/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi/nn/deformable_conv2d.py", line 23, in <module>
from ..cpp.image import bilinear_sample_nchw
ImportError: cannot import name 'bilinear_sample_nchw'
If tvm, nnvm and topi were installed using setup.py we do not need to set LD_LIBRARY_PATH
Anyone looking at the issue?
@tqchen @yzhliu Do you know why import topi
or from tvm import relay
needs LD_LIBRARY_PATH
to point to libtvm_topi.so
folder explicitly now?
I looked at the folder to where topi
was installed using setup.py
- the folder does have libtvm_topi.so
Topi folder:
/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi/
Why I need to explicitly export LD_LIBRARY_PATH=/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi
Why topi can not find libtvm_topi.so
in its own folder automatically?
It’s just a broken path error, you can do
export LD_LIBRARY_PATH=/home/suhas/.local/lib/python3.6/site-packages/topi-0.6.dev0-py3.6.egg/topi
likely you have two topi so files in your path and the wrong one was imported
@vinx13 @tqchen To prevent any side effects from previously installed soft I create new Docker image using the following Dockerfile
FROM ubuntu:19.10
RUN apt update
RUN apt install -y build-essential
RUN apt install -y llvm-9 clang-9
RUN apt install -y cmake git wget curl vim zip
RUN apt install -y python3 python3-dev
RUN apt install -y libedit-dev libxml2-dev antlr4
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py && rm get-pip.py
RUN pip3 install numpy decorator attrs antlr4-python3-runtime
WORKDIR /root
RUN git clone --recursive https://github.com/apache/incubator-tvm.git tvm
WORKDIR /root/tvm/build
RUN cmake -DUSE_LLVM=ON -DUSE_ANTLR=ON .. && make -j$(nproc)
WORKDIR /root/tvm/python
RUN python3 setup.py install
WORKDIR /root/tvm/nnvm/python
RUN python3 setup.py install
WORKDIR /root/tvm/topi/python
RUN python3 setup.py install
Create image and start container with freshly build and installed TVM
docker build .
docker run -ti <image_id>
inside the container run
python3
import topi
Error
python3
>>> import topi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/topi-0.6.dev0-py3.7.egg/topi/__init__.py", line 43, in <module>
from . import nn
File "/usr/local/lib/python3.7/dist-packages/topi-0.6.dev0-py3.7.egg/topi/nn/__init__.py", line 23, in <module>
from .deformable_conv2d import *
File "/usr/local/lib/python3.7/dist-packages/topi-0.6.dev0-py3.7.egg/topi/nn/deformable_conv2d.py", line 23, in <module>
from ..cpp.image import bilinear_sample_nchw
ImportError: cannot import name 'bilinear_sample_nchw' from 'topi.cpp.image' (/usr/local/lib/python3.7/dist-packages/topi-0.6.dev0-py3.7.egg/topi/cpp/image.py)
>>>
TVM has a custom library loading mechanism that is different from the Python way, you can find the library searching in https://github.com/apache/incubator-tvm/blob/master/python/tvm/_ffi/libinfo.py
I found that the change which causes import topi
to fail was merged between Nov 10 and Nov 15, between the following 2 commits
import topi works
Nov 10 [tutorial] Relay pass infra tutorial (#4083) - cff62bdbd20bab3ebcc27213be1e6d79da00c842
import topi fails
Nov 15 proper device query through rocm api (#4305) - 022b285dce9822ea6dcd9147b21ccbb33029610a
topi/python/topi/cpp/__init__.py
was added on Nov 15
https://github.com/apache/incubator-tvm/commits/master/topi/python/topi/cpp
@tqchen @vinx13 After topi/python/topi/cpp/__init__.py
was added to the code import topi
needs libtvm_topi.so
but for some reason it only looks to tvm installation folder to find the libs but not to topi installation folder.
- we can copy
libtvm_topi.so
to tvm installation folder - or include topi installation folder to the list of folders where we search for libs.
I didn’t quite get it. libtvm_topi.so
should have libtvm.so
as a dependency right? Does it mean libtvm_topi.so
is not inside the same folder as libtvm.so
?
What should I finally do to fix the import error? my tvm/build directory already contains libtvm_topi.so and " export LD_LIBRARY_PATH=/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi " or " export LD_LIBRARY_PATH=/home/jetbot/.local/lib/python3.6/site-packages/topi-0.6.dev0-py3.6.egg/topi " is not working. I am getting the same error as before. Help would be much appreciated!