class_docstr: Integration tests ensuring supported models are correctly exported.
class_docstr_tok: ["Integration","tests","ensuring","supported","models","are","correctly","exported","."]
code: def _onnx_export(
      self,
      test_name: str,
      model_type: str,
      model_name: str,
      task: str,
      onnx_config_class_constructor,
      shapes_to_validate: Dict,
      monolith: bool,
      device="cpu",
  ):
      library_name = TasksManager.infer_library_from_model(model_name)
  
      if library_name == "timm":
          model_class = TasksManager.get_model_class_for_task(
              task, library=library_name
          )
          model = model_class(
              f"hf_hub:{model_name}", pretrained=True, exportable=True
          )
          TasksManager.standardize_model_attributes(
              model_name, model, library_name=library_name
          )
      else:
          config = AutoConfig.from_pretrained(model_name)
          model_class = TasksManager.get_model_class_for_task(
              task, model_type=config.model_type.replace("_", "-")
          )
          model = model_class.from_config(config)
  
      # Dynamic axes aren't supported for YOLO-like models. This means they cannot be exported to ONNX on CUDA devices.
      # See: https://github.com/ultralytics/yolov5/pull/8378
      if (
          model.__class__.__name__.startswith("Yolos")
          and device != "cpu"
      ):
          return
  
      onnx_config = onnx_config_class_constructor(model.config)
  
      # We need to set this to some value to be able to test the outputs values for batch size > 1.
      if (
          isinstance(onnx_config, OnnxConfigWithPast)
          and getattr(model.config, "pad_token_id", None) is None
          and task == "text-classification"
      ):
          model.config.pad_token_id = 0
  
      if is_torch_available():
          from optimum.utils import torch_version
  
          if not onnx_config.is_transformers_support_available:
              import transformers
  
              pytest.skip(
                  "Skipping due to incompatible Transformers version. Minimum required is"
                  f" {onnx_config.MIN_TRANSFORMERS_VERSION}, got: {transformers.__version__}"
              )
  
          if not onnx_config.is_torch_support_available:
              pytest.skip(
                  "Skipping due to incompatible PyTorch version. Minimum required is"
                  f" {onnx_config.MIN_TORCH_VERSION}, got: {torch_version}"
              )
  
      atol = onnx_config.ATOL_FOR_VALIDATION
      if isinstance(atol, dict):
          atol = atol[task.replace("-with-past", "")]
  
      model_kwargs = None
      if (
          model.config.is_encoder_decoder
          and task.startswith(
              (
                  "text2text-generation",
                  "automatic-speech-recognition",
                  "image-to-text",
                  "feature-extraction-with-past",
              )
          )
          and monolith is False
      ):
          models_and_onnx_configs = (
              get_encoder_decoder_models_for_export(model, onnx_config)
          )
      elif task.startswith("text-generation") and monolith is False:
          models_and_onnx_configs = get_decoder_models_for_export(
              model, onnx_config
          )
      elif model.config.model_type == "speecht5":
          model_kwargs = {"vocoder": "fxmarty/speecht5-hifigan-tiny"}
          models_and_onnx_configs = get_speecht5_models_for_export(
              model, onnx_config, model_kwargs
          )
      else:
          models_and_onnx_configs = {"model": (model, onnx_config)}
  
      with TemporaryDirectory() as tmpdirname:
          onnx_inputs, onnx_outputs = export_models(
              models_and_onnx_configs=models_and_onnx_configs,
              opset=onnx_config.DEFAULT_ONNX_OPSET,
              output_dir=Path(tmpdirname),
              device=device,
              model_kwargs=model_kwargs,
          )
          input_shapes_iterator = grid_parameters(
              shapes_to_validate, yield_dict=True, add_test_name=False
          )
          for input_shapes in input_shapes_iterator:
              skip = False
              for _, model_onnx_conf in models_and_onnx_configs.items():
                  if (
                      hasattr(
                          model_onnx_conf[0].config,
                          "max_position_embeddings",
                      )
                      and input_shapes["sequence_length"]
                      >= model_onnx_conf[
                          0
                      ].config.max_position_embeddings
                  ):
                      skip = True
                      break
                  if (
                      model_type == "groupvit"
                      and input_shapes["sequence_length"]
                      >= model_onnx_conf[
                          0
                      ].config.text_config.max_position_embeddings
                  ):
                      skip = True
                      break
              if skip:
                  continue
  
              try:
                  validate_models_outputs(
                      models_and_onnx_configs=models_and_onnx_configs,
                      onnx_named_outputs=onnx_outputs,
                      atol=atol,
                      output_dir=Path(tmpdirname),
                      input_shapes=input_shapes,
                      device=device,
                      model_kwargs=model_kwargs,
                  )
              except AtolError as e:
                  print(
                      f"The ONNX export succeeded with the warning: {e}"
                  )
  
              gc.collect()
  
imports: import gc
  import os
  from functools import partial
  from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import Dict
  from unittest import TestCase
  import onnx
  import pytest
  from parameterized import parameterized
  from transformers import AutoConfig, is_tf_available, is_torch_available
  from transformers.testing_utils import require_onnx, require_tf, require_torch, require_torch_gpu, require_vision, slow
  from optimum.exporters.error_utils import AtolError
  from optimum.exporters.onnx import OnnxConfig, OnnxConfigWithPast, export_models, get_decoder_models_for_export, get_encoder_decoder_models_for_export, get_stable_diffusion_models_for_export, validate_models_outputs
  from optimum.exporters.onnx.__main__ import main_export
  from optimum.exporters.onnx.base import ConfigBehavior
  from optimum.exporters.onnx.config import TextDecoderOnnxConfig
  from optimum.exporters.onnx.model_configs import WhisperOnnxConfig
  from optimum.exporters.onnx.utils import get_speecht5_models_for_export
  from optimum.utils import ONNX_WEIGHTS_NAME, DummyPastKeyValuesGenerator, NormalizedTextConfig
  from optimum.utils.testing_utils import grid_parameters, require_diffusers
  from ..exporters_utils import PYTORCH_EXPORT_MODELS_TINY, PYTORCH_SENTENCE_TRANSFORMERS_MODEL, PYTORCH_STABLE_DIFFUSION_MODEL, PYTORCH_TIMM_MODEL, TENSORFLOW_EXPORT_MODELS, VALIDATE_EXPORT_ON_SHAPES_SLOW
label_desc: Use image node_id 1 for calling the OnnxExportTestCase obj's underlying member method code with example usage: obj._onnx_export(test_name, model_type, model_name, task, onnx_config_class_constructor, shapes_to_validate, monolith, device) without return types