



'''simple docstring'''





import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# Build the list of all feature extractors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...feature_extraction_utils import FeatureExtractionMixin
from ...utils import CONFIG_NAME, FEATURE_EXTRACTOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)


lowercase_		       =  logging.get_logger(__name__)

lowercase_		       =  OrderedDict(
    [
        ("audio-spectrogram-transformer", "ASTFeatureExtractor"),
        ("beit", "BeitFeatureExtractor"),
        ("chinese_clip", "ChineseCLIPFeatureExtractor"),
        ("clap", "ClapFeatureExtractor"),
        ("clip", "CLIPFeatureExtractor"),
        ("clipseg", "ViTFeatureExtractor"),
        ("conditional_detr", "ConditionalDetrFeatureExtractor"),
        ("convnext", "ConvNextFeatureExtractor"),
        ("cvt", "ConvNextFeatureExtractor"),
        ("data2vec-audio", "Wav2Vec2FeatureExtractor"),
        ("data2vec-vision", "BeitFeatureExtractor"),
        ("deformable_detr", "DeformableDetrFeatureExtractor"),
        ("deit", "DeiTFeatureExtractor"),
        ("detr", "DetrFeatureExtractor"),
        ("dinat", "ViTFeatureExtractor"),
        ("donut-swin", "DonutFeatureExtractor"),
        ("dpt", "DPTFeatureExtractor"),
        ("encodec", "EncodecFeatureExtractor"),
        ("flava", "FlavaFeatureExtractor"),
        ("glpn", "GLPNFeatureExtractor"),
        ("groupvit", "CLIPFeatureExtractor"),
        ("hubert", "Wav2Vec2FeatureExtractor"),
        ("imagegpt", "ImageGPTFeatureExtractor"),
        ("layoutlmv2", "LayoutLMv2FeatureExtractor"),
        ("layoutlmv3", "LayoutLMv3FeatureExtractor"),
        ("levit", "LevitFeatureExtractor"),
        ("maskformer", "MaskFormerFeatureExtractor"),
        ("mctct", "MCTCTFeatureExtractor"),
        ("mobilenet_v1", "MobileNetV1FeatureExtractor"),
        ("mobilenet_v2", "MobileNetV2FeatureExtractor"),
        ("mobilevit", "MobileViTFeatureExtractor"),
        ("nat", "ViTFeatureExtractor"),
        ("owlvit", "OwlViTFeatureExtractor"),
        ("perceiver", "PerceiverFeatureExtractor"),
        ("poolformer", "PoolFormerFeatureExtractor"),
        ("regnet", "ConvNextFeatureExtractor"),
        ("resnet", "ConvNextFeatureExtractor"),
        ("segformer", "SegformerFeatureExtractor"),
        ("sew", "Wav2Vec2FeatureExtractor"),
        ("sew-d", "Wav2Vec2FeatureExtractor"),
        ("speech_to_text", "Speech2TextFeatureExtractor"),
        ("speecht5", "SpeechT5FeatureExtractor"),
        ("swiftformer", "ViTFeatureExtractor"),
        ("swin", "ViTFeatureExtractor"),
        ("swinv2", "ViTFeatureExtractor"),
        ("table-transformer", "DetrFeatureExtractor"),
        ("timesformer", "VideoMAEFeatureExtractor"),
        ("tvlt", "TvltFeatureExtractor"),
        ("unispeech", "Wav2Vec2FeatureExtractor"),
        ("unispeech-sat", "Wav2Vec2FeatureExtractor"),
        ("van", "ConvNextFeatureExtractor"),
        ("videomae", "VideoMAEFeatureExtractor"),
        ("vilt", "ViltFeatureExtractor"),
        ("vit", "ViTFeatureExtractor"),
        ("vit_mae", "ViTFeatureExtractor"),
        ("vit_msn", "ViTFeatureExtractor"),
        ("wav2vec2", "Wav2Vec2FeatureExtractor"),
        ("wav2vec2-conformer", "Wav2Vec2FeatureExtractor"),
        ("wavlm", "Wav2Vec2FeatureExtractor"),
        ("whisper", "WhisperFeatureExtractor"),
        ("xclip", "CLIPFeatureExtractor"),
        ("yolos", "YolosFeatureExtractor"),
    ]
)

lowercase_		       =  _LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)




def lowerCAmelCase  (__A):



     """simple docstring"""



     for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
          if class_name in extractors:
               _a      =  model_type_to_module_name(__A)

               _a      =  importlib.import_module(F'''.{module_name}'''  ,	'''transformers.models''')
               try:
                    return getattr(__A  ,	__A)
               except AttributeError:
                    continue

     for _, extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.items():
          if getattr(__A  ,	'''__name__'''  ,	__A) == class_name:
               return extractor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
     _a      =  importlib.import_module('''transformers''')
     if hasattr(__A  ,	__A):
          return getattr(__A  ,	__A)

     return None




def lowerCAmelCase  (__A  ,	__A = None  ,	__A = False  ,	__A = False  ,	__A = None  ,	__A = None  ,	__A = None  ,	__A = False  ,	**__A  ,	):



     """simple docstring"""



     _a      =  get_file_from_repo(
         __A  ,	__A  ,	cache_dir=__A  ,	force_download=__A  ,	resume_download=__A  ,	proxies=__A  ,	use_auth_token=__A  ,	revision=__A  ,	local_files_only=__A  ,	)
     if resolved_config_file is None:
          logger.info(
              '''Could not locate the feature extractor configuration file, will try to use the model config instead.''')
          return {}

     with open(__A  ,	encoding='''utf-8''') as reader:
          return json.load(__A)






class __A			:



 '''simple docstring'''







 def __init__(self       )    ->     Optional[Any]:


      """simple docstring"""



      raise EnvironmentError(
          '''AutoFeatureExtractor is designed to be instantiated '''
          '''using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method.'''       )



 @classmethod
 @replace_list_option_in_docstrings(A       )
 def 					a__  (cls ,   A ,   **A       )    ->     List[Any]:


      """simple docstring"""



      _a      =  kwargs.pop('''config''' ,   A       )
      _a      =  kwargs.pop('''trust_remote_code''' ,   A       )
      _a      =  True

      _a  ,    _a      =  FeatureExtractionMixin.get_feature_extractor_dict(A ,   **A       )
      _a      =  config_dict.get('''feature_extractor_type''' ,   A       )
      _a      =  None
      if "AutoFeatureExtractor" in config_dict.get('''auto_map''' ,   {}       ):
           _a      =  config_dict['''auto_map''']['''AutoFeatureExtractor''']

      # If we don't find the feature extractor class in the feature extractor config, let's try the model config.
      if feature_extractor_class is None and feature_extractor_auto_map is None:
           if not isinstance(A ,   A       ):
                _a      =  AutoConfig.from_pretrained(A ,   **A       )
           # It could be in `config.feature_extractor_type``
           _a      =  getattr(A ,   '''feature_extractor_type''' ,   A       )
           if hasattr(A ,   '''auto_map'''       ) and "AutoFeatureExtractor" in config.auto_map:
                _a      =  config.auto_map['''AutoFeatureExtractor''']

      if feature_extractor_class is not None:
           _a      =  feature_extractor_class_from_name(A       )

      _a      =  feature_extractor_auto_map is not None
      _a      =  feature_extractor_class is not None or type(A       ) in FEATURE_EXTRACTOR_MAPPING
      _a      =  resolve_trust_remote_code(
          A ,   A ,   A ,   A       )

      if has_remote_code and trust_remote_code:
           _a      =  get_class_from_dynamic_module(
               A ,   A ,   **A       )
           _a      =  kwargs.pop('''code_revision''' ,   A       )
           if os.path.isdir(A       ):
                feature_extractor_class.register_for_auto_class()
           return feature_extractor_class.from_dict(A ,   **A       )
      elif feature_extractor_class is not None:
           return feature_extractor_class.from_dict(A ,   **A       )
      # Last try: we use the FEATURE_EXTRACTOR_MAPPING.
      elif type(A       ) in FEATURE_EXTRACTOR_MAPPING:
           _a      =  FEATURE_EXTRACTOR_MAPPING[type(A       )]
           return feature_extractor_class.from_dict(A ,   **A       )

      raise ValueError(
          f'''Unrecognized feature extractor in {pretrained_model_name_or_path}. Should have a '''
          f'''`feature_extractor_type` key in its {FEATURE_EXTRACTOR_NAME} of {CONFIG_NAME}, or one of the following '''
          f'''`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in FEATURE_EXTRACTOR_MAPPING_NAMES.keys()       )}'''       )



 @staticmethod
 def 					a__  (A ,   A       )    ->     Any:


      """simple docstring"""



      FEATURE_EXTRACTOR_MAPPING.register(A ,   A       )








'''simple docstring'''





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase_		       =  logging.get_logger(__name__)

lowercase_		       =  {
    "facebook/xmod-base": "https://huggingface.co/facebook/xmod-base/resolve/main/config.json",
    "facebook/xmod-large-prenorm": "https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json",
    "facebook/xmod-base-13-125k": "https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json",
    "facebook/xmod-base-30-125k": "https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json",
    "facebook/xmod-base-30-195k": "https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json",
    "facebook/xmod-base-60-125k": "https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json",
    "facebook/xmod-base-60-265k": "https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json",
    "facebook/xmod-base-75-125k": "https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json",
    "facebook/xmod-base-75-269k": "https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json",
}






class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       Any          =       'xmod'



 def __init__(self ,   A=30_522 ,   A=768 ,   A=12 ,   A=12 ,   A=3_072 ,   A="gelu" ,   A=0.1 ,   A=0.1 ,   A=512 ,   A=2 ,   A=0.02 ,   A=1E-12 ,   A=1 ,   A=0 ,   A=2 ,   A="absolute" ,   A=True ,   A=None ,   A=False ,   A=2 ,   A=False ,   A=True ,   A=True ,   A=("en_XX",) ,   A=None ,   **A ,   )    ->     List[str]:


      """simple docstring"""



      super().__init__(pad_token_id=A ,   bos_token_id=A ,   eos_token_id=A ,   **A       )

      _a      =  vocab_size
      _a      =  hidden_size
      _a      =  num_hidden_layers
      _a      =  num_attention_heads
      _a      =  hidden_act
      _a      =  intermediate_size
      _a      =  hidden_dropout_prob
      _a      =  attention_probs_dropout_prob
      _a      =  max_position_embeddings
      _a      =  type_vocab_size
      _a      =  initializer_range
      _a      =  layer_norm_eps
      _a      =  position_embedding_type
      _a      =  use_cache
      _a      =  classifier_dropout
      _a      =  pre_norm
      _a      =  adapter_reduction_factor
      _a      =  adapter_layer_norm
      _a      =  adapter_reuse_layer_norm
      _a      =  ln_before_adapter
      _a      =  list(A       )
      _a      =  default_language






class __A			(  A						):



 '''simple docstring'''







 @property
 def 					a__  (self       )    ->     Mapping[str, Mapping[int, str]]:


      """simple docstring"""



      if self.task == "multiple-choice":
           _a      =  {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
      else:
           _a      =  {0: '''batch''', 1: '''sequence'''}
      return OrderedDict(
          [
              ('''input_ids''', dynamic_axis),
              ('''attention_mask''', dynamic_axis),
          ]       )



