After Tuning, the model has a inconsistent prediction result with Keras

Thanks. Following your hint , I changed the above script and set opt_level=2 , the script crashed. Besides, ‘opt_level =1’ also crashed with the same messages.

The crash messages are as following.

Traceback (most recent call last):  File "bug_simple.py", line 59, in <module>    compare(model_name)
  File "bug_simple.py", line 41, in compare    irmod, target=target, params=params)  File "/workplace/software/tvm/tvm8/python/tvm/relay/build_module.py", line 260, in build    graph_json, mod, params = bld_mod.build(mod, target, target_host, params)  File "/workplace/software/tvm/tvm8/python/tvm/relay/build_module.py", line 127, in build
    self._build(mod, target, target_host)  File "/workplace/software/tvm/tvm8/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (8) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::backend::MemoizedExprTranslator<tvm::runtime::Array<tvm::te::Tensor, void> >::VisitExpr(tvm::RelayExpr const&)+0xa6) [0x7f3dc5287006]
  [bt] (7) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)+0x89) [0x7f3dc5286d99]
  [bt] (6) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>*)#6}::_FUN(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>*)+0x27) [0x7f3dc5279907]
  [bt] (5) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::ScheduleGetter::VisitExpr_(tvm::relay::CallNode const*)+0x18f) [0x7f3dc528137f]
  [bt] (4) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::backend::MemoizedExprTranslator<tvm::runtime::Array<tvm::te::Tensor, void> >::VisitExpr(tvm::RelayExpr const&)+0xa6) [0x7f3dc5287006]
  [bt] (3) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)+0x89) [0x7f3dc5286d99]
  [bt] (2) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>*)#6}::_FUN(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<tvm::runtime::Array<tvm::te::Tensor, void> (tvm::RelayExpr const&)>*)+0x27) [0x7f3dc5279907]
  [bt] (1) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::ScheduleGetter::VisitExpr_(tvm::relay::CallNode const*)+0x5f3) [0x7f3dc52817e3]
  [bt] (0) /workplace/software/tvm/tvm8/build/libtvm.so(+0x192a9cb) [0x7f3dc542d9cb]
  File "/workplace/software/tvm/tvm8/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun    rv = local_pyfunc(*pyargs)
  File "/workplace/software/tvm/tvm8/python/tvm/relay/backend/compile_engine.py", line 284, in lower_call
    best_impl, outputs = select_implementation(op, call.attrs, inputs, ret_type, target)
  File "/workplace/software/tvm/tvm8/python/tvm/relay/backend/compile_engine.py", line 206, in select_implementation
    outs = impl.compute(attrs, inputs, out_type)  File "/workplace/software/tvm/tvm8/python/tvm/relay/op/op.py", line 91, in compute
    return _OpImplementationCompute(self, attrs, inputs, out_type)
  File "/workplace/software/tvm/tvm8/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
  [bt] (3) /workplace/software/tvm/tvm8/build/libtvm.so(TVMFuncCall+0x61) [0x7f3dc5430fd1]  [bt] (2) /workplace/software/tvm/tvm8/build/libtvm.so(+0x17f8d3d) [0x7f3dc52fbd3d]
  [bt] (1) /workplace/software/tvm/tvm8/build/libtvm.so(tvm::relay::OpImplementation::Compute(tvm::Attrs const&, tvm::runtime::Array<tvm::te::Tensor, void> const&, tvm::Type const&)+0xb1) [0x7f3dc52fbb11]
  [bt] (0) /workplace/software/tvm/tvm8/build/libtvm.so(+0x192a9cb) [0x7f3dc542d9cb]
  File "/workplace/software/tvm/tvm8/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
    rv = local_pyfunc(*pyargs)  File "/workplace/software/tvm/tvm8/python/tvm/relay/op/strategy/generic.py", line 663, in _compute_dense
    return [topi_compute(inputs[0], inputs[1], None, out_dtype)]
  File "/workplace/software/tvm/tvm8/python/tvm/autotvm/task/topi_integration.py", line 161, in wrapper    cfg = DispatchContext.current.query(tgt, workload)
  File "/workplace/software/tvm/tvm8/python/tvm/autotvm/task/dispatcher.py", line 76, in query
    ret = self._query_inside(target, workload)
  File "/workplace/software/tvm/tvm8/python/tvm/autotvm/task/dispatcher.py", line 421, in _query_inside
    assert wkl == workload
TVMError: AssertionError

By the way, another similar question can be find with this link Why tuning 2 times, the accuracy of compiled model nearly 0?.

I wish this information could be useful for you to locate the bug.