code: def main():
      """Main function"""
      describe()
      with ms.Profiler() as profiler:
          # initialize
          target = ARGS.target
          dev_type = get_device_type(target)
          builder = ms.builder.LocalBuilder()
          database = ms.database.create(work_dir=ARGS.work_dir)
  
          # collect records
          with profiler.timeit("collect records"):
              records = database.get_all_tuning_records()
          total = len(records)
          print(
              f"Total {total} records to be validated. "
              f"Collected in {float(profiler.get()['collect records']): 3.3f} sec."
          )
  
          # collect unique original TIR
          with profiler.timeit("deduplicate records"):
              workloads = set()
              for record in records:
                  workloads.add(OriginalModule(record.workload.mod))
          print(
              f"Total {len(workloads)} unique original TIR to validate. "
              f"Deduplicated in {float(profiler.get()['deduplicate records']): 3.3f} sec."
          )
          if ARGS.top_k < 10**9:
              print(
                  f"Top {ARGS.top_k} records for each original TIR will be validated."
              )
              total = len(workloads) * ARGS.top_k
          print()
  
          # validate correctness
          counter = 0
          for item in workloads:
              original_mod = item.mod
              records = database.get_top_k(
                  workload=database.commit_workload(original_mod),
                  top_k=ARGS.top_k,
              )
              if len(records) < ARGS.top_k:
                  total -= ARGS.top_k - len(records)
              inputs = to_numpy(
                  check_and_run(ARGS.input_generator_func, original_mod)
              )
              original_res, original_run_secs = local_build_and_run(
                  original_mod,
                  target=ARGS.baseline_target,
                  inputs=inputs,
                  device=get_runtime_device(ARGS.baseline_target),
              )
              scheduled_mods = [
                  _apply_trace(original_mod, record.trace)
                  for record in records
              ]
              builder_results = _build_all_mods(scheduled_mods, builder, target)  # type: ignore
              for i, record in enumerate(records):
                  counter += 1
                  print_result = print_with_counter_func(
                      counter=counter, total=total
                  )
                  if is_failed_record(record):
                      # skip failed records where run_secs is 1e9
                      # these records are only negative samples for cost model
                      print_result(result="skip")
                      continue
                  try:
                      # prepare scheduled module
                      scheduled_mod = scheduled_mods[i]
                      # check build result
                      builder_result = builder_results[i]
                      _check_builder_result(builder_result)
                      # fetch functions
                      (
                          f_with_args_alloc_argument,
                          f_with_args_run_evaluator,
                      ) = make_alloc_arg_and_check(
                          inputs,
                          original_mod,
                          scheduled_mod,
                          str(record.trace),
                          original_res=original_res,
                          original_run_secs=original_run_secs,
                          print_result=print_result,
                      )
                      # create runner
                      evaluator_config = ms.runner.EvaluatorConfig(
                          number=ARGS.number,
                          repeat=ARGS.repeat,
                          min_repeat_ms=ARGS.min_repeat_ms,
                          enable_cpu_cache_flush=ARGS.cpu_flush,
                      )
                      if ARGS.rpc_config is not None:
                          runner: ms.Runner = ms.runner.RPCRunner(  # type: ignore
                              ARGS.rpc_config,
                              evaluator_config=evaluator_config,
                              alloc_repeat=1,
                              f_alloc_argument=f_with_args_alloc_argument,
                              f_run_evaluator=f_with_args_run_evaluator,
                              initializer=initializer,
                          )
                      else:
                          runner: ms.Runner = ms.runner.LocalRunner(  # type: ignore
                              evaluator_config=evaluator_config,
                              alloc_repeat=1,
                              f_alloc_argument=f_with_args_alloc_argument,
                              f_run_evaluator=f_with_args_run_evaluator,
                              initializer=initializer,
                          )
  
                      # run and validate
                      _run_single_mod(builder_result, runner, dev_type)  # type: ignore
                  except (
                      Exception
                  ) as e:  # pylint: disable=broad-except, invalid-name
                      # validation failed with exception
                      print_result(
                          result="exception",
                          original_mod=original_mod,
                          scheduled_mod=scheduled_mod,
                          trace=str(record.trace),
                          exception=e,
                      )
                  # clean up
                  remove_build_dir(builder_result.artifact_path)
      print(
          f"Validation finished! Total time spent: {float(profiler.get()['Total']): 3.3f} sec."
      )
  
imports: import argparse
  import logging
  import warnings
  import itertools
  from statistics import mean
  from distutils.util import strtobool
  from typing import Callable, Tuple, Union, List, Any
  import numpy
  import tvm
  from tvm import meta_schedule
  from tvm._ffi import get_global_func, register_func
  from tvm.ir import IRModule
  from tvm.support import describe
  from tvm.target import Target
  from tvm.tir import Schedule
  from tvm.tir.schedule import Trace
  from tvm.meta_schedule.utils import remove_build_dir
  from tvm.meta_schedule.testing.tune_utils import generate_input_data
  from tvm.tir.tensor_intrin import *
label_desc: Use image node_id 17 for calling a global function with example usage: main() without return types