relay.build fails: module 'tvm.codegen' has no attribute 'llvm_version_major'

On FreeBSD I am getting this failure:

$ python3.6 my.py input (1, 224, 224, 3) Traceback (most recent call last):

File “my.py”, line 58, in graph, lib, params = relay.build(mod, target, params=params)

File “/usr/local/lib/python3.6/site-packages/tvm/relay/build_module.py”, line 244, in build graph_json, mod, params = bld_mod.build(func, target, target_host, params)

File “/usr/local/lib/python3.6/site-packages/tvm/relay/build_module.py”, line 109, in build self._build(func, target, target_host)

File “tvm/_ffi/_cython/./function.pxi”, line 304, in tvm._ffi._cy3.core.FunctionBase.call

File “tvm/_ffi/_cython/./function.pxi”, line 239, in tvm._ffi._cy3.core.FuncCall

File “tvm/_ffi/_cython/./function.pxi”, line 228, in tvm._ffi._cy3.core.FuncCall3

File “tvm/_ffi/_cython/./base.pxi”, line 160, in tvm._ffi._cy3.core.CALL

AttributeError: Traceback (most recent call last): [bt] (7) 0x80cc17ee1 <tvm::relay::legalize::Legalizer::VisitExpr_(tvm::relay::CallNode const*)+0x31> at /usr/local/lib/libtvm.so [bt] (6) 0x80cd7074f <tvm::relay::ExprMutator::VisitExpr_(tvm::relay::CallNode const*)+0x21f> at /usr/local/lib/libtvm.so [bt] (5) 0x80cd6f1bc <tvm::relay::ExprMutator::VisitExpr(tvm::relay::Expr const&)+0x10c> at /usr/local/lib/libtvm.so [bt] (4) 0x80cbee7b3 <ZN3tvm5relay11ExprFunctorIFNS0_4ExprERKS2_EE9VisitExprES4+0xa3> at /usr/local/lib/libtvm.so [bt] (3) 0x80cbeeaf8 <tvm::NodeFunctor<tvm::relay::Expr()(tvm::runtime::ObjectRef const&tvm::relay::ExprFunctor<tvm::relay::Expr()(tvm::relay::Expr const&)>)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::relay::Expr()(tvm::relay::Expr const&)>) const+0x138> at /usr/local/lib/libtvm.so [bt] (2) 0x80cbf0528 <ZZN3tvm5relay11ExprFunctorIFNS0_4ExprERKS2_EE10InitVTableEvENUlRKNS_7runtime9ObjectRefEPS6_E4_8__invokeESA_SB+0x18> at /usr/local/lib/libtvm.so [bt] (1) 0x80cc18253 <tvm::relay::legalize::Legalizer::VisitExpr_(tvm::relay::CallNode const*)+0x3a3> at /usr/local/lib/libtvm.so [bt] (0) 0x80ce2fc0c <TVMCbArgToReturn+0x74c> at /usr/local/lib/libtvm.so File “tvm/_ffi/_cython/./function.pxi”, line 55, in tvm._ffi._cy3.core.tvm_callback File “/usr/local/lib/python3.6/site-packages/tvm/relay/op/nn/_nn.py”, line 246, in legalize_conv2d return topi.nn.conv2d_legalize(attrs, inputs, types) File “”, line 2, in conv2d_legalize File “/usr/local/lib/python3.6/site-packages/tvm/target.py”, line 382, in dispatch_func return dispatch_dict[k](*args, **kwargs) File “/usr/local/lib/python3.6/site-packages/topi/x86/conv2d_alter_op.py”, line 261, in _conv2d_legalize if _is_int8_hw_support(data_dtype, kernel_dtype): File “/usr/local/lib/python3.6/site-packages/topi/x86/conv2d_int8.py”, line 60, in _is_int8_hw_support llvm_version = tvm.codegen.llvm_version_major() AttributeError: module ‘tvm.codegen’ has no attribute ‘llvm_version_major’

This is likely due to the fact that you have not build tvm with LLVM support

Hello tq: I got the same issue, my env is 7700HQ / kabylake, Ubuntu 16.04, python 3.5. I installed llvm 4.0.1, then build tvm 0.7.dev0 on based it. Is there a possibility llvm version not compatible, could you please recommend a llvm+tvm combi ? BR

Check the value of USE_LLVM in your config.cmake.

Hi tq, ramana,

Having the same problem on Ubuntu 16.04.6 when building from source. I tried building with LLVM 9.0 and 4.0, but the problem persisted. I do have set(USE_LLVM ON) in config.cmake and cmake is able to find LLVM:

-- Found LLVM_INCLUDE_DIRS=/usr/lib/llvm-4.0/include
-- Found LLVM_DEFINITIONS=-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found TVM_LLVM_VERSION=40
-- Build with LLVM 4.0.0
-- Set TVM_LLVM_VERSION=40

Building works perfectly, but I get the same runtime error:

AttributeError: module 'tvm.target._ffi_api' has no attribute 'llvm_version_major'
During handling of the above exception, another exception occurred:
RuntimeError: LLVM version is not available, please check if you build with LLVM

Any ideas?

same here. Have you solved this?

I have the same issue here when building with LLVM 10.0.1 or with GCC. I also have the LLVM option set to on. cmake also reports to me that it is finding LLVM. I’m on Arch Linux.

Even if I compile with the newest prebuilt libraries from llvm’s website (11.0.0) I cannot get it to work;

tvmc compile --target "llvm" --output compiled_module.tar resnet50-v2-7.onnx
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute spatial is ignored in relay.sym.batch_norm
Traceback (most recent call last):
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/bin/tvmc", line 33, in <module>
    sys.exit(load_entry_point('tvm==0.8.dev122+g1b6ef5c80', 'console_scripts', 'tvmc')())
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/driver/tvmc/main.py", line 95, in main
    sys.exit(_main(sys.argv[1:]))
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/driver/tvmc/main.py", line 88, in _main
    return args.func(args)
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/driver/tvmc/compiler.py", line 107, in drive_compile
    graph, lib, params, dumps = compile_model(
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/driver/tvmc/compiler.py", line 201, in compile_model
    graph_module = relay.build(mod, tvm_target, params=params, target_host=tvm_target)
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/relay/build_module.py", line 260, in build
    graph_json, mod, params = bld_mod.build(mod, target, target_host, params)
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/relay/build_module.py", line 127, in build
    self._build(mod, target, target_host)
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
AttributeError: Traceback (most recent call last):
  [bt] (8) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*)#5}::_FUN(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*)+0x26) [0x7fe48b5180c6]
  [bt] (7) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::ExprMutator::VisitExpr_(tvm::relay::FunctionNode const*)+0x5c6) [0x7fe48b655db6]
  [bt] (6) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&)+0x344) [0x7fe48b657204]
  [bt] (5) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&)+0x45) [0x7fe48b656e45]
  [bt] (4) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::PostOrderRewriter::DispatchVisitExpr(tvm::RelayExpr const&)+0xb0) [0x7fe48b65dde0]
  [bt] (3) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::NodeFunctor<tvm::RelayExpr (tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&) const+0x125) [0x7fe48b418305]
  [bt] (2) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::ExprRewriter::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&)#6}::_FUN(tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&)+0x26) [0x7fe48b417816]
  [bt] (1) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::legalize::Legalizer::Rewrite_(tvm::relay::CallNode const*, tvm::RelayExpr const&)+0x702) [0x7fe48b522052]
  [bt] (0) /home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/libtvm.so(+0x498f39) [0x7fe48aaaef39]
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/target/codegen.py", line 72, in llvm_version_major
    return _ffi_api.llvm_version_major()
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
    rv = local_pyfunc(*pyargs)
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/relay/op/nn/_nn.py", line 140, in legalize_conv2d
    return topi.nn.conv2d_legalize(attrs, inputs, types)
  File "<decorator-gen-52>", line 2, in conv2d_legalize
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/target/generic_func.py", line 275, in dispatch_func
    return dispatch_dict[k](*args, **kwargs)
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/topi/x86/conv2d_alter_op.py", line 307, in _conv2d_legalize
    if is_int8_hw_support(data_dtype, kernel_dtype):
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/topi/x86/conv2d_int8.py", line 71, in is_int8_hw_support
    llvm_version = tvm.target.codegen.llvm_version_major()
  File "/home/josse/.local/share/virtualenvs/tryout-tvm-MK_O0g7I/lib/python3.8/site-packages/tvm-0.8.dev122+g1b6ef5c80-py3.8-linux-x86_64.egg/tvm/target/codegen.py", line 76, in llvm_version_major
    raise RuntimeError("LLVM version is not available, please check if you build with LLVM")
AttributeError: module 'tvm.target._ffi_api' has no attribute 'llvm_version_major'
During handling of the above exception, another exception occurred:

RuntimeError: LLVM version is not available, please check if you build with LLVM

Please check if https://github.com/apache/incubator-tvm/blob/main/src/target/llvm/llvm_module.cc#L393 is included in the compiled library.

1 Like

Hi @tqchen.

Thanks for coming back to this so quickly. I’m not an expert in C++ compiliation, so to be honest, I don’t know how to check this. Maybe this is helpful; the llvm_module.cc is listed 4 times in my build.ninja-file so i’d guess it should be compiled, no?

Thanks!

You still need to check if this macro is indeed enabled. try to write a random string inside https://github.com/apache/incubator-tvm/blob/main/src/target/llvm/llvm_module.cc#L25 to see if the file get compiled(and report an error). Make sure you redo the install after setting it up.

There are also some prebuild thirdparty wheels https://tlcpack.ai/wheels or conda https://anaconda.org/tlcpack that you could try out.

1 Like

Thank you @tqchen it’s working now! I didn’t know I had to run the python setup again. I think the reason why it didn’t work was because I did not enable LLVM in the right cmake.config file the first time i ran the python setup. (I only enabled it in the template :man_facepalming:)

So the thing that fixed it for me was rerunning the python setup.py install command after compiling with the LLVM prebuilt binaries. Right now i’m using the prebuilt binaries for ubuntu 20.04 of LLVM 11.0.0 and I compiled it with clang(++)

I’ll make sure to remember the wheels as an alternative. Is there a particular reason why the tvm documentation does not mention this way of installing? Otherwise it might be useful to include it there maybe?

Thanks once again!

Glad it works. The wheels are most recent introduction and some are still wip, see [RFC] tlcpack: Thirdparty Binary Packages for more background

1 Like