class_docstr: Handles the ONNX Runtime quantization process for models shared on huggingface.co/models.
class_docstr_tok: ["Handles","the","ONNX","Runtime","quantization","process","for","models","shared","on","huggingface.co\/models","."]
docstr: Instantiates a `ORTQuantizer` from an ONNX model file or an `ORTModel`.
  
  Args:
      model_or_path (`Union[ORTModel, str, Path]`):
          Can be either:
              - A path to a saved exported ONNX Intermediate Representation (IR) model, e.g., `./my_model_directory/.
              - Or an `ORTModelForXX` class, e.g., `ORTModelForQuestionAnswering`.
      file_name(`Optional[str]`, defaults to `None`):
          Overwrites the default model file name from `"model.onnx"` to `file_name`.
          This allows you to load different model files from the same repository or directory.
  Returns:
      An instance of `ORTQuantizer`.
docstr_tok: ["Instantiates","a","`","ORTQuantizer","`","from","an","ONNX","model","file","or","an","`","ORTModel","`",".","Args",":","model_or_path","(","`","Union","[","ORTModel",",","str",",","Path","]","`",")",":","Can","be","either",":","-","A","path","to","a","saved","exported","ONNX","Intermediate","Representation","(","IR",")","model",",","e.g.",",","`",".\/my_model_directory\/",".","-","Or","an","`","ORTModelForXX","`","class",",","e.g.",",","`","ORTModelForQuestionAnswering","`",".","file_name","(","`","Optional","[","str","]","`",",","defaults","to","`","None","`",")",":","Overwrites","the","default","model","file","name","from","`","``","model.onnx","''","`","to","`","file_name","`",".","This","allows","you","to","load","different","model","files","from","the","same","repository","or","directory",".","Returns",":","An","instance","of","`","ORTQuantizer","`","."]
code: def from_pretrained(
      cls,
      model_or_path: Union["ORTModel", str, Path],
      file_name: Optional[str] = None,
  ) -> "ORTQuantizer":
      """
      Instantiates a `ORTQuantizer` from an ONNX model file or an `ORTModel`.
  
      Args:
          model_or_path (`Union[ORTModel, str, Path]`):
              Can be either:
                  - A path to a saved exported ONNX Intermediate Representation (IR) model, e.g., `./my_model_directory/.
                  - Or an `ORTModelForXX` class, e.g., `ORTModelForQuestionAnswering`.
          file_name(`Optional[str]`, defaults to `None`):
              Overwrites the default model file name from `"model.onnx"` to `file_name`.
              This allows you to load different model files from the same repository or directory.
      Returns:
          An instance of `ORTQuantizer`.
      """
      ort_quantizer_error_message = "ORTQuantizer does not support multi-file quantization. Please create separate ORTQuantizer instances for each model/file, by passing the argument `file_name` to ORTQuantizer.from_pretrained()."
  
      if isinstance(model_or_path, str):
          model_or_path = Path(model_or_path)
  
      path = None
      if isinstance(model_or_path, ORTModelForConditionalGeneration):
          raise NotImplementedError(ort_quantizer_error_message)
      elif isinstance(model_or_path, Path) and file_name is None:
          onnx_files = list(model_or_path.glob("*.onnx"))
          if len(onnx_files) == 0:
              raise FileNotFoundError(
                  f"Could not find any ONNX model file in {model_or_path}"
              )
          elif len(onnx_files) > 1:
              raise RuntimeError(
                  f"Found too many ONNX model files in {model_or_path}. {ort_quantizer_error_message}"
              )
          file_name = onnx_files[0].name
  
      if isinstance(model_or_path, ORTModel):
          if path is None:
              path = Path(model_or_path.model._model_path)
      elif os.path.isdir(model_or_path):
          path = Path(model_or_path) / file_name
      else:
          raise ValueError(
              f"Unable to load model from {model_or_path}."
          )
      return cls(path)
  
imports: import logging
  import os
  from collections import defaultdict
  from pathlib import Path
  from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple, Union
  import onnx
  from datasets import Dataset, load_dataset
  from packaging.version import Version, parse
  from transformers import AutoConfig
  from onnxruntime import __version__
  from onnxruntime.quantization import CalibrationDataReader, QuantFormat, QuantizationMode, QuantType
  from onnxruntime.quantization.onnx_quantizer import ONNXQuantizer
  from onnxruntime.quantization.qdq_quantizer import QDQQuantizer
  from ..quantization_base import OptimumQuantizer
  from ..utils.save_utils import maybe_save_preprocessors
  from .None import ORTQuantizableOperator
  from .configuration import CalibrationConfig, ORTConfig, QuantizationConfig
  from .modeling_ort import ORTModel
  from .modeling_seq2seq import ORTModelForConditionalGeneration
  from .preprocessors import QuantizationPreprocessor
label_desc: Use image node_id 2 for calling the ORTQuantizer obj's underlying member method code with example usage: obj.from_pretrained(cls, model_or_path, file_name) and returns: cls