class_docstr: Handles the ONNX Runtime optimization process for models shared on huggingface.co/models.
class_docstr_tok: ["Handles","the","ONNX","Runtime","optimization","process","for","models","shared","on","huggingface.co\/models","."]
docstr: Args:
      model_or_path (`Union[str, os.PathLike, ORTModel]`):
          The path to a local directory hosting the model to optimize or an instance of an `ORTModel` to quantize.
          Can be either:
              - A path to a local *directory* containing the model to optimize.
              - An instance of [`~optimum.onnxruntime.ORTModel`].
      file_names(`Optional[List[str]]`, defaults to `None`):
          The list of file names of the models to optimize.
docstr_tok: ["Args",":","model_or_path","(","`","Union","[","str",",","os.PathLike",",","ORTModel","]","`",")",":","The","path","to","a","local","directory","hosting","the","model","to","optimize","or","an","instance","of","an","`","ORTModel","`","to","quantize",".","Can","be","either",":","-","A","path","to","a","local","*","directory","*","containing","the","model","to","optimize",".","-","An","instance","of","[","`","~optimum.onnxruntime.ORTModel","`","]",".","file_names","(","`","Optional","[","List","[","str","]","]","`",",","defaults","to","`","None","`",")",":","The","list","of","file","names","of","the","models","to","optimize","."]
code: def from_pretrained(
      cls,
      model_or_path: Union[str, os.PathLike, ORTModel],
      file_names: Optional[List[str]] = None,
  ) -> "ORTOptimizer":
      """
      Args:
          model_or_path (`Union[str, os.PathLike, ORTModel]`):
              The path to a local directory hosting the model to optimize or an instance of an `ORTModel` to quantize.
              Can be either:
                  - A path to a local *directory* containing the model to optimize.
                  - An instance of [`~optimum.onnxruntime.ORTModel`].
          file_names(`Optional[List[str]]`, defaults to `None`):
              The list of file names of the models to optimize.
      """
      onnx_model_path = []
      config = None
      if isinstance(model_or_path, ORTModel):
          from_ortmodel = True
          if isinstance(
              model_or_path, ORTModelForConditionalGeneration
          ):
              onnx_model_path += [
                  model_or_path.encoder_model_path,
                  model_or_path.decoder_model_path,
              ]
              # Add the decoder with past key/values if present
              if model_or_path.use_cache:
                  onnx_model_path.append(
                      model_or_path.decoder_with_past_model_path
                  )
          elif (
              isinstance(model_or_path, ORTModelForCausalLM)
              and model_or_path.use_merged
          ):
              raise NotImplementedError(
                  "ORTOptimizer does not support ORTModelForCausalLM models when without/with past models are merged. "
                  "Please re-export your model. This can be done by using the optimum-cli ONNX export tool or `ORTModelForCausalLM.from_pretrained(..., export=True, use_merged=False)`."
              )
          else:
              onnx_model_path.append(model_or_path.model_path)
          config = model_or_path.config
      elif os.path.isdir(model_or_path):
          from_ortmodel = False
          file_names = (
              [ONNX_WEIGHTS_NAME] if file_names is None else file_names
          )
          model_or_path = Path(model_or_path)
          if CONFIG_NAME not in os.listdir(model_or_path):
              raise ValueError(
                  f"The local directory does not contain the configuration file {CONFIG_NAME}."
              )
          config = AutoConfig.from_pretrained(model_or_path)
          for file_name in file_names:
              onnx_model_path.append(model_or_path.joinpath(file_name))
      else:
          raise ValueError(
              f"Unable to load the model from {model_or_path}."
          )
      return cls(
          onnx_model_path, config=config, from_ortmodel=from_ortmodel
      )
  
imports: import gc
  import os
  from pathlib import Path
  from typing import TYPE_CHECKING, Dict, List, Optional, Union
  import onnx
  from onnx import load_model
  from transformers.models.auto.configuration_auto import AutoConfig
  from onnxruntime.transformers.onnx_model_bert import BertOnnxModel
  from onnxruntime.transformers.optimizer import optimize_model
  from ..onnx.utils import check_model_uses_external_data
  from ..utils import CONFIG_NAME, NormalizedConfigManager, logging
  from ..utils.save_utils import maybe_save_preprocessors
  from .configuration import OptimizationConfig, ORTConfig
  from .modeling_decoder import ORTModelForCausalLM
  from .modeling_ort import ORTModel
  from .modeling_seq2seq import ORTModelForConditionalGeneration
  from .utils import ONNX_WEIGHTS_NAME, ORTConfigManager
label_desc: Use image node_id 2 for calling the ORTOptimizer obj's underlying member method code with example usage: obj.from_pretrained(cls, model_or_path, file_names) and returns: cls