code: def check_result(
      mod,
      map_inputs,
      out_shape,
      result,
      tol=1e-5,
      target="llvm",
      device=tvm.cpu(),
      params=None,
      runtime=Runtime("cpp"),
  ):
      if sys.platform == "win32":
          print("Skip test on Windows for now")
          return
  
      def update_lib(lib):
          test_dir = os.path.dirname(
              os.path.realpath(os.path.expanduser(__file__))
          )
          source_dir = os.path.join(test_dir, "..", "..", "..")
          contrib_path = os.path.join(
              source_dir, "src", "runtime", "contrib"
          )
  
          kwargs = {}
          kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path]
          tmp_path = utils.tempdir()
          lib_name = "lib.so"
          lib_path = tmp_path.relpath(lib_name)
          lib.export_library(lib_path, fcompile=False, **kwargs)
          lib = tvm_runtime.load_module(lib_path)
  
          return lib
  
      def check_vm_result():
          te_compiler.get().clear()
          with tvm.transform.PassContext(opt_level=3):
              exe = relay.vm.compile(mod, target=target, params=params)
          code, lib = exe.save()
          lib = update_lib(lib)
          exe = tvm_runtime.vm.Executable.load_exec(code, lib)
          vm = tvm_runtime.vm.VirtualMachine(exe, device)
          outs = vm.run(**map_inputs)
          outs = (
              outs
              if isinstance(outs, tvm_runtime.container.ADT)
              else [outs]
          )
          results = result if isinstance(result, list) else [result]
          for out, ref in zip(outs, results):
              tvm.testing.assert_allclose(
                  out.numpy(), ref, rtol=tol, atol=tol
              )
  
      def check_graph_executor_result():
          te_compiler.get().clear()
          with tvm.transform.PassContext(opt_level=3):
              json, lib, param = relay.build(
                  mod, target=target, params=params, runtime=runtime
              )
          lib = update_lib(lib)
          rt_mod = tvm.contrib.graph_executor.create(json, lib, device)
  
          for name, data in map_inputs.items():
              rt_mod.set_input(name, data)
          rt_mod.set_input(**param)
          rt_mod.run()
  
          out_shapes = (
              out_shape if isinstance(out_shape, list) else [out_shape]
          )
          results = result if isinstance(result, list) else [result]
  
          for idx, shape in enumerate(out_shapes):
              out = tvm.nd.empty(shape, device=device)
              out = rt_mod.get_output(idx, out)
              tvm.testing.assert_allclose(
                  out.numpy(), results[idx], rtol=tol, atol=tol
              )
  
      check_vm_result()
      check_graph_executor_result()
  
imports: import os
  import sys
  import numpy
  import tvm
  from tvm.relay.backend import te_compiler
  from tvm.relay.backend.runtime import Runtime
  import tvm.relay.testing
  import tvm.relay.op
  from tvm import relay
  from tvm import runtime
  from tvm.relay import transform
  from tvm.relay.testing import byoc
  from tvm.contrib import utils
  from tvm.relay.expr_functor import ExprMutator
  from tvm.relay.op.annotation import compiler_begin, compiler_end
  from tvm.relay.op.contrib.register import get_pattern_table
  from tvm.relay.build_module import bind_params_by_name
label_desc: Use image node_id 1 for calling a global function with example usage: check_result(mod, map_inputs, out_shape, result, tol, target, device, params, runtime) and returns: lib