




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   :						Union[str, Any]				=			logging.get_logger(__name__)

__lowerCamelCase   :						Any				=			{
    '''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    (		_lowerCamelCase						):






			'''simple docstring'''





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

			def __init__( self			:   List[Any]       ,						lowerCamelCase_			:   Dict=50400       ,						lowerCamelCase_			:   List[str]=2048       ,						lowerCamelCase_			:   Dict=4096       ,						lowerCamelCase_			:   Optional[Any]=28       ,						lowerCamelCase_			:   Optional[Any]=16       ,						lowerCamelCase_			:   Optional[Any]=64       ,						lowerCamelCase_			:   Tuple=None       ,						lowerCamelCase_			:   Optional[int]="gelu_new"       ,						lowerCamelCase_			:   Tuple=0.0       ,						lowerCamelCase_			:   List[Any]=0.0       ,						lowerCamelCase_			:   Optional[int]=0.0       ,						lowerCamelCase_			:   List[str]=1E-5       ,						lowerCamelCase_			:   Union[str, Any]=0.0_2       ,						lowerCamelCase_			:   Dict=True       ,						lowerCamelCase_			:   Dict=50256       ,						lowerCamelCase_			:   Dict=50256       ,						lowerCamelCase_			:   Union[str, Any]=False       ,						**lowerCamelCase_			:   Any       ,						)						->   str:
								__magic_name__							:	List[str]    							=							vocab_size
								__magic_name__							:	List[Any]    							=							n_positions
								__magic_name__							:	Union[str, Any]    							=							n_embd
								__magic_name__							:	Tuple    							=							n_layer
								__magic_name__							:	str    							=							n_head
								__magic_name__							:	List[str]    							=							n_inner
								__magic_name__							:	Dict    							=							rotary_dim
								__magic_name__							:	int    							=							activation_function
								__magic_name__							:	Tuple    							=							resid_pdrop
								__magic_name__							:	Optional[int]    							=							embd_pdrop
								__magic_name__							:	List[str]    							=							attn_pdrop
								__magic_name__							:	Dict    							=							layer_norm_epsilon
								__magic_name__							:	Any    							=							initializer_range
								__magic_name__							:	Optional[Any]    							=							use_cache

								__magic_name__							:	Tuple    							=							bos_token_id
								__magic_name__							:	str    							=							eos_token_id

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






class    lowerCamelCase    (		_lowerCamelCase						):






			'''simple docstring'''





			def __init__( self			:   Any       ,						lowerCamelCase_			:   PretrainedConfig       ,						lowerCamelCase_			:   str = "default"       ,						lowerCamelCase_			:   List[PatchingSpec] = None       ,						lowerCamelCase_			:   bool = False       ,						)						->   List[Any]:
								super().__init__(lowerCamelCase_       ,						task=lowerCamelCase_       ,						patching_specs=lowerCamelCase_       ,						use_past=lowerCamelCase_  )
								if not getattr(self._config       ,						'''pad_token_id'''       ,						lowerCamelCase_  ):
													# TODO: how to do that better?
													__magic_name__							:	Tuple    							=							0

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

								return common_inputs

			@property
			def 							UpperCAmelCase__       ( self			:   Any  )						->   int:
								return self._config.n_layer

			@property
			def 							UpperCAmelCase__       ( self			:   Any  )						->   int:
								return self._config.n_head

			def 							UpperCAmelCase__       ( self			:   Optional[int]       ,						lowerCamelCase_			:   PreTrainedTokenizer       ,						lowerCamelCase_			:   int = -1       ,						lowerCamelCase_			:   int = -1       ,						lowerCamelCase_			:   bool = False       ,						lowerCamelCase_			:   Optional[TensorType] = None       ,						)						->   Mapping[str, Any]:
								__magic_name__							:	int    							=							super(lowerCamelCase_       ,						self  ).generate_dummy_inputs(
								    lowerCamelCase_       ,						batch_size=lowerCamelCase_       ,						seq_length=lowerCamelCase_       ,						is_pair=lowerCamelCase_       ,						framework=lowerCamelCase_  )

								# We need to order the input in the way they appears in the forward()
								__magic_name__							:	List[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

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

								__magic_name__							:	Optional[Any]    							=							common_inputs['''attention_mask''']
								if self.use_past:
													__magic_name__							:	int    							=							ordered_inputs['''attention_mask'''].dtype
													__magic_name__							:	str    							=							torch.cat(
													    [ordered_inputs['''attention_mask'''], torch.ones(lowerCamelCase_       ,						lowerCamelCase_       ,						dtype=lowerCamelCase_  )]       ,						dim=1  )

								return ordered_inputs


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









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_tf_available,
    is_torch_available,
)


__lowerCamelCase   :						List[Any]				=			{
    '''configuration_speech_to_text''': ['''SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''Speech2TextConfig'''],
    '''processing_speech_to_text''': ['''Speech2TextProcessor'''],
}

try:
	if not is_sentencepiece_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowerCamelCase   :						Any				=			['''Speech2TextTokenizer''']

try:
	if not is_speech_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowerCamelCase   :						Optional[Any]				=			['''Speech2TextFeatureExtractor''']

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowerCamelCase   :						Any				=			[
	    '''TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TFSpeech2TextForConditionalGeneration''',
	    '''TFSpeech2TextModel''',
	    '''TFSpeech2TextPreTrainedModel''',
	]

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowerCamelCase   :						Any				=			[
	    '''SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''Speech2TextForConditionalGeneration''',
	    '''Speech2TextModel''',
	    '''Speech2TextPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_speech_to_text import SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextConfig
	from .processing_speech_to_text import SpeechaTextProcessor

	try:
		if not is_sentencepiece_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_speech_to_text import SpeechaTextTokenizer

	try:
		if not is_speech_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_speech_to_text import SpeechaTextFeatureExtractor

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_speech_to_text import (
		    TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFSpeechaTextForConditionalGeneration,
		    TFSpeechaTextModel,
		    TFSpeechaTextPreTrainedModel,
		)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_speech_to_text import (
		    SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    SpeechaTextForConditionalGeneration,
		    SpeechaTextModel,
		    SpeechaTextPreTrainedModel,
		)

else:
	import sys

	__lowerCamelCase   :						List[str]				=			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



