code: def compile_model(
      tvmc_model: TVMCModel,
      target: str,
      opt_level: int = 3,
      executor: Optional[Executor] = Executor("graph"),
      runtime: Optional[Runtime] = Runtime("cpp"),
      tuning_records: Optional[str] = None,
      package_path: Optional[str] = None,
      cross: Optional[Union[str, Callable]] = None,
      cross_options: Optional[str] = None,
      output_format: str = "so",
      dump_code: Optional[List[str]] = None,
      dump_offloads: str = "",
      target_host: Optional[str] = None,
      disabled_pass: Optional[str] = None,
      pass_context_configs: Optional[List[str]] = None,
      additional_target_options: Optional[
          Dict[str, Dict[str, Any]]
      ] = None,
      use_vm: bool = False,
      mod_name: Optional[str] = "default",
      workspace_pools: Optional[WorkspaceMemoryPools] = None,
      print_pass_times: bool = False,
      print_ir_before: Optional[List[str]] = None,
      print_ir_after: Optional[List[str]] = None,
      instruments: Optional[Sequence[PassInstrument]] = None,
      desired_layout: Optional[str] = None,
      desired_layout_ops: Optional[List[str]] = None,
      mixed_precision: bool = False,
      mixed_precision_ops: Optional[List[str]] = None,
      mixed_precision_calculation_type: Optional[str] = None,
      mixed_precision_acc_type: Optional[str] = None,
  ):
      """Compile a model from a supported framework into a TVM module.
  
      This function takes a union of the arguments of both frontends.load_model
      and compiler.compile_relay. The resulting TVM module can be executed using
      the graph executor.
  
      Parameters
      ----------
      tvmc_model : TVMCModel
          The model object that should be compiled.
      target : str
          The target for which to compile. Can be a plain string or
          a path.
      opt_level : int
          The option that controls various sorts of optimizations.
      tuning_records : str
          A path to tuning records produced using tvmc.tune. When provided,
          compilation will use more optimized kernels leading to better results.
      package_path : str, optional
          The path to export the compiled model to. If not provided it will
          be saved in a temporary directory.
      cross : str or callable object, optional
          Function that performs the actual compilation
      cross_options : str, optional
          Command line options to be passed to the cross compiler.
      output_format : str
          What format to use when saving the function library. Must be one of "so" or "tar".
          When compiling for a remote device without a cross compiler, "tar" will likely work better.
      dump_code : list[str], optional
          Dump the generated code for the specified source types, on
          the requested target. Choose from: ["asm", "ll", "tir", "relay"].
      dump_offloads : str
          Dump the information about the partition of input model's layers by external codegen.
          Can be '' to not dump at all, '-' to dump to the console
          or '<path_to_file>' to dump to the specified file.
      target_host : str, optional
          The target of the host machine if host-side code
          needs to be generated.
      disabled_pass: str, optional
          Comma-separated list of passes which needs to be disabled
          during compilation.
      pass_context_configs: list[str], optional
          List of strings containing a set of configurations to be passed to the
          PassContext.
      additional_target_options: Optional[Dict[str, Dict[str, Any]]]
          Additional target options in a dictionary to combine with initial Target arguments
      use_vm: bool
          Whether to use the VM to compile the model as opposed to the graph executor
      mod_name: str, optional
          The module name
      workspace_pools: WorkspaceMemoryPools, optional
          Specification of WorkspacePoolInfo objects to be used as workspace memory in the
          compilation.
      print_pass_times: bool
          To enable printing a breakdown of compilation times by pass. Disabled by default.
      print_ir_before: list[str], optional
          To print IR before each named pass of a comma-separated list of passes.
      print_ir_after: list[str], optional
          To print IR after each named pass of a comma-separated list of passes.
      instruments: Optional[Sequence[PassInstrument]]
          The list of pass instrument implementations.
      desired_layout: str, optional
          Can be one of "NCHW" or "NHWC". When specified, compatible operations in the graph
          will have their layout set to this format. Tasks will then be tuned using this
          specified layout.
      desired_layout_ops: list[str], optional
          The list of operators to be transformed with desired layout.
      mixed_precision: bool
          To enable mixed precision transformation. Disabled by default.
      mixed_precision_ops: list[str], optional
          The list of operators to be converted to mixed precision.
          Set to ["nn.conv2d", "nn.dense"] by default
      mixed_precision_calculation_type: str
          The calculation dtype to be used while mixed precision. Set to "float16" by default.
      mixed_precision_acc_type: str
          The accumulation data type to be used while mixed precision. Set to "float16" by default.
  
      Returns
      -------
      compiled_model : TVMCPackage
          The compiled TVMCModel ready to be run.
  
      """
      mod, params = tvmc_model.mod, tvmc_model.params
  
      if dump_code is None:
          dump_code = []
      if not isinstance(dump_code, list):
          dump_code = [dump_code]
      dumps = {}
  
      config = parse_configs(pass_context_configs)
      if "tir" in dump_code:
          config, dumps = add_tir_to_dumps(config, dumps)
  
      initial_relay = None
      if dump_offloads != "":
          # add suffixes to the span field for calls in Relay
          mod = tag_suffixes(mod)
          # remember initial Relay
          initial_relay = deepcopy(mod)
  
      tvm_target, extra_targets = target_from_cli(
          target, additional_target_options
      )
      tvm_target, target_host = Target.canon_target_and_host(
          tvm_target, target_host
      )
  
      partition_functions = []
      partition_opts = []
      for codegen_from_cli in extra_targets:
          codegen = composite_target.get_codegen_by_target(
              codegen_from_cli["name"]
          )
          partition_functions.append(codegen["pass_pipeline"])
          partition_opts.append(codegen_from_cli["opts"])
          if codegen["config_key"] is not None:
              config[codegen["config_key"]] = codegen_from_cli["opts"]
  
      if print_pass_times:
          timing_inst = PassTimingInstrument()
          instruments = (
              [timing_inst]
              if instruments is None
              else [timing_inst] + instruments
          )
  
      if print_ir_before or print_ir_after:
          print_ir_instr = PassPrintingInstrument(
              print_before_pass_names=print_ir_before,
              print_after_pass_names=print_ir_after,
          )
          instruments = (
              [print_ir_instr]
              if instruments is None
              else [print_ir_instr] + instruments
          )
  
      with tvm.transform.PassContext(
          opt_level=opt_level,
          config=config,
          disabled_pass=disabled_pass,
          instruments=instruments,
      ):
          transform_args = parse_graph_transform_args(locals())
          mod = apply_graph_transforms(mod, transform_args)
  
          for partition_function, opts in zip(
              partition_functions, partition_opts
          ):
              mod = partition_function(
                  mod, params, mod_name=mod_name, **opts
              )
  
          if initial_relay:
              # dump which operations are offloaded to which backend
              dump_operation_offloads(mod, initial_relay, dump_offloads)
  
          if tuning_records and os.path.exists(tuning_records):
              logger.debug(
                  "tuning records file provided: %s", tuning_records
              )
  
              use_autoscheduler = True
              try:
                  auto_scheduler.load_records(tuning_records)
              except tvm._ffi.base.TVMError:
                  use_autoscheduler = False
  
              if use_autoscheduler:
                  with auto_scheduler.ApplyHistoryBest(tuning_records):
                      config["relay.backend.use_auto_scheduler"] = True
                      logger.debug(
                          "building relay graph with autoscheduler"
                      )
                      graph_module = build(
                          mod,
                          tvm_target=tvm_target,
                          executor=executor,
                          runtime=runtime,
                          params=params,
                          use_vm=use_vm,
                          mod_name=mod_name,
                          workspace_pools=workspace_pools,
                      )
              else:
                  with autotvm.apply_history_best(tuning_records):
                      logger.debug(
                          "building relay graph with tuning records"
                      )
                      graph_module = build(
                          mod,
                          tvm_target=tvm_target,
                          executor=executor,
                          runtime=runtime,
                          params=params,
                          use_vm=use_vm,
                          mod_name=mod_name,
                          workspace_pools=workspace_pools,
                      )
          else:
              logger.debug(
                  "building relay graph (no tuning records provided)"
              )
              graph_module = build(
                  mod,
                  tvm_target=tvm_target,
                  executor=executor,
                  runtime=runtime,
                  params=params,
                  use_vm=use_vm,
                  mod_name=mod_name,
                  workspace_pools=workspace_pools,
              )
  
          # Generate output dump files with sources
          for source_type in dump_code:
              if source_type == "relay":
                  dumps[source_type] = str(mod)
              elif source_type == "tir":
                  dumps[source_type] = "\n".join(dumps[source_type])
              else:
                  lib = (
                      graph_module.lib
                      if use_vm
                      else graph_module.get_lib()
                  )
                  # TODO lib.get_source call have inconsistent behavior for unsupported
                  #      formats (@leandron).
                  dumps[source_type] = lib.get_source(source_type)
                  for smod in lib.imported_modules:
                      dumps[smod.type_key] = smod.get_source()
  
          # Create a new tvmc model package object from the graph definition.
          package_path = tvmc_model.export_package(
              graph_module,
              package_path,
              cross,
              cross_options,
              output_format,
          )
  
          # Write dumps to file.
          if dumps:
              save_dumps(package_path, dumps)
  
          # Print compilation times per pass
          if print_pass_times:
              print("Compilation time breakdown by pass:")
              print(timing_inst.render())
  
          return TVMCPackage(package_path)
  
imports: import logging
  import os.path
  import re
  import itertools
  from copy import deepcopy
  from typing import Any, Optional, Dict, List, Union, Callable, Sequence
  from pathlib import Path
  from collections import defaultdict
  import tvm
  from tvm import autotvm, auto_scheduler
  from tvm import relay
  from tvm.driver.tvmc.registry import generate_registry_args, reconstruct_registry_entity
  from tvm.ir.instrument import PassInstrument, PassTimingInstrument, PassPrintingInstrument
  from tvm.ir.memory_pools import WorkspaceMemoryPools
  from tvm.target import Target
  from tvm.relay.backend import Executor, Runtime
  from tvm.relay.analysis.operations_distribution import analyze_operations_distribution
  from tvm.relay.transform.suffixes import tag_suffixes
  from .None import composite_target, frontends, TVMCException
  from .model import TVMCModel, TVMCPackage
  from .main import register_parser
  from .target import target_from_cli, generate_target_args, reconstruct_target_args
  from .pass_config import parse_configs
  from .pass_list import parse_pass_list_str
  from .transform import generate_transform_args, parse_graph_transform_args, apply_graph_transforms
  from .shape_parser import parse_shape_string
  from .workspace_pools import generate_workspace_pools_args, workspace_pools_recombobulate
label_desc: Use image node_id 3 for calling a global function with example usage: compile_model(tvmc_model, target, opt_level, executor, runtime, tuning_records, package_path, cross, cross_options, output_format, dump_code, dump_offloads, target_host, disabled_pass, pass_context_configs, additional_target_options, use_vm, mod_name, workspace_pools, print_pass_times, print_ir_before, print_ir_after, instruments, desired_layout, desired_layout_ops, mixed_precision, mixed_precision_ops, mixed_precision_calculation_type, mixed_precision_acc_type) and returns: TVMCPackage