code: def _onnx_trt_compile(
      onnx_model,
      min_shape: Sequence[int],
      opt_shape: Sequence[int],
      max_shape: Sequence[int],
      device: int,
      precision: str,
      input_names: Sequence[str] | None,
      output_names: Sequence[str] | None,
  ):
      """
      This function takes an ONNX model as input, exports it to a TensorRT engine, wraps the TensorRT engine
      to a TensorRT engine-based TorchScript model and return the TorchScript model.
  
      Args:
          onnx_model: the source ONNX model to compile.
          min_shape: the minimum input shape of the converted TensorRT model.
          opt_shape: the optimization input shape of the model, on which the TensorRT optimizes.
          max_shape: the maximum input shape of the converted TensorRT model.
          device: the target GPU index to convert and verify the model.
          precision: the weight precision of the converted TensorRT engine-based TorchScript model.
              Should be 'fp32' or 'fp16'.
          input_names: optional input names of the ONNX model. Should be a sequence like
              `['input_0', 'input_1', ..., 'input_N']` where N equals to the number of the
              model inputs.
          output_names: optional output names of the ONNX model. Should be a sequence like
              `['output_0', 'output_1', ..., 'output_N']` where N equals to the number of
              the model outputs.
  
      """
      trt, _ = optional_import("tensorrt", "8.5.3")
      torch_tensorrt, _ = optional_import("torch_tensorrt", "1.4.0")
  
      input_shapes = (min_shape, opt_shape, max_shape)
      # default to an empty list to fit the `torch_tensorrt.ts.embed_engine_in_new_module` function.
      input_names = [] if not input_names else input_names
      output_names = [] if not output_names else output_names
  
      # set up the TensorRT builder
      torch_tensorrt.set_device(device)
      logger = trt.Logger(trt.Logger.WARNING)
      builder = trt.Builder(logger)
      network = builder.create_network(
          1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
      )
      profile = builder.create_optimization_profile()
      if input_names:
          profile.set_shape(input_names[0], *input_shapes)
  
      # parse the ONNX model
      parser = trt.OnnxParser(network, logger)
      success = parser.parse(onnx_model.SerializeToString())
      if not success:
          parser_error_message = ""
          for idx in range(parser.num_errors):
              parser_error_message += (
                  parser.get_error(idx).desc() + "\n"
              )
          raise Exception(
              f"TensorRT cannot parse the ONNX model, due to:\n{parser_error_message}"
          )
  
      # set up the conversion configuration
      config = builder.create_builder_config()
      config.set_memory_pool_limit(
          trt.MemoryPoolType.WORKSPACE, 1 << 31
      )
      config.add_optimization_profile(profile)
      if precision == "fp16":
          config.set_flag(trt.BuilderFlag.FP16)
      serialized_engine = builder.build_serialized_network(
          network, config
      )
      f = io.BytesIO()
      f.write(serialized_engine)
  
      # wrap the serialized TensorRT engine back to a TorchScript module.
      trt_model = torch_tensorrt.ts.embed_engine_in_new_module(
          f.getvalue(),
          torch.device(f"cuda:{device}"),
          input_names,
          output_names,
      )
      return trt_model
  
imports: from __future__ import annotations
  import io
  import re
  import warnings
  from collections import OrderedDict
  from collections.abc import Callable, Mapping, Sequence
  from contextlib import contextmanager
  from copy import deepcopy
  from typing import Any
  import numpy
  import torch
  import torch.nn
  from monai.apps.utils import get_logger
  from monai.config import PathLike
  from monai.utils.misc import ensure_tuple, save_obj, set_determinism
  from monai.utils.module import look_up_option, optional_import, pytorch_after
  from monai.utils.type_conversion import convert_to_dst_type, convert_to_tensor
label_desc: Use image node_id 18 for calling a global function with example usage: _onnx_trt_compile(onnx_model, min_shape, opt_shape, max_shape, device, precision, input_names, output_names) and returns: trt_model