



"""simple docstring"""





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

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


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

__lowerCAmelCase							:       Tuple          =       {
    '''EleutherAI/gpt-j-6B''': '''https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json''',
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}



class  _lowerCAmelCase     (					SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase      	=							'''gptj'''
		_lowerCamelCase      	=							{
		    '''max_position_embeddings''': '''n_positions''',
		    '''hidden_size''': '''n_embd''',
		    '''num_attention_heads''': '''n_head''',
		    '''num_hidden_layers''': '''n_layer''',
		}





		def __init__(       self				,     _lowercase=5_0_4_0_0				,     _lowercase=2_0_4_8				,     _lowercase=4_0_9_6				,     _lowercase=2_8				,     _lowercase=1_6				,     _lowercase=6_4				,     _lowercase=None				,     _lowercase="gelu_new"				,     _lowercase=0.0				,     _lowercase=0.0				,     _lowercase=0.0				,     _lowercase=1E-5				,     _lowercase=0.02				,     _lowercase=True				,     _lowercase=5_0_2_5_6				,     _lowercase=5_0_2_5_6				,     _lowercase=False				,     **_lowercase				,     )			->    Any:







								'''simple docstring'''

								snake_case_ :			Dict            =      vocab_size
								snake_case_ :			str            =      n_positions
								snake_case_ :			List[str]            =      n_embd
								snake_case_ :			List[str]            =      n_layer
								snake_case_ :			str            =      n_head
								snake_case_ :			List[Any]            =      n_inner
								snake_case_ :			Union[str, Any]            =      rotary_dim
								snake_case_ :			str            =      activation_function
								snake_case_ :			Tuple            =      resid_pdrop
								snake_case_ :			str            =      embd_pdrop
								snake_case_ :			Optional[int]            =      attn_pdrop
								snake_case_ :			Tuple            =      layer_norm_epsilon
								snake_case_ :			Union[str, Any]            =      initializer_range
								snake_case_ :			Dict            =      use_cache

								snake_case_ :			Any            =      bos_token_id
								snake_case_ :			Dict            =      eos_token_id

								super().__init__(
								    bos_token_id=_lowercase				,     eos_token_id=_lowercase				,     tie_word_embeddings=_lowercase				,     **_lowercase )




class  _lowerCAmelCase     (					SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		def __init__(       self				,     _lowercase				,     _lowercase = "default"				,     _lowercase = None				,     _lowercase = False				,     )			->    Optional[int]:







								'''simple docstring'''

								super().__init__(_lowercase				,     task=_lowercase				,     patching_specs=_lowercase				,     use_past=_lowercase )
								if not getattr(self._config				,     """pad_token_id"""				,     _lowercase ):
														# TODO: how to do that better?
														snake_case_ :			Dict            =      0





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







								'''simple docstring'''

								snake_case_ :			Dict            =      OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}} )
								if self.use_past:
														self.fill_with_past_key_values_(_lowercase				,     direction="""inputs""" )
														snake_case_ :			int            =      {0: """batch""", 1: """past_sequence + sequence"""}
								else:
														snake_case_ :			Optional[int]            =      {0: """batch""", 1: """sequence"""}

								return common_inputs





		@property
		def  UpperCAmelCase__				(       self )			->    int:







								'''simple docstring'''

								return self._config.n_layer





		@property
		def  UpperCAmelCase__				(       self )			->    int:







								'''simple docstring'''

								return self._config.n_head





		def  UpperCAmelCase__				(       self				,     _lowercase				,     _lowercase = -1				,     _lowercase = -1				,     _lowercase = False				,     _lowercase = None				,     )			->    Mapping[str, Any]:







								'''simple docstring'''

								snake_case_ :			List[str]            =      super(_lowercase				,     self ).generate_dummy_inputs(
								    _lowercase				,     batch_size=_lowercase				,     seq_length=_lowercase				,     is_pair=_lowercase				,     framework=_lowercase )

								# We need to order the input in the way they appears in the forward()
								snake_case_ :			Optional[Any]            =      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_      ,		snake_case_ :			Dict            =      common_inputs["""input_ids"""].shape
																				# Not using the same length for past_key_values
																				snake_case_ :			List[Any]            =      seqlen + 2
																				snake_case_ :			Dict            =      (
																				    batch,
																				    self.num_attention_heads,
																				    past_key_values_length,
																				    self._config.hidden_size // self.num_attention_heads,
																				)
																				snake_case_ :			str            =      [
																				    (torch.zeros(_lowercase ), torch.zeros(_lowercase )) for _ in range(self.num_layers )
																				]

								snake_case_ :			Dict            =      common_inputs["""attention_mask"""]
								if self.use_past:
														snake_case_ :			List[Any]            =      ordered_inputs["""attention_mask"""].dtype
														snake_case_ :			Union[str, Any]            =      torch.cat(
														    [ordered_inputs["""attention_mask"""], torch.ones(_lowercase				,     _lowercase				,     dtype=_lowercase )]				,     dim=1 )

								return ordered_inputs





		@property
		def  UpperCAmelCase__				(       self )			->    int:







								'''simple docstring'''

								return 1_3





import functools
import operator

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


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

snake_case							:       Optional[int]										=	{
    '''microsoft/unispeech-large-1500h-cv''': (
        '''https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'''
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}







class 						_snake_case    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			'unispeech'




 def __init__(						self   ,    _lowerCamelCase=32   ,    _lowerCamelCase=768   ,    _lowerCamelCase=12   ,    _lowerCamelCase=12   ,    _lowerCamelCase=3072   ,    _lowerCamelCase="gelu"   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.0   ,    _lowerCamelCase=0.0   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.02   ,    _lowerCamelCase=1e-5   ,    _lowerCamelCase="group"   ,    _lowerCamelCase="gelu"   ,    _lowerCamelCase=(512, 512, 512, 512, 512, 512, 512)   ,    _lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)   ,    _lowerCamelCase=(10, 3, 3, 3, 3, 2, 2)   ,    _lowerCamelCase=False   ,    _lowerCamelCase=128   ,    _lowerCamelCase=16   ,    _lowerCamelCase=False   ,    _lowerCamelCase=True   ,    _lowerCamelCase=0.05   ,    _lowerCamelCase=10   ,    _lowerCamelCase=2   ,    _lowerCamelCase=0.0   ,    _lowerCamelCase=10   ,    _lowerCamelCase=0   ,    _lowerCamelCase=320   ,    _lowerCamelCase=2   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=100   ,    _lowerCamelCase=256   ,    _lowerCamelCase=256   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase="mean"   ,    _lowerCamelCase=False   ,    _lowerCamelCase=False   ,    _lowerCamelCase=256   ,    _lowerCamelCase=80   ,    _lowerCamelCase=0   ,    _lowerCamelCase=1   ,    _lowerCamelCase=2   ,    _lowerCamelCase=0.5   ,    **_lowerCamelCase   ,    ):
       super().__init__(**_lowerCamelCase   ,    pad_token_id=_lowerCamelCase   ,    bos_token_id=_lowerCamelCase   ,    eos_token_id=_lowerCamelCase       )
       a		:Any									=			hidden_size
       a		:str									=			feat_extract_norm
       a		:List[Any]									=			feat_extract_activation
       a		:Tuple									=			list(_lowerCamelCase       )
       a		:Any									=			list(_lowerCamelCase       )
       a		:List[Any]									=			list(_lowerCamelCase       )
       a		:Union[str, Any]									=			conv_bias
       a		:str									=			num_conv_pos_embeddings
       a		:str									=			num_conv_pos_embedding_groups
       a		:Tuple									=			len(self.conv_dim       )
       a		:int									=			num_hidden_layers
       a		:Any									=			intermediate_size
       a		:Optional[Any]									=			hidden_act
       a		:Tuple									=			num_attention_heads
       a		:Any									=			hidden_dropout
       a		:Any									=			attention_dropout
       a		:Optional[Any]									=			activation_dropout
       a		:Optional[Any]									=			feat_proj_dropout
       a		:Any									=			final_dropout
       a		:int									=			layerdrop
       a		:int									=			layer_norm_eps
       a		:Dict									=			initializer_range
       a		:Dict									=			num_ctc_classes
       a		:Optional[Any]									=			vocab_size
       a		:str									=			do_stable_layer_norm
       a		:Tuple									=			use_weighted_layer_sum
       a		:Any									=			classifier_proj_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)`, but is `len(config.conv_dim) ='''
                 F''' {len(self.conv_dim       )}`, `len(config.conv_stride) = {len(self.conv_stride       )}`,'''
                 F''' `len(config.conv_kernel) = {len(self.conv_kernel       )}`.'''       )

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

       # parameters for pretraining with codevector quantized representations
       a		:Union[str, Any]									=			num_codevectors_per_group
       a		:Dict									=			num_codevector_groups
       a		:List[Any]									=			contrastive_logits_temperature
       a		:Union[str, Any]									=			feat_quantizer_dropout
       a		:Optional[Any]									=			num_negatives
       a		:Tuple									=			codevector_dim
       a		:Optional[Any]									=			proj_codevector_dim
       a		:Union[str, Any]									=			diversity_loss_weight

       # ctc loss
       a		:List[Any]									=			ctc_loss_reduction
       a		:Union[str, Any]									=			ctc_zero_infinity

       # pretraining loss
       a		:int									=			replace_prob




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





