


'''simple docstring'''



from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast
from ...utils import logging


A__						:   Dict				=    logging.get_logger(__name__)

A__						:   Union[str, Any]				=    {
    """EleutherAI/gpt-neo-1.3B""": """https://huggingface.co/EleutherAI/gpt-neo-1.3B/resolve/main/config.json""",
    # See all GPTNeo models at https://huggingface.co/models?filter=gpt_neo
}





class   UpperCAmelCase_    (_UpperCAmelCase    ):





    """simple docstring"""






    lowerCamelCase    :   str					=     'gpt_neo'
    lowerCamelCase    :   str					=     ['past_key_values']
    lowerCamelCase    :   Optional[int]					=     {'num_attention_heads': 'num_heads', 'num_hidden_layers': 'num_layers'}







    def __init__(				self     ,	SCREAMING_SNAKE_CASE_=5_02_57     ,	SCREAMING_SNAKE_CASE_=20_48     ,	SCREAMING_SNAKE_CASE_=20_48     ,	SCREAMING_SNAKE_CASE_=24     ,	SCREAMING_SNAKE_CASE_=[[["global", "local"], 12]]     ,	SCREAMING_SNAKE_CASE_=16     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=2_56     ,	SCREAMING_SNAKE_CASE_="gelu_new"     ,	SCREAMING_SNAKE_CASE_=0.0     ,	SCREAMING_SNAKE_CASE_=0.0     ,	SCREAMING_SNAKE_CASE_=0.0     ,	SCREAMING_SNAKE_CASE_=0.1     ,	SCREAMING_SNAKE_CASE_=1E-5     ,	SCREAMING_SNAKE_CASE_=0.0_2     ,	SCREAMING_SNAKE_CASE_=True     ,	SCREAMING_SNAKE_CASE_=5_02_56     ,	SCREAMING_SNAKE_CASE_=5_02_56     ,	**SCREAMING_SNAKE_CASE_     ,	)							->	Any:
         __lowerCamelCase  :      List[Any]														=						vocab_size
         __lowerCamelCase  :      Union[str, Any]														=						max_position_embeddings
         __lowerCamelCase  :      Union[str, Any]														=						hidden_size
         __lowerCamelCase  :      List[Any]														=						num_layers
         __lowerCamelCase  :      Optional[Any]														=						num_heads
         __lowerCamelCase  :      int														=						intermediate_size
         __lowerCamelCase  :      int														=						window_size
         __lowerCamelCase  :      Optional[Any]														=						activation_function
         __lowerCamelCase  :      List[str]														=						resid_dropout
         __lowerCamelCase  :      Any														=						embed_dropout
         __lowerCamelCase  :      Union[str, Any]														=						attention_dropout
         __lowerCamelCase  :      Union[str, Any]														=						classifier_dropout
         __lowerCamelCase  :      Optional[int]														=						layer_norm_epsilon
         __lowerCamelCase  :      int														=						initializer_range
         __lowerCamelCase  :      Union[str, Any]														=						use_cache

         __lowerCamelCase  :      Dict														=						bos_token_id
         __lowerCamelCase  :      List[Any]														=						eos_token_id

         __lowerCamelCase  :      List[str]														=						attention_types
         __lowerCamelCase  :      Dict														=						self.expand_attention_types_params(SCREAMING_SNAKE_CASE_      )

         if len(self.attention_layers      ) != self.num_layers:
              raise ValueError(
                  'Configuration for convolutional module is incorrect. '
                  'It is required that `len(config.attention_layers)` == `config.num_layers` '
                  f'but is `len(config.attention_layers) = {len(self.attention_layers      )}`, '
                  f'`config.num_layers = {self.num_layers}`. '
                  '`config.attention_layers` is prepared using `config.attention_types`. '
                  'Please verify the value of `config.attention_types` argument.'      )

         super().__init__(bos_token_id=SCREAMING_SNAKE_CASE_     ,	eos_token_id=SCREAMING_SNAKE_CASE_     ,	**SCREAMING_SNAKE_CASE_      )







    @staticmethod
    def  lowercase_							(				SCREAMING_SNAKE_CASE_      )							->	int:
         __lowerCamelCase  :      Dict														=						[]
         for item in attention_types:
              for _ in range(item[1]      ):
                   attentions.extend(item[0]      )
         return attentions







def      UpperCAmelCase__   (      UpperCAmelCase_       :							Tuple ,       UpperCAmelCase_       :							List[str] ,       UpperCAmelCase_       :							Optional[int] ,       UpperCAmelCase_       :							Union[str, Any]				)	->						Union[str, Any]:
     import torch

     __lowerCamelCase  :      Optional[Any]														=						input.size()
     __lowerCamelCase  :      Dict														=						len(UpperCAmelCase_				)
     __lowerCamelCase  :      Any														=						shape[dimension]

     __lowerCamelCase  :      Tuple														=						torch.arange(0 ,       UpperCAmelCase_ ,       UpperCAmelCase_				)
     __lowerCamelCase  :      Union[str, Any]														=						torch.div(sizedim - size ,       UpperCAmelCase_ ,       rounding_mode='floor'				) + 1
     __lowerCamelCase  :      int														=						torch.arange(UpperCAmelCase_				) + low_indices[:min_length][:, None]

     __lowerCamelCase  :      Tuple														=						[slice(UpperCAmelCase_				)] * rank
     __lowerCamelCase  :      Union[str, Any]														=						indices
     __lowerCamelCase  :      Optional[int]														=						input[s]

     __lowerCamelCase  :      Optional[Any]														=						list(range(0 ,       rank + 1				)				)
     perm.append(perm.pop(dimension + 1				)				)

     return sliced.permute(UpperCAmelCase_				)



def      UpperCAmelCase__   (      UpperCAmelCase_       :							List[Any] ,       UpperCAmelCase_       :							int				)	->						Dict:
     import torch

     __lowerCamelCase  :      Optional[Any]														=						torch.arange(1 ,       UpperCAmelCase_				)
     __lowerCamelCase  :      List[Any]														=						torch.remainder(UpperCAmelCase_ ,       UpperCAmelCase_				)
     __lowerCamelCase  :      List[Any]														=						remainders == 0
     __lowerCamelCase  :      Dict														=						candidates[divisor_indices]
     __lowerCamelCase  :      Dict														=						torch.max(UpperCAmelCase_				)
     return largest_divisor, torch.div(UpperCAmelCase_ ,       UpperCAmelCase_ ,       rounding_mode='floor'				)





class   UpperCAmelCase_    (_UpperCAmelCase    ):





    """simple docstring"""






    @property
    def  lowercase_							(				self      )							->	Mapping[str, Mapping[int, str]]:
         __lowerCamelCase  :      List[Any]														=						OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}      )
         if self.use_past:
              self.fill_with_past_key_values_(SCREAMING_SNAKE_CASE_     ,	direction='inputs'      )
              __lowerCamelCase  :      Optional[int]														=						{0: 'batch', 1: 'past_sequence + sequence'}
         else:
              __lowerCamelCase  :      Any														=						{0: 'batch', 1: 'sequence'}

         return common_inputs







    @property
    def  lowercase_							(				self      )							->	int:
         return self._config.num_heads







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_ = -1     ,	SCREAMING_SNAKE_CASE_ = -1     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = None     ,	)							->	Mapping[str, Any]:
         __lowerCamelCase  :      List[Any]														=						super(SCREAMING_SNAKE_CASE_     ,	self      ).generate_dummy_inputs(
             SCREAMING_SNAKE_CASE_     ,	batch_size=SCREAMING_SNAKE_CASE_     ,	seq_length=SCREAMING_SNAKE_CASE_     ,	is_pair=SCREAMING_SNAKE_CASE_     ,	framework=SCREAMING_SNAKE_CASE_      )

         # We need to order the input in the way they appears in the forward()
         __lowerCamelCase  :      str														=						OrderedDict({'input_ids': common_inputs['input_ids']}      )

         # Need to add the past_keys
         if self.use_past:
              if not is_torch_available():
                   raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'      )
              else:
                   import torch

                   __lowerCamelCase							,			__lowerCamelCase  :      Any														=						common_inputs['input_ids'].shape
                   # Not using the same length for past_key_values
                   __lowerCamelCase  :      Optional[int]														=						seqlen + 2
                   __lowerCamelCase  :      Tuple														=						(
                       batch,
                       self.num_attention_heads,
                       past_key_values_length,
                       self._config.hidden_size // self.num_attention_heads,
                   )
                   __lowerCamelCase  :      List[Any]														=						[
                       (torch.zeros(SCREAMING_SNAKE_CASE_      ), torch.zeros(SCREAMING_SNAKE_CASE_      )) for _ in range(self.num_layers      )
                   ]

         __lowerCamelCase  :      List[Any]														=						common_inputs['attention_mask']
         if self.use_past:
              __lowerCamelCase  :      Any														=						ordered_inputs['attention_mask'].dtype
              __lowerCamelCase  :      Union[str, Any]														=						torch.cat(
                  [ordered_inputs['attention_mask'], torch.ones(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	dtype=SCREAMING_SNAKE_CASE_      )]     ,	dim=1      )

         return ordered_inputs







    @property
    def  lowercase_							(				self      )							->	int:
         return 13














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,
)


lowerCamelCase      :       Optional[Any]    =						logging.get_logger(__name__)

lowerCamelCase      :       Any    =						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'''),
    ]
)

lowerCamelCase      :       Optional[int]    =						_LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)





def    __lowerCAmelCase   (    __snake_case							):
     for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
          if class_name in extractors:
               __lowerCAmelCase             =       model_type_to_module_name(__snake_case							)

               __lowerCAmelCase             =       importlib.import_module(F""".{module_name}"""       ,			"transformers.models"							)
               try:
                    return getattr(__snake_case       ,			__snake_case							)
               except AttributeError:
                    continue

     for _, extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.items():
          if getattr(__snake_case       ,			"__name__"       ,			__snake_case							) == 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.
     __lowerCAmelCase             =       importlib.import_module("transformers"							)
     if hasattr(__snake_case       ,			__snake_case							):
          return getattr(__snake_case       ,			__snake_case							)

     return None





def    __lowerCAmelCase   (    __snake_case       ,			__snake_case = None       ,			__snake_case = False       ,			__snake_case = False       ,			__snake_case = None       ,			__snake_case = None       ,			__snake_case = None       ,			__snake_case = False       ,			**__snake_case       ,			):
     __lowerCAmelCase             =       get_file_from_repo(
         __snake_case       ,			__snake_case       ,			cache_dir=__snake_case       ,			force_download=__snake_case       ,			resume_download=__snake_case       ,			proxies=__snake_case       ,			use_auth_token=__snake_case       ,			revision=__snake_case       ,			local_files_only=__snake_case       ,			)
     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(__snake_case       ,			encoding="utf-8"							) as reader:
          return json.load(__snake_case							)



class 				_UpperCamelCase      :


      def __init__(						self						)->						Union[str, Any]:
           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(__UpperCamelCase						)
      def 			__UpperCAmelCase		(						cls       ,    __UpperCamelCase       ,    **__UpperCamelCase						)->						Optional[int]:
           __lowerCAmelCase             =       kwargs.pop("config"       ,    __UpperCamelCase						)
           __lowerCAmelCase             =       kwargs.pop("trust_remote_code"       ,    __UpperCamelCase						)
           __lowerCAmelCase             =       True

           __lowerCAmelCase      ,			__lowerCAmelCase             =       FeatureExtractionMixin.get_feature_extractor_dict(__UpperCamelCase       ,    **__UpperCamelCase						)
           __lowerCAmelCase             =       config_dict.get("feature_extractor_type"       ,    __UpperCamelCase						)
           __lowerCAmelCase             =       None
           if "AutoFeatureExtractor" in config_dict.get("auto_map"       ,    {}						):
                __lowerCAmelCase             =       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(__UpperCamelCase       ,    __UpperCamelCase						):
                     __lowerCAmelCase             =       AutoConfig.from_pretrained(__UpperCamelCase       ,    **__UpperCamelCase						)
                # It could be in `config.feature_extractor_type``
                __lowerCAmelCase             =       getattr(__UpperCamelCase       ,    "feature_extractor_type"       ,    __UpperCamelCase						)
                if hasattr(__UpperCamelCase       ,    "auto_map"						) and "AutoFeatureExtractor" in config.auto_map:
                     __lowerCAmelCase             =       config.auto_map["AutoFeatureExtractor"]

           if feature_extractor_class is not None:
                __lowerCAmelCase             =       feature_extractor_class_from_name(__UpperCamelCase						)

           __lowerCAmelCase             =       feature_extractor_auto_map is not None
           __lowerCAmelCase             =       feature_extractor_class is not None or type(__UpperCamelCase						) in FEATURE_EXTRACTOR_MAPPING
           __lowerCAmelCase             =       resolve_trust_remote_code(
               __UpperCamelCase       ,    __UpperCamelCase       ,    __UpperCamelCase       ,    __UpperCamelCase						)

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

           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 			__UpperCAmelCase		(						__UpperCamelCase       ,    __UpperCamelCase						)->						Optional[int]:
           FEATURE_EXTRACTOR_MAPPING.register(__UpperCamelCase       ,    __UpperCamelCase						)






