Compilation issue with BERT model "IntImm object is not iterable"

I’m looking at loading bert-base-uncased from Transformers into TVM, via ONNX.

I can successfully import the ONNX model in TVM.

However, when I attempt to compile to run inference, I get the error: TypeError: 'IntImm' object is not iterable

I have a simple reproducible script below, which is comprised of three main stages:

  • export_bert_model() # exports the model to ONNX
  • import_onnx() # loads model into TVM mod, params
  • evaluate_tvm_model() # compiles and runs the model in TVM

It fails when trying to build the model, using both relay.build and relay.build_module.build.

The tutorial shows that BERT should be supported in TVM.

This other issue with BERT mentions IntImm.

Is there something I’m missing here? Thanks

#!/usr/bin/env python
import os
import tempfile
from transformers import (
    AutoConfig,
    AutoTokenizer,
    AutoModelForSequenceClassification,
)
from pathlib import Path
from transformers.convert_graph_to_onnx import convert
import onnx
import tvm
from tvm import relay, runtime
import numpy as np


def export_bert_model(onnx_file):
    num_labels = 32
    task_name = "cola"
    onnx_file = Path(onnx_file)

    config = AutoConfig.from_pretrained(
        "bert-base-uncased",
        num_labels=num_labels,
        finetuning_task=task_name,
    )

    # Load the tokenizer by path
    tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")

    # Load the model based on the path and the config
    model = AutoModelForSequenceClassification.from_pretrained(
        "bert-base-uncased",
        config=config,
    )

    # save model
    with tempfile.TemporaryDirectory() as model_path:
        model.save_pretrained(model_path)

        # delete ONNX file if it exists:
        if os.path.exists(onnx_file):
            os.remove(onnx_file)
        if not os.path.exists(onnx_file.parent):
            os.makedirs(onnx_file.parent)

        # export to ONNX
        print(onnx_file)
        print(model_path)
        convert(
            framework="pt",
            model=model_path,
            output=onnx_file,
            opset=11,
            tokenizer=tokenizer,
        )


def import_onnx(network_file, input_shape_dict):
    model = onnx.load(network_file)
    mod, params = relay.frontend.from_onnx(model, input_shape_dict)

    return mod, params


def evaluate_tvm_model(mod, params, input_data_dict, alt_inference=False):
    target = "llvm"
    target_host = "llvm"
    dev = tvm.cpu(0)

    if alt_inference:
        with relay.build_config(opt_level=3):
            lib = relay.build(mod, target=target, params=params)
            dummy_data = np.random.uniform(
                size=(1, 256), low=0, high=input_shape[1]
            ).astype("int32")
            m = graph_executor.GraphModule(lib["default"](dev))
            m.set_input(0, dummy_data)
            m.run()
    else:
        # Compile the network
        with relay.build_config(opt_level=3):
            graph, lib, params = relay.build_module.build(
                mod, target, params=params, target_host=target_host
            )
        module = graph_runtime.create(graph, lib, dev)

        for i, (input_name, test_input) in enumerate(input_data_dict.items()):
            print(f"Input {i}", input_name, test_input.shape)
            data_tvm = tvm.nd.array(test_input.astype("int32"))
            module.set_input(input_name, data_tvm)
        # Evaluate
        ftimer = module.module.time_evaluator("run", ctx, number=3, repeat=runs)
        results = list(np.array(ftimer().results) * 1e3)  # convert to millisecond
        out = module.get_output(0).asnumpy().flatten()

        mean, std = np.mean(results), np.std(results)

    return  # mean, std


if __name__ == "__main__":
    # export bert model to ONNX
    onnx_file = "onnx/model.onnx"
    export_bert_model(onnx_file)

    # import ONNX model to TVM
    batch_size = 1
    seq_len = 256
    input_shape_dict = {
        # "token_type_ids": (batch_size, seq_len),
        # "attention_mask": (batch_size, seq_len),
        "input_ids": (batch_size, seq_len),
    }
    mod, params = import_onnx(onnx_file, input_shape_dict)

    # Run CPU inference using TVM
    test_input_data_dict = {
        input_name: np.random.randint(0, high=32, size=size).astype("int32")
        for input_name, size in input_shape_dict.items()
    }
    evaluate_tvm_model(mod, params, test_input_data_dict)
    print(f"Finished BERT successfully")

Can you post the full stack trace of the error you are getting?

Sure, thank you.

The runtime portion of the stack trace is too verbose for a discourse post, but the python part at the end is quite short.

I’ll post the runtime portion as another post

Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                                             
  File "/home/wheest/phd/tvm-transformers/standalone.py", line 126, in <module>                                                                                                                                                                                                                                                                                                                   
    evaluate_tvm_model(mod, params, test_input_data_dict)                                                                                                                                                                                                                                                                                                                                      
  File "/home/wheest/phd/tvm-transformers/standalone.py", line 87, in evaluate_tvm_model                                                                                                                                                                                                                                                                                                          
    graph, lib, params = relay.build_module.build(                                                                                                                                                                                                                                                                                                                                             
  File "/home/wheest/tools/tvm/python/tvm/relay/build_module.py", line 332, in build                                                                                                                                                                                                                                                                                                              
    executor_config, runtime_mod, params = bld_mod.build(                                                                                                                                                                                                                                                                                                                                      
  File "/home/wheest/tools/tvm/python/tvm/relay/build_module.py", line 148, in build                                                                                                                                                                                                                                                                                                              
    self._build(mod, target, target_host, executor)                                                                                                                                                                                                                                                                                                                                            
  File "/home/wheest/tools/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__                                                                                                                                                                                                                                                                                                     
    raise get_last_ffi_error()                                                                                                                                                                                                                                                                                                                                                                 
TypeError: Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                                  
  File "/home/wheest/tools/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
    rv = local_pyfunc(*pyargs)                                                                 
  File "/home/wheest/tools/tvm/python/tvm/relay/backend/compile_engine.py", line 311, in lower_call                                                                                               
    best_impl, outputs = select_implementation(op, call.attrs, inputs, ret_type, target)
  File "/home/wheest/tools/tvm/python/tvm/relay/backend/compile_engine.py", line 219, in select_implementation                                                                                    
    outs = impl.compute(attrs, inputs, out_type)
  File "/home/wheest/tools/tvm/python/tvm/relay/op/op.py", line 125, in compute
    return _OpImplementationCompute(self, attrs, inputs, out_type)
  File "/home/wheest/tools/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()                                                                 
  3: TVMFuncCall                                                                               
  2: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::relay::$_3>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&) 
  1: tvm::relay::OpImplementation::Compute(tvm::Attrs const&, tvm::runtime::Array<tvm::te::Tensor, void> const&, tvm::Type const&)                                                             
  0: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), TVMFuncCreateFromCFunc::$_2>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  File "/home/wheest/tools/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
    rv = local_pyfunc(*pyargs)
  File "/home/wheest/tools/tvm/python/tvm/relay/op/strategy/generic.py", line 1289, in _compute_scatter
    return [topi_compute(inputs[0], inputs[1], inputs[2], attrs.axis)]
  File "/home/wheest/tools/tvm/python/tvm/topi/scatter.py", line 192, in scatter
    return _scatter_1d(data, indices, updates)
  File "/home/wheest/.virtualenvs/trans/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/__init__.py", line 60, in wrapped_func
    return source_to_op(src, args, func.__globals__, closure_vars)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 635, in source_to_op
    parser = parse_python(src, args, symbols, closure_vars)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 605, in parse_python
    parser.parsed_body = parser.visit(root)
  File "/usr/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 230, in visit_Module
    return self.visit(node.body[0])
  File "/usr/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 243, in visit_FunctionDef
    res = visit_list_to_block(self.visit, node.body)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 58, in visit_list_to_block
    lst = [visit(stmt) for stmt in lst if not utils.is_docstring(stmt)]
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 58, in <listcomp>
    lst = [visit(stmt) for stmt in lst if not utils.is_docstring(stmt)]
  File "/usr/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 483, in visit_For
    iter_var, low, ext, kind = self.visit(node.iter)
  File "/usr/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 467, in visit_Call
    args = [self.visit(i) for i in node.args]
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 467, in <listcomp>
    args = [self.visit(i) for i in node.args]
  File "/usr/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)
  File "/home/wheest/tools/tvm/python/tvm/te/hybrid/parser.py", line 380, in visit_Subscript
    for i in args:
TypeError: 'IntImm' object is not iterable

And, if relevant, the runtime portion of the stack trace:

  98: TVMFuncCall                                                                                                                                                                                                                                                                                                                                                                              
  97: _ZNSt17_Function_handlerIFvN3tvm7runtime7TVMArgsEPNS1_11                                                                                                                                                                                                                                                                                                                                 
  96: tvm::relay::backend::RelayBuildModule::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#3}::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const                                                     
  95: tvm::relay::backend::RelayBuildModule::Build(tvm::IRModule, tvm::runtime::Map<tvm::Integer, tvm::Target, void, void> const&, tvm::Target const&, tvm::runtime::String)                                                                                                                                                                                                                   
  94: tvm::relay::backend::RelayBuildModule::BuildRelay(tvm::IRModule, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::NDArray, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
 std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::NDArray> > > const&)                                                                                                                                                                                                                                            
  93: tvm::relay::backend::RelayBuildModule::Optimize(tvm::IRModule, tvm::runtime::Map<tvm::Integer, tvm::Target, void, void> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::NDArray, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic
_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::NDArray> > > const&)                                                                                                                                                                             
  92: tvm::transform::Pass::operator()(tvm::IRModule) const                                                                                                                                                                                                                                                                                                                                    
  91: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                                
  90: tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                      
  89: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                                
  88: tvm::relay::transform::FunctionPassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                             
  87: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::relay::Function (tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::DynamicToStatic()::$_0>(tvm::relay::transform::DynamicToStatic()::$_0)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue
*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)                                                                                                                                                                                                                                                                                                
  86: tvm::relay::DynamicToStatic(tvm::relay::Function, tvm::IRModule)                                                                                                                                                                                                                                                                                                                         
  85: tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  84: tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  83: tvm::relay::DynamicToStaticMutator::DispatchVisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                             
  82: _ZN3tvm5relay1  Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                                             
  File "/home/wheest/phd/tvm-transformers/standalone.py", line 126, in <module>                                                                                                                                                                                                                                                                                                                   
    evaluate_tvm_model(mod, params, test_input_data_dict)                                                                                                                                                                                                                                                                                                                                      
  File "/home/wheest/phd/tvm-transformers/standalone.py", line 87, in evaluate_tvm_model                                                                                                                                                                                                                                                                                                          
    graph, lib, params = relay.build_module.build(                                                                                                                                                                                                                                                                                                                                             
  File "/home/wheest/tools/tvm/python/tvm/relay/build_module.py", line 332, in build                                                                                                                                                                                                                                                                                                              
    executor_config, runtime_mod, params = bld_mod.build(                                                                                                                                                                                                                                                                                                                                      
  File "/home/wheest/tools/tvm/python/tvm/relay/build_module.py", line 148, in build                                                                                                                                                                                                                                                                                                              
    self._build(mod, target, target_host, executor)                                                                                                                                                                                                                                                                                                                                            
  File "/home/wheest/tools/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__                                                                                                                                                                                                                                                                                                     
    raise get_last_ffi_error()                                                                                                                                                                                                                                                                                                                                                                 
TypeError: Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                                  
  98: TVMFuncCall                                                                                                                                                                                                                                                                                                                                                                              
  97: _ZNSt17_Function_handlerIFvN3tvm7runtime7TVMArgsEPNS1_11                                                                                                                                                                                                                                                                                                                                 
  96: tvm::relay::backend::RelayBuildModule::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#3}::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const                                                     
  95: tvm::relay::backend::RelayBuildModule::Build(tvm::IRModule, tvm::runtime::Map<tvm::Integer, tvm::Target, void, void> const&, tvm::Target const&, tvm::runtime::String)                                                                                                                                                                                                                   
  94: tvm::relay::backend::RelayBuildModule::BuildRelay(tvm::IRModule, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::NDArray, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
 std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::NDArray> > > const&)                                                                                                                                                                                                                                            
  93: tvm::relay::backend::RelayBuildModule::Optimize(tvm::IRModule, tvm::runtime::Map<tvm::Integer, tvm::Target, void, void> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::NDArray, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic
_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::NDArray> > > const&)                                                                                                                                                                             
  92: tvm::transform::Pass::operator()(tvm::IRModule) const                                                                                                                                                                                                                                                                                                                                    
  91: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                                
  90: tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                      
  89: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                                
  88: tvm::relay::transform::FunctionPassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                             
  87: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::relay::Function (tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::DynamicToStatic()::$_0>(tvm::relay::transform::DynamicToStatic()::$_0)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue
*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)                                                                                                                                                                                                                                                                                                
  86: tvm::relay::DynamicToStatic(tvm::relay::Function, tvm::IRModule)                                                                                                                                                                                                                                                                                                                         
  85: tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  84: tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  83: tvm::relay::DynamicToStaticMutator::DispatchVisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                             
  82: _ZN3tvm5relay1  
  81: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                       [42/2354]
  80: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                        
  79: tvm::NodeFunctor<tvm::RelayExpr (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*) const                                                                                                                                  
  78: _ZZN3tvm5relay11ExprFunc                                                                                                                                                                                                                                                                                                                                                                 
  77: tvm::relay::ExprMutator::VisitExpr_(tvm::relay::FunctionNode const*)                                                                                                                                                                                                                                                                                                                     
  76: tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  75: tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  74: tvm::relay::DynamicToStaticMutator::DispatchVisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                             
  73: _ZN3tvm5relay1                                                                                                                                                                                                                                                                                                                                                                           
  72: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                                
  71: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                        
  70: tvm::NodeFunctor<tvm::RelayExpr (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*) const                                                                                                                                  
  69: _ZZN3tvm5relay11ExprFunc                                                                                                                                                                                                                                                                                                                                                                 
  68: _ZN3tvm5relay1                                                                                                                                                                                                                                                                                                                                                                           
  67: tvm::RelayExpr tvm::relay::MixedModeMutator::Rewrite<tvm::relay::CallNode>(tvm::relay::CallNode const*)                                                                                                                                                                                                                                                                                  
  66: tvm::relay::DynamicToStaticMutator::Rewrite_(tvm::relay::CallNode const*, tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                         
  65: _ZNSt17_Function_                                                                                                                                                                                                                                                                                                                                                                        
  64: tvm::relay::DynamicToStaticMutator::DynamicToStaticMutator(tvm::IRModule, tvm::relay::Function)::{lambda(tvm::relay::CallNode const*)#13}::operator()(tvm::relay::CallNode const*) const                                                                                                                                                                                                 
  63: tvm::relay::DynamicToStaticMutator::PrepareArgs(tvm::relay::CallNode const*)                                                                                                                                                                                                                                                                                                             
  62: tvm::relay::DynamicToStaticMutator::PrepareInput(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                  
  61: tvm::transform::Pass::operator()(tvm::IRModule) const                                                                                                                                                                                                                                                                                                                                    
  60: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                                                
  59: tvm::relay::transform::FunctionPassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const                                                                                                                                                                                                                                                                             
  58: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::relay::Function (tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::FoldConstant()::$_0>(tvm::relay::transform::FoldConstant()::$_0)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>
::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)                                                                                                                                                                                                                                                                                                      
  57: tvm::relay::FoldConstant(tvm::RelayExpr const&, tvm::IRModule const&)                                                                                                                                                                                                                                                                                                                    
  56: tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  55: tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  54: _ZN3tvm5relay1                                                                                                                                                                                                                                                                                                                                                                           
  53: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                                
  52: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                        
  51: tvm::NodeFunctor<tvm::RelayExpr (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*) const                                                                                                                                  
  50: _ZZN3tvm5relay11ExprFunc                                                                                                                                                                                                                                                                                                                                                                 
  49: tvm::relay::ConstantFolder::VisitExpr_(tvm::relay::FunctionNode const*)                                                                                                                                                                                                                                                                                                                  
  48: tvm::relay::ExprMutator::VisitExpr_(tvm::relay::FunctionNode const*)                                                                                                                                                                                                                                                                                                                     
  47: tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  46: tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                           
  45: _ZN3tvm5relay1                                                                                                                                                                                                                                                                                                                                                                           
  44: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                                                                
  43: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                                                                                                                                                                                                                                        
  42: tvm::NodeFunctor<tvm::RelayExpr (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>*) const                                                                                                                                  
  41: _ZZN3tvm5relay11ExprFunc                                                                                                                                                                                                                                                                                                                                                                 
  40: _ZN3tvm5relay1                                                                                                                                                                                                                                                                                                                                                                           
  39: tvm::RelayExpr tvm::relay::MixedModeMutator::Rewrite<tvm::relay::CallNode>(tvm::relay::CallNode const*)                                                                                  
  38: tvm::relay::ConstantFolder::Rewrite_(tvm::relay::CallNode const*, tvm::RelayExpr const&)
  37: tvm::relay::ConstantFolder::ConstEvaluate(tvm::RelayExpr)
  36: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::runtime::ObjectRef (tvm::RelayExpr)>::AssignTypedLambda<tvm::relay::CreateInterpreter(tvm::IRModule, DLDevice, tvm::Target)::$_8>(tvm::relay::CreateInterpreter(tvm::IRModule, DLDevice, tvm::Target)::$_8)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMR
etValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)                                                                                         
  35: tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                               
  34: tvm::NodeFunctor<tvm::runtime::ObjectRef (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*) const
  33: _ZZN3tvm5relay11ExprFunc                                                                 
  32: tvm::relay::Interpreter::VisitExpr_(tvm::relay::LetNode const*)
  31: tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                               
  30: tvm::NodeFunctor<tvm::runtime::ObjectRef (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*) const
  29: _ZZN3tvm5relay11ExprFunc                                                                 
  28: tvm::relay::Interpreter::VisitExpr_(tvm::relay::LetNode const*)
  27: tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                               
  26: tvm::NodeFunctor<tvm::runtime::ObjectRef (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*) const
  25: _ZZN3tvm5relay11ExprFunc                                                                 
  24: tvm::relay::Interpreter::VisitExpr_(tvm::relay::LetNode const*)
  23: tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                               
  22: tvm::NodeFunctor<tvm::runtime::ObjectRef (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*) const
  21: _ZZN3tvm5relay11ExprFunc                                                                 
  20: tvm::relay::Interpreter::VisitExpr_(tvm::relay::LetNode const*)
  19: tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                               
  18: tvm::NodeFunctor<tvm::runtime::ObjectRef (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*) const
  17: _ZZN3tvm5relay11ExprFunc                                                                 
  16: tvm::relay::Interpreter::VisitExpr_(tvm::relay::LetNode const*)
  15: tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                                               
  14: tvm::NodeFunctor<tvm::runtime::ObjectRef (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::ObjectRef (tvm::RelayExpr const&)>*) const
  13: _ZZN3tvm5relay11ExprFunc                                                                 
  12: tvm::relay::Interpreter::VisitExpr_(tvm::relay::CallNode const*)
  11: tvm::relay::Interpreter::Invoke(tvm::relay::InterpreterClosure const&, tvm::runtime::Array<tvm::runtime::ObjectRef, void> const&, tvm::relay::Var const&)                                
  10: tvm::relay::Interpreter::InvokePrimitiveOp(tvm::relay::Function const&, tvm::runtime::Array<tvm::runtime::ObjectRef, void> const&)                                                       
  9: tvm::relay::CompileEngineImpl::JIT(tvm::relay::CCacheKey const&)
  8: tvm::relay::CompileEngineImpl::LowerInternal(tvm::relay::CCacheKey const&)
  7: tvm::relay::CreateSchedule(tvm::relay::Function const&, tvm::Target const&)
  6: tvm::relay::ScheduleGetter::Create(tvm::relay::Function const&)
  5: tvm::relay::backend::MemoizedExprTranslator<tvm::runtime::Array<tvm::te::Tensor, void> >::VisitExpr(tvm::RelayExpr const&)                                                                
  4: tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)                                                             
  3: tvm::NodeFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>*) const
  2: _ZZN3tvm5relay11ExprFunc                                                                  
  1: tvm::relay::ScheduleGetter::VisitExpr_(tvm::relay::CallNode const*)
  0: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), TVMFuncCreateFromCFunc::$_2>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)

I see you’re using python 3.9. That is currently not supported. 3.7 is recommended.

I just wanted to confirm that I had the same issue and this was the solution. For me just going from python 3.9 to python 3.8 was enough.

Great, my thanks both.

My approach side-stepped the issue by converting directly from PyTorch, however it is good to know that the Python version can influence in this way.