Run error with test_relay_translator.py

Dears,

When I try to use test_relay_translator.py to verify how to use relax to deploy resnet to gpu, I met many errors(I’ve added the questions into below code).Could you please help to give some advices for this?

Thanks.


def relax_build_and_run(mod, target, dev, params, data):
    mod = relax.transform.BindParams("main", params)(mod)
    with tempfile.TemporaryDirectory() as work_dir:
        db = ms.relax_integration.tune_relax(
            mod=mod,
            target=target,
            # Q3: params is required by tune_relax
            params=params,
            task_scheduler="round-robin",
            num_trials_per_iter=32,
            max_trials_per_task=32,
            max_trials_global=1024,
            work_dir=work_dir,
        )
        ex = ms.relax_integration.compile_relax(
            db,
            mod=mod,
            target=target,
            params=params,
        )
    vm = relax.VirtualMachine(ex, dev)
    res = vm["main"](data)
    out = res.numpy()
    return ex, vm, out

def verify_e2e_translation(target_str, layout, batch_size, image_shape):
    target = Target(target_str)
    dev = tvm.device(str(target), dev_id=0)
    relay_mod, params = get_resnet(batch_size, "float32", layout, image_shape)
    input_shape = (1, *image_shape)
    data = tvm.nd.array(np.random.rand(*input_shape).astype(np.float32), dev)
    relax_mod = relay_translator.from_relay(relay_mod["main"], target, params)
    # Q1: assert error
    #assert relax_mod["main"].attrs["global_symbol"] == "main"

    # Only care about relax case.
    #_, _, relay_out = relay_build_and_run(relay_mod, target, dev, params, data)
    _, _, relax_out = relax_build_and_run(relax_mod, target, dev, params, data)
    #tvm.testing.assert_allclose(relay_out, relax_out, atol=1e-5, rtol=1e-5)

#@pytest.mark.skip(reason="take too much time")
@tvm.testing.requires_gpu
@pytest.mark.parametrize(
    "layout, batch_size, image_shape", [("NCHW", 1, (3, 224, 224)), ("NHWC", 1, (224, 224, 3))]
)
def test_verify_e2e_translation_gpu(layout, batch_size, image_shape):
    # Q2: runtime error, max_threads_per_block and max_shared_memory_per_block are missing.
    verify_e2e_translation("cuda --max_threads_per_block=1024 --max_shared_memory_per_block=64", layout, batch_size, image_shape)

Finally, I got below errors

test_relay_translator.py:106: in verify_e2e_translation
    _, _, relax_out = relax_build_and_run(relax_mod, target, dev, params, data)
test_relay_translator.py:82: in relax_build_and_run
    work_dir=work_dir,
../../../python/tvm/meta_schedule/relax_integration.py:223: in tune_relax
    task_scheduler=task_scheduler,
../../../python/tvm/meta_schedule/tune.py:127: in tune_tasks
    cost_model=cost_model,
../../../python/tvm/meta_schedule/task_scheduler/task_scheduler.py:143: in tune
    cost_model,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tvm.runtime.packed_func.PackedFunc object at 0x7f2c1d867960>
args = (meta_schedule.RoundRobin(0x55f75ab93fd8), [meta_schedule.TuneContext(0x55f75c74b9c0), meta_schedule.TuneContext(0x55f...55f75c746f60), meta_schedule.TuneContext(0x55f75ab55380), ...], [1.0, 1.0, 1.0, 1.0, 1.0, 5.0, ...], 1024, 32, 32, ...)
temp_args = [[meta_schedule.TuneContext(0x55f75c74b9c0), meta_schedule.TuneContext(0x55f75ab1dc50), meta_schedule.TuneContext(0x55...32(3), T.float32(1), T.float32(2), T.float32(1), T.float32(1), T.float32(1), T.float32(1), T.float32(1), T.float32(1)]]
values = <tvm._ffi._ctypes.packed_func.TVMValue_Array_11 object at 0x7f2b3c646560>
tcodes = <tvm._ffi._ctypes.packed_func.c_int_Array_11 object at 0x7f2b3c6460e0>

    def __call__(self, *args):
        """Call the function with positional arguments

        args : list
           The positional arguments to the function call.
        """
        temp_args = []
        values, tcodes, num_args = _make_tvm_args(args, temp_args)
        ret_val = TVMValue()
        ret_tcode = ctypes.c_int()
        if (
            _LIB.TVMFuncCall(
                self.handle,
                values,
                tcodes,
                ctypes.c_int(num_args),
                ctypes.byref(ret_val),
                ctypes.byref(ret_tcode),
            )
            != 0
        ):
>           raise get_last_ffi_error()
E           tvm._ffi.base.TVMError: Traceback (most recent call last):
E             7: TVMFuncCall
E             6: _ZN3tvm7runtime13PackedFun
E             5: tvm::runtime::TypedPackedFunc<void (tvm::meta_schedule::TaskScheduler, tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>)>::AssignTypedLambda<tvm::runtime::Registry::set_body_method<tvm::meta_schedule::TaskScheduler, tvm::meta_schedule::TaskSchedulerNode, void, tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>, void>(void (tvm::meta_schedule::TaskSchedulerNode::*)(tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>))::{lambda(tvm::meta_schedule::TaskScheduler, tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>)#1}>(tvm::runtime::Registry::set_body_method<tvm::meta_schedule::TaskScheduler, tvm::meta_schedule::TaskSchedulerNode, void, tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>, void>(void (tvm::meta_schedule::TaskSchedulerNode::*)(tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>))::{lambda(tvm::meta_schedule::TaskScheduler, tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>)#1}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}::operator()(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*) const
E             4: tvm::meta_schedule::TaskSchedulerNode::Tune(tvm::runtime::Array<tvm::meta_schedule::TuneContext, void>, tvm::runtime::Array<tvm::FloatImm, void>, int, int, int, tvm::meta_schedule::Builder, tvm::meta_schedule::Runner, tvm::runtime::Array<tvm::meta_schedule::MeasureCallback, void>, tvm::runtime::Optional<tvm::meta_schedule::Database>, tvm::runtime::Optional<tvm::meta_schedule::CostModel>)
E             3: tvm::meta_schedule::PostOrderApplyNode::GenerateDesignSpace(tvm::IRModule const&)
E             2: tvm::meta_schedule::CrossThreadReductionNode::Apply(tvm::tir::Schedule const&, tvm::tir::BlockRV const&)
E             1: tvm::meta_schedule::CrossThreadReductionNode::GetThreadIdxExtentFromTrace(tvm::tir::Trace const&)
E             0: tvm::runtime::Array<tvm::runtime::ObjectRef, void>::operator[](long) const
E             File "/home/wwei/codes/gitlab/relax/include/tvm/runtime/container/array.h", line 414
E           TVMError:
E           ---------------------------------------------------------------
E           An error occurred during the execution of TVM.
E           For more information, please see: https://tvm.apache.org/docs/errors.html
E           ---------------------------------------------------------------
E             Check failed: (0 <= i && i < p->size_) is false: IndexError: indexing 3 on an array of size 3

../../../python/tvm/_ffi/_ctypes/packed_func.py:237: TVMError

Add relax code version: bc46b0b4dfbb539e5f537e12f5812933636ad04a