code: def export_pytorch(
      preprocessor: Union[
          "PreTrainedTokenizer",
          "FeatureExtractionMixin",
          "ProcessorMixin",
      ],
      model: "PreTrainedModel",
      config: OnnxConfig,
      opset: int,
      output: Path,
      tokenizer: "PreTrainedTokenizer" = None,
      device: str = "cpu",
  ) -> Tuple[List[str], List[str]]:
      """
      Export a PyTorch model to an ONNX Intermediate Representation (IR)
  
      Args:
          preprocessor: ([`PreTrainedTokenizer`], [`FeatureExtractionMixin`] or [`ProcessorMixin`]):
              The preprocessor used for encoding the data.
          model ([`PreTrainedModel`]):
              The model to export.
          config ([`~onnx.config.OnnxConfig`]):
              The ONNX configuration associated with the exported model.
          opset (`int`):
              The version of the ONNX operator set to use.
          output (`Path`):
              Directory to store the exported ONNX model.
          device (`str`, *optional*, defaults to `cpu`):
              The device on which the ONNX model will be exported. Either `cpu` or `cuda`.
  
      Returns:
          `Tuple[List[str], List[str]]`: A tuple with an ordered list of the model's inputs, and the named inputs from
          the ONNX configuration.
      """
  
      if (
          isinstance(preprocessor, PreTrainedTokenizerBase)
          and tokenizer is not None
      ):
          raise ValueError(
              "You cannot provide both a tokenizer and a preprocessor to export the model."
          )
      if tokenizer is not None:
          warnings.warn(
              "The `tokenizer` argument is deprecated and will be removed in version 5 of Transformers. Use"
              " `preprocessor` instead.",
              FutureWarning,
          )
          logger.info(
              "Overwriting the `preprocessor` argument with `tokenizer` to generate dummmy inputs."
          )
          preprocessor = tokenizer
  
      if issubclass(type(model), PreTrainedModel):
          import torch
          from torch.onnx import export as onnx_export
  
          logger.info(f"Using framework PyTorch: {torch.__version__}")
          with torch.no_grad():
              model.config.return_dict = True
              model.eval()
  
              # Check if we need to override certain configuration item
              if config.values_override is not None:
                  logger.info(
                      f"Overriding {len(config.values_override)} configuration item(s)"
                  )
                  for (
                      override_config_key,
                      override_config_value,
                  ) in config.values_override.items():
                      logger.info(
                          f"\t- {override_config_key} -> {override_config_value}"
                      )
                      setattr(
                          model.config,
                          override_config_key,
                          override_config_value,
                      )
  
              # Ensure inputs match
              # TODO: Check when exporting QA we provide "is_pair=True"
              model_inputs = config.generate_dummy_inputs(
                  preprocessor, framework=TensorType.PYTORCH
              )
              device = torch.device(device)
              if device.type == "cuda" and torch.cuda.is_available():
                  model.to(device)
                  model_inputs_device = {}
                  for k, v in model_inputs.items():
                      if isinstance(v, Tuple):
                          model_inputs_device[k] = tuple(
                              x.to(device)
                              if isinstance(x, torch.Tensor)
                              else None
                              for x in v
                          )
                      elif isinstance(v, List):
                          model_inputs_device[k] = [
                              tuple(
                                  x.to(device)
                                  if isinstance(x, torch.Tensor)
                                  else None
                                  for x in t
                              )
                              for t in v
                          ]
                      else:
                          model_inputs_device[k] = v.to(device)
  
                  model_inputs = model_inputs_device
  
              (
                  inputs_match,
                  matched_inputs,
              ) = ensure_model_and_config_inputs_match(
                  model, model_inputs.keys()
              )
              onnx_outputs = list(config.outputs.keys())
  
              if not inputs_match:
                  raise ValueError(
                      "Model and config inputs doesn't match"
                  )
  
              config.patch_ops()
  
              onnx_export(
                  model,
                  (model_inputs,),
                  f=output.as_posix(),
                  input_names=list(config.inputs.keys()),
                  output_names=onnx_outputs,
                  dynamic_axes=dict(
                      chain(
                          config.inputs.items(), config.outputs.items()
                      )
                  ),
                  do_constant_folding=True,
                  opset_version=opset,
              )
  
              config.restore_ops()
  
      return matched_inputs, onnx_outputs
  
file_path: transformers/src/transformers/onnx/convert.py
imports: import warnings
  from inspect import signature
  from itertools import chain
  from pathlib import Path
  from typing import TYPE_CHECKING, Iterable, List, Tuple, Union
  import numpy
  from packaging.version import Version, parse
  from ..tokenization_utils_base import PreTrainedTokenizerBase
  from ..utils import TensorType, is_tf_available, is_torch_available, logging
  from .config import OnnxConfig
label_desc: Use image node_id 2 for calling a global function with example usage: export_pytorch(preprocessor, model, config, opset, output, tokenizer, device) and returns: matched_inputs,  onnx_outputs