How to Package TVM into Another Python Wheel Package?

Backgroud

After doing some development based on official TVM repository, now we need release our modified TVM to our users, we already have a bigger development tool chain, they are packaged to one Python wheel package, for example our top level tool is named “nn_builder”, because the our modified TVM is a member of “nn_builder”, so we want to put the TVM into “nn_builder”.

Problem

If the tvm directory is put inside “nn_builder”, then lots of TVM original python script will fail like something below.

----> 1 from nn_builder import tvm

~/.local/lib/python3.6/site-packages/nn_builder/tvm/__init__.py in <module>
     30 # top-level alias
     31 # tvm.runtime
---> 32 from .runtime.object import Object
     33 from .runtime.ndarray import device, cpu, cuda, gpu, opencl, cl, vulkan, metal, mtl
     34 from .runtime.ndarray import vpi, rocm, ext_dev, hexagon
~/.local/lib/python3.6/site-packages/nn_builder/tvm/runtime/__init__.py in <module>
     18 
     19 # class exposures
---> 20 from .packed_func import PackedFunc
     21 from .object import Object
     22 from .object_generic import ObjectGeneric, ObjectTypes

~/.local/lib/python3.6/site-packages/nn_builder/tvm/runtime/packed_func.py in <module>
     19 """Packed Function namespace."""
     20 import ctypes
---> 21 from tvm._ffi.base import _LIB, check_call, c_str, string_types, _FFI_MODE
     22 
     23 try:

ModuleNotFoundError: No module named 'tvm'

I think this issue is a common problem for company who use TVM as a part of their tools, is there a solution for it?

@tqchen @comaniac @junrushao Thanks.

You should just need to add <path>/nn_builder/tvm/python/ to PYTHONPATH.

1 Like

Thanks for replying, but it maybe unacceptable for our customers to set a specific value in PYTHONPATH after install our released python package.

The only method I can found to achieve the same goal is appending the path <path>/nn_builder to sys.path in file <path>/nn_builder/__init__.py.

Do you think there is a better way?

Alternatively we could change all the

from tvm.xxx import xxx

to relative import:

from ..xxx import xxx

but it is heavy engineering time

if maintaining one’s own conda channel, it won’t be a problem, because you may just release an own version of tvm there

Yes, the relative import will make TVM distribute as a sub directory easy, but as you said, it really is a heavy work, in addition the disadvantage of relative(i.e., it is hard to find the real file location from the import statement) maybe will hurt TVM code.

Hi @Johnson9009

had you find away to do that? i am facing the same issue , tried with python setup.py install but it actually install the tvmc to the current user env…

Thanks, Ebraheem