





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


__UpperCAmelCase	:       Optional[int]    	=							logging.get_logger(__name__)

__UpperCAmelCase	:       List[str]    	=							{
    "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    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					"""gpt_neo"""
       lowerCAmelCase__						=					["""past_key_values"""]
       lowerCAmelCase__						=					{"""num_attention_heads""": """num_heads""", """num_hidden_layers""": """num_layers"""}




       def __init__(  self			:   List[str]							,    A			:   Tuple=50_257							,    A			:   Union[str, Any]=2_048							,    A			:   Dict=2_048							,    A			:   int=24							,    A			:   Optional[int]=[[["global", "local"], 12]]							,    A			:   Optional[int]=16							,    A			:   str=None							,    A			:   Union[str, Any]=256							,    A			:   List[Any]="gelu_new"							,    A			:   Dict=0.0							,    A			:   int=0.0							,    A			:   Any=0.0							,    A			:   int=0.1							,    A			:   int=1E-5							,    A			:   Optional[int]=0.02							,    A			:   Union[str, Any]=True							,    A			:   str=50_256							,    A			:   Any=50_256							,    **A			:   str							,    ):
         __snake_case:						Optional[Any]			  =						vocab_size
         __snake_case:						Union[str, Any]			  =						max_position_embeddings
         __snake_case:						List[Any]			  =						hidden_size
         __snake_case:						Dict			  =						num_layers
         __snake_case:						Optional[int]			  =						num_heads
         __snake_case:						Tuple			  =						intermediate_size
         __snake_case:						List[Any]			  =						window_size
         __snake_case:						Optional[Any]			  =						activation_function
         __snake_case:						List[Any]			  =						resid_dropout
         __snake_case:						Any			  =						embed_dropout
         __snake_case:						str			  =						attention_dropout
         __snake_case:						int			  =						classifier_dropout
         __snake_case:						Any			  =						layer_norm_epsilon
         __snake_case:						List[str]			  =						initializer_range
         __snake_case:						int			  =						use_cache

         __snake_case:						Dict			  =						bos_token_id
         __snake_case:						Dict			  =						eos_token_id

         __snake_case:						Tuple			  =						attention_types
         __snake_case:						Optional[int]			  =						self.expand_attention_types_params(A		)

         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=A							,    eos_token_id=A							,    **A		)






       @staticmethod
       def 							UpperCAmelCase__			(  A			:   Union[str, Any]		):
         __snake_case:						Optional[Any]			  =						[]
         for item in attention_types:
           for _ in range(item[1]		):
             attentions.extend(item[0]		)
         return attentions







def       A__							(   SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)       ->   str:
  import torch

  __snake_case:						List[Any]			  =						input.size()
  __snake_case:						Dict			  =						len(lowercase__)
  __snake_case:						Optional[Any]			  =						shape[dimension]

  __snake_case:						int			  =						torch.arange(0 , lowercase__ , lowercase__)
  __snake_case:						Dict			  =						torch.div(sizedim - size , lowercase__ , rounding_mode="""floor""") + 1
  __snake_case:						Dict			  =						torch.arange(lowercase__) + low_indices[:min_length][:, None]

  __snake_case:						Dict			  =						[slice(lowercase__)] * rank
  __snake_case:						str			  =						indices
  __snake_case:						Optional[Any]			  =						input[s]

  __snake_case:						str			  =						list(range(0 , rank + 1))
  perm.append(perm.pop(dimension + 1))

  return sliced.permute(lowercase__)







def       A__							(   SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)       ->   Any:
  import torch

  __snake_case:						Optional[Any]			  =						torch.arange(1 , lowercase__)
  __snake_case:						List[str]			  =						torch.remainder(lowercase__ , lowercase__)
  __snake_case:						Optional[Any]			  =						remainders == 0
  __snake_case:						Union[str, Any]			  =						candidates[divisor_indices]
  __snake_case:						List[str]			  =						torch.max(lowercase__)
  return largest_divisor, torch.div(lowercase__ , lowercase__ , rounding_mode="""floor""")







class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       @property
       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         __snake_case:						List[str]			  =						OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}		)
         if self.use_past:
           self.fill_with_past_key_values_(A							,    direction="""inputs"""		)
           __snake_case:						Union[str, Any]			  =						{0: 'batch', 1: 'past_sequence + sequence'}
         else:
           __snake_case:						Dict			  =						{0: 'batch', 1: 'sequence'}

         return common_inputs




       @property
       def 							UpperCAmelCase__			(  self			:   Any		):
         return self._config.num_heads




       def 							UpperCAmelCase__			(  self			:   Tuple							,    A			:   int							,    A			:   List[str] = -1							,    A			:   Union[str, Any] = -1							,    A			:   str = False							,    A			:   Dict = None							,    ):
         __snake_case:						Dict			  =						super(A							,    self		).generate_dummy_inputs(
             A							,    batch_size=A							,    seq_length=A							,    is_pair=A							,    framework=A		)

         # We need to order the input in the way they appears in the forward()
         __snake_case:						Optional[int]			  =						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

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

         __snake_case:						int			  =						common_inputs['attention_mask']
         if self.use_past:
           __snake_case:						int			  =						ordered_inputs['attention_mask'].dtype
           __snake_case:						int			  =						torch.cat(
               [ordered_inputs["""attention_mask"""], torch.ones(A							,    A							,    dtype=A		)]							,    dim=1		)

         return ordered_inputs






       @property
       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         return 13













import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

__UpperCAmelCase	:       Union[str, Any]    	=							{
    "asapp/sew-d-tiny-100k": "https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}







class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					"""sew-d"""




       def __init__(  self			:   Dict							,    A			:   Any=32							,    A			:   Dict=768							,    A			:   Optional[Any]=12							,    A			:   Union[str, Any]=12							,    A			:   Union[str, Any]=3_072							,    A			:   Optional[Any]=2							,    A			:   Union[str, Any]=512							,    A			:   List[Any]=256							,    A			:   Dict=True							,    A			:   Union[str, Any]=True							,    A			:   Optional[int]=("p2c", "c2p")							,    A			:   str="layer_norm"							,    A			:   Dict="gelu_python"							,    A			:   Tuple=0.1							,    A			:   Any=0.1							,    A			:   Tuple=0.1							,    A			:   Optional[int]=0.0							,    A			:   Any=0.1							,    A			:   Any=0.02							,    A			:   Dict=1E-7							,    A			:   str=1E-5							,    A			:   int="group"							,    A			:   int="gelu"							,    A			:   str=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)							,    A			:   Union[str, Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)							,    A			:   List[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)							,    A			:   Optional[int]=False							,    A			:   int=128							,    A			:   int=16							,    A			:   Optional[Any]=True							,    A			:   List[Any]=0.05							,    A			:   Any=10							,    A			:   Dict=2							,    A			:   List[Any]=0.0							,    A			:   Union[str, Any]=10							,    A			:   int=0							,    A			:   List[Any]="mean"							,    A			:   Union[str, Any]=False							,    A			:   Any=False							,    A			:   Optional[int]=256							,    A			:   List[Any]=0							,    A			:   Any=1							,    A			:   List[Any]=2							,    **A			:   List[Any]							,    ):
         super().__init__(**A							,    pad_token_id=A							,    bos_token_id=A							,    eos_token_id=A		)
         __snake_case:						Optional[int]			  =						hidden_size
         __snake_case:						str			  =						feat_extract_norm
         __snake_case:						int			  =						feat_extract_activation
         __snake_case:						str			  =						list(A		)
         __snake_case:						Any			  =						list(A		)
         __snake_case:						str			  =						list(A		)
         __snake_case:						Union[str, Any]			  =						conv_bias
         __snake_case:						int			  =						num_conv_pos_embeddings
         __snake_case:						str			  =						num_conv_pos_embedding_groups
         __snake_case:						List[Any]			  =						len(self.conv_dim		)
         __snake_case:						List[str]			  =						num_hidden_layers
         __snake_case:						Union[str, Any]			  =						intermediate_size
         __snake_case:						Dict			  =						squeeze_factor
         __snake_case:						List[Any]			  =						max_position_embeddings
         __snake_case:						List[Any]			  =						position_buckets
         __snake_case:						List[str]			  =						share_att_key
         __snake_case:						int			  =						relative_attention
         __snake_case:						Union[str, Any]			  =						norm_rel_ebd
         __snake_case:						List[str]			  =						list(A		)
         __snake_case:						Tuple			  =						hidden_act
         __snake_case:						List[Any]			  =						num_attention_heads
         __snake_case:						str			  =						hidden_dropout
         __snake_case:						int			  =						attention_dropout
         __snake_case:						Dict			  =						activation_dropout
         __snake_case:						Any			  =						feat_proj_dropout
         __snake_case:						int			  =						final_dropout
         __snake_case:						List[Any]			  =						layer_norm_eps
         __snake_case:						List[str]			  =						feature_layer_norm_eps
         __snake_case:						List[Any]			  =						initializer_range
         __snake_case:						List[Any]			  =						vocab_size

         if (
             (len(self.conv_stride		) != self.num_feat_extract_layers)
             or (len(self.conv_kernel		) != self.num_feat_extract_layers)
             or (len(self.conv_dim		) != self.num_feat_extract_layers)
         ):
           raise ValueError(
               """Configuration for convolutional layers is incorrect."""
               """It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"""
               f'''but is `len(config.conv_dim) = {len(self.conv_dim		)}`, `len(config.conv_stride)'''
               f'''= {len(self.conv_stride		)}`, `len(config.conv_kernel) = {len(self.conv_kernel		)}`.'''		)

         # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
         __snake_case:						List[Any]			  =						apply_spec_augment
         __snake_case:						List[Any]			  =						mask_time_prob
         __snake_case:						str			  =						mask_time_length
         __snake_case:						List[str]			  =						mask_time_min_masks
         __snake_case:						str			  =						mask_feature_prob
         __snake_case:						Optional[int]			  =						mask_feature_length
         __snake_case:						Dict			  =						mask_feature_min_masks

         # ctc loss
         __snake_case:						Any			  =						ctc_loss_reduction
         __snake_case:						str			  =						ctc_zero_infinity

         # sequence classification
         __snake_case:						Optional[Any]			  =						use_weighted_layer_sum
         __snake_case:						List[Any]			  =						classifier_proj_size






       @property
       def 							UpperCAmelCase__			(  self			:   int		):
         return functools.reduce(operator.mul							,    self.conv_stride							,    1		)






