docstr: Tune the model using AutoTVM.
docstr_tok: ["Tune","the","model","using","AutoTVM","."]
code: def _tune_tvm_model(
      target: str, mod: IRModule, params: Dict[str, NDArray]
  ) -> str:
      """Tune the model using AutoTVM."""
      # TODO: add support to Ansor
      tuning_records = f"{uuid.uuid4()}_model_records.json"
      # create a TVM runner
      runner = autotvm.LocalRunner(
          number=AUTO_TVM_PARAMS["number"],
          repeat=AUTO_TVM_PARAMS["repeat"],
          timeout=AUTO_TVM_PARAMS["timeout"],
          min_repeat_ms=AUTO_TVM_PARAMS["min_repeat_ms"],
          # TODO modify min_repeat_ms for GPU usage
          enable_cpu_cache_flush=True,
      )
      # begin by extracting the tasks from the onnx model
      tasks = autotvm.task.extract_from_program(
          mod["main"], target=target, params=params
      )
  
      # Tune the extracted tasks sequentially.
      for i, task in enumerate(tasks):
          tuner_obj = XGBTuner(task, loss_type="rank")
          tuner_obj.tune(
              n_trial=min(
                  AUTO_TVM_TUNING_OPTION["trials"],
                  len(task.config_space),
              ),
              early_stopping=AUTO_TVM_TUNING_OPTION["early_stopping"],
              measure_option=autotvm.measure_option(
                  builder=autotvm.LocalBuilder(build_func="default"),
                  runner=runner,
              ),
              callbacks=[
                  autotvm.callback.log_to_file(tuning_records),
              ],
          )
      return tuning_records
  
imports: import abc
  import os
  import uuid
  from abc import ABC
  from typing import Any, Tuple, Dict, Union
  from nebullvm.config import AUTO_TVM_PARAMS, AUTO_TVM_TUNING_OPTION
  from nebullvm.core.models import QuantizationType, ModelParams, DeviceType, Device
  from nebullvm.operations.optimizations.compilers.base import Compiler
  from nebullvm.operations.optimizations.compilers.quantizations.tvm import TVMCalibrator, quantize_apache_tvm
  from nebullvm.operations.optimizations.compilers.quantizations.utils import check_quantization
  from nebullvm.optional_modules.onnx import onnx
  from nebullvm.optional_modules.torch import Module, torch
  from nebullvm.optional_modules.tvm import tvm, IRModule, NDArray, XGBTuner, autotvm, relay, ExecutorFactoryModule
  from nebullvm.tools.data import DataManager
  from nebullvm.tools.onnx import get_input_names
  from nebullvm.tools.pytorch import create_model_inputs_torch
  from nebullvm.tools.transformations import MultiStageTransformation
label_desc: Use image node_id 8 for calling the ApacheTVMCompiler obj's underlying member method code with example usage: obj._tune_tvm_model(target, mod, params) and returns: tuning_records