uwsampl / SparseTIR

SparseTIR: Sparse Tensor Compiler for Deep Learning
https://sampl.cs.washington.edu/SparseTIR/
Apache License 2.0
131 stars 14 forks source link

[Bug] Meet error ModuleNotFoundError: No module named 'tvm.sparse' on runtime #79

Closed azazhu closed 1 year ago

azazhu commented 1 year ago

Did I use a wrong TVM version? image

Expected behavior

Run examples/spmm/bench_spmm_naive.py successfully

Actual behavior

Met following error: [01:56:18] /opt/dgl/src/runtime/tensordispatch.cc:43: TensorDispatcher: dlopen failed: /venv/apache-tvm-py3.7/lib/python3.7/site-packages/dgl/tensoradapter/pytorch/libtensoradapter_pytorch_1.12.0.so: cannot open shared object file: No such file or directory Using backend: pytorch Traceback (most recent call last): File "examples/spmm/bench_spmm_naive.py", line 27, in from tvm.sparse import FormatRewriteRule, lower_sparse_buffer, lower_sparse_iter ModuleNotFoundError: No module named 'tvm.sparse'

Environment

Ubuntu 18.04.6 LTS TVM: 0.11.dev0 LLVM version 14.0.0

Steps to reproduce

  1. download and mv and setup PATH
  2. build tvm from tvm repo
  3. build sparseTIR
yzh119 commented 1 year ago

After you compile the source code (in C++), you should either install the python package via

python3 python/setup.py install

or set environment variable PYTHONPATH:

export PYTHONPATH=${YOUR_SPARSETIR_DIR}/python:${PYTHONPATH}
yzh119 commented 1 year ago

btw, you shouldn't build tvm from tvm repo, SparseTIR is a fork of TVM and is self-contained.

azazhu commented 1 year ago

export PYTHONPATH can work. "python3 python/setup.py install" fails with following error:

 root@84eaf74fddb8:/workspace2/sparsetir# python3 python/setup.py install
WARNING:root:git describe: fatal: detected dubious ownership in repository at '/workspace2/sparsetir'
To add an exception for this directory, call:
        git config --global --add safe.directory /workspace2/sparsetir
, use 0.9.dev0
Traceback (most recent call last):
  File "python/setup.py", line 251, in <module>
    ext_modules=config_cython(),
  File "python/setup.py", line 133, in config_cython
    for fn in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: 'tvm/_ffi/_cython'

I think it is due to using a wrong tvm version. BTW, where is self-contained tvm in sparseTIR? is it in docker image or submodules?

yzh119 commented 1 year ago

I think it is due to using a wrong tvm version.

No, it's not.

Let me explain it again, you shouldn't install TVM for SparseTIR. If you did, please pip uninstall it to avoid duplication. SparseTIR is basically a modified version of TVM with sparse support, the tvm in your error message No module named 'tvm.sparse' refers to the SparseTIR itself instead of standard TVM in upstream repo.

azazhu commented 1 year ago

It works now. Thx Zihao. This issue can be closed.