code: def trt_export(
      net_id: str | None = None,
      filepath: PathLike | None = None,
      ckpt_file: str | None = None,
      meta_file: str | Sequence[str] | None = None,
      config_file: str | Sequence[str] | None = None,
      key_in_ckpt: str | None = None,
      precision: str | None = None,
      input_shape: Sequence[int] | None = None,
      use_trace: bool | None = None,
      dynamic_batchsize: Sequence[int] | None = None,
      device: int | None = None,
      use_onnx: bool | None = None,
      onnx_input_names: Sequence[str] | None = None,
      onnx_output_names: Sequence[str] | None = None,
      args_file: str | None = None,
      converter_kwargs: Mapping | None = None,
      **override: Any,
  ) -> None:
      """
      Export the model checkpoint to the given filepath as a TensorRT engine-based TorchScript.
      Currently, this API only supports converting models whose inputs are all tensors.
  
      There are two ways to export a model:
      1, Torch-TensorRT way: PyTorch module ---> TorchScript module ---> TensorRT engine-based TorchScript.
      2, ONNX-TensorRT way: PyTorch module ---> TorchScript module ---> ONNX model ---> TensorRT engine --->
      TensorRT engine-based TorchScript.
  
      When exporting through the first way, some models suffer from the slowdown problem, since Torch-TensorRT
      may only convert a little part of the PyTorch model to the TensorRT engine. However when exporting through
      the second way, some Python data structures like `dict` are not supported. And some TorchScript models are
      not supported by the ONNX if exported through `torch.jit.script`.
  
      Typical usage examples:
  
      .. code-block:: bash
  
          python -m monai.bundle trt_export --net_id <network definition> --filepath <export path> \
              --ckpt_file <checkpoint path> --input_shape <input shape> --dynamic_batchsize <batch range> ...
  
      Args:
          net_id: ID name of the network component in the config, it must be `torch.nn.Module`.
          filepath: filepath to export, if filename has no extension, it becomes `.ts`.
          ckpt_file: filepath of the model checkpoint to load.
          meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged.
          config_file: filepath of the config file to save in the TensorRT based TorchScript model and extract network
              information, the saved key in the model is the config filename without extension, and the saved config
              value is always serialized in JSON format no matter the original file format is JSON or YAML.
              it can be a single file or a list of files. if `None`, must be provided in `args_file`.
          key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model
              weights. if not nested checkpoint, no need to set.
          precision: the weight precision of the converted TensorRT engine based TorchScript models. Should be 'fp32' or 'fp16'.
          input_shape: the input shape that is used to convert the model. Should be a list like [N, C, H, W] or
              [N, C, H, W, D]. If not given, will try to parse from the `metadata` config.
          use_trace: whether using `torch.jit.trace` to convert the PyTorch model to a TorchScript model and then convert to
              a TensorRT engine based TorchScript model or an ONNX model (if `use_onnx` is True).
          dynamic_batchsize: a sequence with three elements to define the batch size range of the input for the model to be
              converted. Should be a sequence like [MIN_BATCH, OPT_BATCH, MAX_BATCH]. After converted, the batchsize of
              model input should between `MIN_BATCH` and `MAX_BATCH` and the `OPT_BATCH` is the best performance batchsize
              that the TensorRT tries to fit. The `OPT_BATCH` should be the most frequently used input batchsize in
              the application.
          device: the target GPU index to convert and verify the model.
          use_onnx: whether using the ONNX-TensorRT way to export the TensorRT engine-based TorchScript model.
          onnx_input_names: optional input names of the ONNX model. This arg is only useful when `use_onnx` is True. Should be
              a sequence like `['input_0', 'input_1', ..., 'input_N']` where N equals to the number of the model inputs. If not
              given, will use `['input_0']`, which supposes the model only has one input.
          onnx_output_names: optional output names of the ONNX model. This arg is only useful when `use_onnx` is True. Should be
              a sequence like `['output_0', 'output_1', ..., 'output_N']` where N equals to the number of the model outputs. If
              not given, will use `['output_0']`, which supposes the model only has one output.
          args_file: a JSON or YAML file to provide default values for all the parameters of this function, so that
              the command line inputs can be simplified.
          converter_kwargs: extra arguments that are needed by `convert_to_trt`, except ones that already exist in the
              input parameters.
          override: id-value pairs to override or add the corresponding config content.
              e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``.
  
      """
      _args = update_kwargs(
          args=args_file,
          net_id=net_id,
          filepath=filepath,
          meta_file=meta_file,
          config_file=config_file,
          ckpt_file=ckpt_file,
          key_in_ckpt=key_in_ckpt,
          precision=precision,
          input_shape=input_shape,
          use_trace=use_trace,
          dynamic_batchsize=dynamic_batchsize,
          device=device,
          use_onnx=use_onnx,
          onnx_input_names=onnx_input_names,
          onnx_output_names=onnx_output_names,
          converter_kwargs=converter_kwargs,
          **override,
      )
      _log_input_summary(tag="trt_export", args=_args)
      (
          filepath_,
          ckpt_file_,
          config_file_,
          net_id_,
          meta_file_,
          key_in_ckpt_,
          precision_,
          input_shape_,
          use_trace_,
          dynamic_batchsize_,
          device_,
          use_onnx_,
          onnx_input_names_,
          onnx_output_names_,
          converter_kwargs_,
      ) = _pop_args(
          _args,
          "filepath",
          "ckpt_file",
          "config_file",
          net_id="",
          meta_file=None,
          key_in_ckpt="",
          precision="fp32",
          input_shape=[],
          use_trace=False,
          dynamic_batchsize=None,
          device=None,
          use_onnx=False,
          onnx_input_names=["input_0"],
          onnx_output_names=["output_0"],
          converter_kwargs={},
      )
  
      parser = ConfigParser()
  
      parser.read_config(f=config_file_)
      if meta_file_ is not None:
          parser.read_meta(f=meta_file_)
  
      # the rest key-values in the _args are to override config content
      for k, v in _args.items():
          parser[k] = v
  
      # The convert_to_trt must have an `input_shape_` as input, no matter what the `use_trace` is.
      # If the `input_shape` is not provided, will try to parse it from the parser`.
      if not input_shape_:
          input_shape_ = _get_fake_input_shape(parser=parser)
  
      trt_api_parameters = {
          "precision": precision_,
          "input_shape": input_shape_,
          "dynamic_batchsize": dynamic_batchsize_,
          "use_trace": use_trace_,
          "device": device_,
          "use_onnx": use_onnx_,
          "onnx_input_names": onnx_input_names_,
          "onnx_output_names": onnx_output_names_,
      }
      converter_kwargs_.update(trt_api_parameters)
  
      _export(
          convert_to_trt,
          parser,
          net_id=net_id_,
          filepath=filepath_,
          ckpt_file=ckpt_file_,
          config_file=config_file_,
          key_in_ckpt=key_in_ckpt_,
          **converter_kwargs_,
      )
  
imports: from __future__ import annotations
  import ast
  import json
  import os
  import re
  import warnings
  from collections.abc import Mapping, Sequence
  from pathlib import Path
  from pydoc import locate
  from shutil import copyfile
  from textwrap import dedent
  from typing import Any, Callable
  import torch
  from torch.cuda import is_available
  from monai.apps.mmars.mmars import _get_all_ngc_models
  from monai.apps.utils import _basename, download_url, extractall, get_logger
  from monai.bundle.config_item import ConfigComponent
  from monai.bundle.config_parser import ConfigParser
  from monai.bundle.utils import DEFAULT_INFERENCE, DEFAULT_METADATA
  from monai.bundle.workflows import BundleWorkflow, ConfigWorkflow
  from monai.config import IgniteInfo, PathLike
  from monai.data import load_net_with_metadata, save_net_with_metadata
  from monai.networks import convert_to_onnx, convert_to_torchscript, convert_to_trt, copy_model_state, get_state_dict, save_state
  from monai.utils import check_parent_dir, deprecated_arg, ensure_tuple, get_equivalent_dtype, min_version, optional_import, pprint_edges
label_desc: Use image node_id 32 for calling a global function with example usage: trt_export(net_id, filepath, ckpt_file, meta_file, config_file, key_in_ckpt, precision, input_shape, use_trace, dynamic_batchsize, device, use_onnx, onnx_input_names, onnx_output_names, args_file, converter_kwargs) without return types