





'''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 :		List[str] 			=				logging.get_logger(__name__)


_lowerCamelCase :		List[Any] 			=				{
    'Salesforce/codegen-350M-nl': 'https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json',
    'Salesforce/codegen-350M-multi': 'https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json',
    'Salesforce/codegen-350M-mono': 'https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json',
    'Salesforce/codegen-2B-nl': 'https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json',
    'Salesforce/codegen-2B-multi': 'https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json',
    'Salesforce/codegen-2B-mono': 'https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json',
    'Salesforce/codegen-6B-nl': 'https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json',
    'Salesforce/codegen-6B-multi': 'https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json',
    'Salesforce/codegen-6B-mono': 'https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json',
    'Salesforce/codegen-16B-nl': 'https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json',
    'Salesforce/codegen-16B-multi': 'https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json',
    'Salesforce/codegen-16B-mono': 'https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json',
}



class 							__UpperCAmelCase     (				__lowercase  ):







		'''simple docstring'''







		__lowerCAmelCase        =			'''codegen'''
		__lowerCAmelCase        =			{
		    '''max_position_embeddings''': '''n_positions''',
		    '''hidden_size''': '''n_embd''',
		    '''num_attention_heads''': '''n_head''',
		    '''num_hidden_layers''': '''n_layer''',
		}







		def __init__(self  :					int					,					_lowerCAmelCase  :					Any=5_0400					,					_lowerCAmelCase  :					Union[str, Any]=2048					,					_lowerCAmelCase  :					Dict=2048					,					_lowerCAmelCase  :					Union[str, Any]=4096					,					_lowerCAmelCase  :					Tuple=28					,					_lowerCAmelCase  :					List[Any]=16					,					_lowerCAmelCase  :					List[str]=64					,					_lowerCAmelCase  :					List[Any]=None					,					_lowerCAmelCase  :					List[Any]="gelu_new"					,					_lowerCAmelCase  :					Optional[int]=0.0					,					_lowerCAmelCase  :					Optional[int]=0.0					,					_lowerCAmelCase  :					List[Any]=0.0					,					_lowerCAmelCase  :					Union[str, Any]=1e-5					,					_lowerCAmelCase  :					Any=0.02					,					_lowerCAmelCase  :					Dict=True					,					_lowerCAmelCase  :					Any=5_0256					,					_lowerCAmelCase  :					Tuple=5_0256					,					_lowerCAmelCase  :					str=False					,					**_lowerCAmelCase  :					Optional[int]					,					):
			A							     =					vocab_size
			A							     =					n_ctx
			A							     =					n_positions
			A							     =					n_embd
			A							     =					n_layer
			A							     =					n_head
			A							     =					n_inner
			A							     =					rotary_dim
			A							     =					activation_function
			A							     =					resid_pdrop
			A							     =					embd_pdrop
			A							     =					attn_pdrop
			A							     =					layer_norm_epsilon
			A							     =					initializer_range
			A							     =					use_cache

			A							     =					bos_token_id
			A							     =					eos_token_id

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






class 							__UpperCAmelCase     (				__lowercase  ):







		'''simple docstring'''







		def __init__(self  :					Optional[int]					,					_lowerCAmelCase  :					PretrainedConfig					,					_lowerCAmelCase  :					str = "default"					,					_lowerCAmelCase  :					List[PatchingSpec] = None					,					_lowerCAmelCase  :					bool = False					,					):
			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?
				A							     =					0







		@property
		def 				A   (self  :					Tuple					):
			A							     =					OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}					)
			if self.use_past:
				self.fill_with_past_key_values_(_lowerCAmelCase					,					direction="""inputs"""					)
				A							     =					{0: "batch", 1: "past_sequence + sequence"}
			else:
				A							     =					{0: "batch", 1: "sequence"}

			return common_inputs







		@property
		def 				A   (self  :					Union[str, Any]					):
			return self._config.n_layer







		@property
		def 				A   (self  :					Any					):
			return self._config.n_head







		def 				A   (self  :					List[Any]					,					_lowerCAmelCase  :					PreTrainedTokenizer					,					_lowerCAmelCase  :					int = -1					,					_lowerCAmelCase  :					int = -1					,					_lowerCAmelCase  :					bool = False					,					_lowerCAmelCase  :					Optional[TensorType] = None					,					):
			A							     =					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()
			A							     =					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

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

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

			return ordered_inputs







		@property
		def 				A   (self  :					List[str]					):
			return 13



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


lowercase  :					List[Any]													=       logging.get_logger(__name__)

lowercase  :					Any													=       {
    'google/pegasus-large': 'https://huggingface.co/google/pegasus-large/resolve/main/config.json',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}




class  lowerCamelCase__							(				__lowercase):




	'''simple docstring'''




	_A								=     'pegasus'
	_A								=     ['past_key_values']
	_A								=     {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}







	def __init__(					self		:Dict     ,   a		:Dict=5_0_2_6_5     ,   a		:Dict=1_0_2_4     ,   a		:Union[str, Any]=1_2     ,   a		:Any=4_0_9_6     ,   a		:str=1_6     ,   a		:str=1_2     ,   a		:Optional[Any]=4_0_9_6     ,   a		:int=1_6     ,   a		:Optional[int]=0.0     ,   a		:Optional[int]=0.0     ,   a		:List[Any]=True     ,   a		:Union[str, Any]=True     ,   a		:int="gelu"     ,   a		:Dict=1_0_2_4     ,   a		:List[Any]=0.1     ,   a		:List[str]=0.0     ,   a		:List[Any]=0.0     ,   a		:str=0.02     ,   a		:int=0     ,   a		:Any=False     ,   a		:Dict=0     ,   a		:int=1     ,   a		:Optional[Any]=1     ,   **a		:Optional[int]     ,   )		-> str:
								__UpperCamelCase	:   List[Any]			   =					vocab_size
								__UpperCamelCase	:   Union[str, Any]			   =					max_position_embeddings
								__UpperCamelCase	:   str			   =					d_model
								__UpperCamelCase	:   Dict			   =					encoder_ffn_dim
								__UpperCamelCase	:   int			   =					encoder_layers
								__UpperCamelCase	:   int			   =					encoder_attention_heads
								__UpperCamelCase	:   List[Any]			   =					decoder_ffn_dim
								__UpperCamelCase	:   List[Any]			   =					decoder_layers
								__UpperCamelCase	:   List[str]			   =					decoder_attention_heads
								__UpperCamelCase	:   str			   =					dropout
								__UpperCamelCase	:   Union[str, Any]			   =					attention_dropout
								__UpperCamelCase	:   List[str]			   =					activation_dropout
								__UpperCamelCase	:   Optional[Any]			   =					activation_function
								__UpperCamelCase	:   Tuple			   =					init_std
								__UpperCamelCase	:   Optional[int]			   =					encoder_layerdrop
								__UpperCamelCase	:   Union[str, Any]			   =					decoder_layerdrop
								__UpperCamelCase	:   Optional[Any]			   =					use_cache
								__UpperCamelCase	:   Union[str, Any]			   =					encoder_layers
								__UpperCamelCase	:   int			   =					scale_embedding  # scale factor will be sqrt(d_model) if True
								super().__init__(
								    pad_token_id=a     ,   eos_token_id=a     ,   is_encoder_decoder=a     ,   decoder_start_token_id=a     ,   forced_eos_token_id=a     ,   **a     ,   )







	@property
	def    _lowerCamelCase				(					self		:Dict						)		-> int:
								return self.encoder_attention_heads







	@property
	def    _lowerCamelCase				(					self		:Optional[Any]						)		-> int:
								return self.d_model