docstr: Compile the input model using TensorRT Compiler from the
      ONNX interface.
  
  Args:
      model (str): The path to the onnx model.
      model_params (ModelParams): The model parameters.
      input_tfms (MultiStageTransformation, optional): Transformations
          to be performed to the model's input tensors in order to
          get the prediction. Default: None.
      metric_drop_ths (float, optional): Threshold for the accepted drop
          in terms of precision. Any optimized model with a higher drop
          will be ignored. Default: None.
      quantization_type (QuantizationType, optional): The desired
          quantization algorithm to be used. Default: None.
      input_data (DataManager): User defined data. Default: None
      is_diffusion (bool): Whether the model is a diffusion model.
          Default: False.
docstr_tok: ["Compile","the","input","model","using","TensorRT","Compiler","from","the","ONNX","interface",".","Args",":","model","(","str",")",":","The","path","to","the","onnx","model",".","model_params","(","ModelParams",")",":","The","model","parameters",".","input_tfms","(","MultiStageTransformation",",","optional",")",":","Transformations","to","be","performed","to","the","model","'s","input","tensors","in","order","to","get","the","prediction",".","Default",":","None",".","metric_drop_ths","(","float",",","optional",")",":","Threshold","for","the","accepted","drop","in","terms","of","precision",".","Any","optimized","model","with","a","higher","drop","will","be","ignored",".","Default",":","None",".","quantization_type","(","QuantizationType",",","optional",")",":","The","desired","quantization","algorithm","to","be","used",".","Default",":","None",".","input_data","(","DataManager",")",":","User","defined","data",".","Default",":","None","is_diffusion","(","bool",")",":","Whether","the","model","is","a","diffusion","model",".","Default",":","False","."]
code: def execute(
      self,
      model: str,
      model_params: ModelParams,
      input_tfms: MultiStageTransformation = None,
      metric_drop_ths: float = None,
      quantization_type: QuantizationType = None,
      input_data: DataManager = None,
      is_diffusion: bool = False,
      **kwargs,
  ):
      """Compile the input model using TensorRT Compiler from the
          ONNX interface.
  
      Args:
          model (str): The path to the onnx model.
          model_params (ModelParams): The model parameters.
          input_tfms (MultiStageTransformation, optional): Transformations
              to be performed to the model's input tensors in order to
              get the prediction. Default: None.
          metric_drop_ths (float, optional): Threshold for the accepted drop
              in terms of precision. Any optimized model with a higher drop
              will be ignored. Default: None.
          quantization_type (QuantizationType, optional): The desired
              quantization algorithm to be used. Default: None.
          input_data (DataManager): User defined data. Default: None
          is_diffusion (bool): Whether the model is a diffusion model.
              Default: False.
      """
  
      if (
          quantization_type
          not in self.supported_ops[self.device.type.value]
      ):
          self.compiled_model = None
          return
  
      if (
          quantization_type is QuantizationType.STATIC
          and input_data is None
      ):
          raise ValueError(
              "Input data is required for static quantization."
          )
  
      self.logger.info(
          f"Optimizing with {self.__class__.__name__} and "
          f"q_type: {quantization_type}."
      )
  
      check_quantization(quantization_type, metric_drop_ths)
      train_input_data = input_data.get_split("train").get_numpy_list(
          QUANTIZATION_DATA_NUM
      )
  
      if self.simplify_model and not is_diffusion:
          try:
              import onnxsim  # noqa: F401
  
              # Simplify model, otherwise tensor RT won't work
              # on gpt2 and some other models.
              simplified_model = str(model) + "_simplified"
              if not Path(simplified_model).is_file():
                  cmd = [
                      "onnxsim",
                      str(model),
                      simplified_model,
                  ]
                  subprocess.run(cmd, stdout=subprocess.DEVNULL)
  
              # First try with simplified model
              self.onnx_model_path = simplified_model
              assert os.path.isfile(self.onnx_model_path)
          except Exception:
              # Use original model
              self.logger.warning(
                  "Unable to simplify model with ONNX Simplifier. "
                  "Original ONNX model will be used to build "
                  "TensorRT engine"
              )
              self.onnx_model_path = str(model)
          self.simplify_model = False
      elif self.onnx_model_path is None:
          self.onnx_model_path = str(model)
  
      if is_diffusion:
          if quantization_type is None:
              self.logger.warning(
                  "Skipping float32 precision for Stable Diffusion, "
                  "half precision will be used instead."
              )
              return
          if quantization_type is QuantizationType.STATIC:
              self.logger.warning(
                  "Skipping static quantization for Stable Diffusion "
                  "because for now it's not supported."
              )
              return
  
      if self.simplify_model and is_diffusion:
          optimized_model = str(Path(model).parent / "model_opt.onnx")
          unet = UNet(hf_token=None)
          opt_graph = unet.optimize(onnx.load(str(model)))
          try:
              onnx.save(opt_graph, optimized_model)
          except Exception:
              onnx.save(
                  opt_graph, optimized_model, save_as_external_data=True
              )
          self.onnx_model_path = optimized_model
          self.simplify_model = False
      elif self.onnx_model_path is None:
          self.onnx_model_path = str(model)
  
      # -- Build phase --
      nvidia_logger = trt.Logger(trt.Logger.ERROR)
      builder = trt.Builder(nvidia_logger)
      # create network definition
      network = builder.create_network(
          1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
      )
      # build the engine
      # TODO: setup config value for the class in a config file
      config = builder.create_builder_config()
      try:
          config.set_memory_pool_limit(
              trt.MemoryPoolType.WORKSPACE,
              self.device.get_free_memory(),
          )
      except AttributeError:
          # The method set_memory_pool_limit is not available
          # until TensorRT Release 8.4.1
          self.logger.warning(
              "Cannot call method set_memory_pool_limit for TensorRT. "
              "because your version is lower than 8.4.1. "
              "Please update TensorRT version."
          )
  
      if quantization_type is not None:
          config = self._quantize_model(
              quantization_type,
              model_params,
              config,
              input_tfms,
              train_input_data
              if quantization_type is QuantizationType.STATIC
              else None,
          )
  
      self.compiled_model = self._compile_model(
          onnx_model_path=str(self.onnx_model_path),
          model_params=model_params,
          config=config,
          network=network,
          builder=builder,
          nvidia_logger=nvidia_logger,
      )
      self.model_orig = self.onnx_model_path
  
imports: import abc
  import copy
  import os
  import subprocess
  from pathlib import Path
  from typing import List, Any, Tuple
  import numpy
  from nebullvm.config import QUANTIZATION_DATA_NUM, TORCH_TENSORRT_PRECISIONS
  from nebullvm.core.models import QuantizationType, ModelParams
  from nebullvm.operations.optimizations.compilers.base import Compiler
  from nebullvm.operations.optimizations.compilers.quantizations.tensor_rt import quantize_tensorrt
  from nebullvm.operations.optimizations.compilers.quantizations.utils import check_quantization
  from nebullvm.optional_modules.onnx import onnx
  from nebullvm.optional_modules.tensor_rt import tensorrt
  from nebullvm.optional_modules.torch import torch, Module
  from nebullvm.optional_modules.torch_tensorrt import torch_tensorrt, DataLoaderCalibrator
  from nebullvm.tools.data import DataManager, PytorchDataset
  from nebullvm.tools.diffusers import UNet
  from nebullvm.tools.onnx import get_input_names
  from nebullvm.tools.transformations import MultiStageTransformation, HalfPrecisionTransformation
label_desc: Use image node_id 2 for calling the ONNXTensorRTCompiler obj's underlying member method code with example usage: obj.execute(model, model_params, input_tfms, metric_drop_ths, quantization_type, input_data, is_diffusion) without return types