code: def tune_and_evaluate(tuning_opt):
      # Register VTA tuning tasks
      register_vta_tuning_tasks()
  
      # Perform task extraction on Relay program
      print("Extract tasks...")
      relay_prog, params = compile_network(
          env, target, network, start_pack, stop_pack
      )
      mod = tvm.IRModule.from_expr(relay_prog)
      tasks = autotvm.task.extract_from_program(
          mod,
          params=params,
          ops=(relay.op.get("nn.conv2d"),),
          target=target,
          target_host=env.target_host,
      )
  
      # filter out non-packed conv2d task
      tasks = list(
          filter(
              lambda t: len(t.args[0][1]) > 4 and "conv" in t.name,
              tasks,
          )
      )
  
      # We should have extracted 10 convolution tasks
      assert len(tasks) == 10
      print("Extracted {} conv2d tasks:".format(len(tasks)))
      for tsk in tasks:
          inp = tsk.args[0][1]
          wgt = tsk.args[1][1]
          batch = inp[0] * inp[4]
          in_filter = inp[1] * inp[5]
          out_filter = wgt[0] * wgt[4]
          height, width = inp[2], inp[3]
          hkernel, wkernel = wgt[2], wgt[3]
          hstride, wstride = tsk.args[2][0], tsk.args[2][1]
          hpad, wpad = tsk.args[3][0], tsk.args[3][1]
          print(
              "({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})".format(
                  batch,
                  height,
                  width,
                  in_filter,
                  out_filter,
                  hkernel,
                  wkernel,
                  hpad,
                  wpad,
                  hstride,
                  wstride,
              )
          )
  
      # We do not run the tuning in our webpage server since it takes too long.
      # Comment the following line to run it by yourself.
      return
  
      # run tuning tasks
      print("Tuning...")
      tune_tasks(tasks, **tuning_opt)
  
      # evaluate with tuning history
      if env.TARGET != "sim":
          # Get remote from fleet node
          remote = autotvm.measure.request_remote(
              env.TARGET, tracker_host, tracker_port, timeout=10000
          )
          # Reconfigure the JIT runtime and FPGA.
          vta.reconfig_runtime(remote)
          vta.program_fpga(remote, bitstream=None)
      else:
          # In simulation mode, host the RPC server locally.
          remote = rpc.LocalSession()
  
      # compile kernels with history best records
      with autotvm.tophub.context(target, extra_files=[log_file]):
          # Compile network
          print("Compile...")
          if target.device_name != "vta":
              with tvm.transform.PassContext(
                  opt_level=3, disabled_pass={"AlterOpLayout"}
              ):
                  lib = relay.build(
                      relay_prog,
                      target=target,
                      params=params,
                      target_host=env.target_host,
                  )
          else:
              with vta.build_config(
                  opt_level=3, disabled_pass={"AlterOpLayout"}
              ):
                  lib = relay.build(
                      relay_prog,
                      target=target,
                      params=params,
                      target_host=env.target_host,
                  )
  
          # Export library
          print("Upload...")
          temp = utils.tempdir()
          lib.export_library(temp.relpath("graphlib.tar"))
          remote.upload(temp.relpath("graphlib.tar"))
          lib = remote.load_module("graphlib.tar")
  
          # Generate the graph executor
          ctx = remote.ext_dev(0) if device == "vta" else remote.cpu(0)
          m = graph_executor.GraphModule(lib["default"](ctx))
  
          # upload parameters to device
          image = tvm.nd.array(
              (np.random.uniform(size=(1, 3, 224, 224))).astype(
                  "float32"
              )
          )
          m.set_input("data", image)
  
          # evaluate
          print("Evaluate inference time cost...")
          timer = m.module.time_evaluator(
              "run", ctx, number=1, repeat=10
          )
          tcost = timer()
          prof_res = (
              np.array(tcost.results) * 1000
          )  # convert to millisecond
          print(
              "Mean inference time (std dev): %.2f ms (%.2f ms)"
              % (np.mean(prof_res), np.std(prof_res))
          )
  
file_path: tvm/vta/tutorials/autotvm/tune_relay_vta.py
imports: import os
  from mxnet.gluon.model_zoo import vision
  import numpy
  from PIL import Image
  from tvm import topi
  import tvm
  from tvm import te
  from tvm import rpc, autotvm, relay
  from tvm.contrib import graph_executor, utils, download
  from tvm.autotvm.measure.measure_methods import request_remote
  from tvm.autotvm.tuner import XGBTuner, GATuner, RandomTuner, GridSearchTuner
  import vta
  from vta.testing import simulator
  from vta.top import graph_pack
label_desc: Use image node_id 4 for calling a global function with example usage: tune_and_evaluate(tuning_opt) without return types