






"""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


_snake_case          =   logging.get_logger(__name__)


_snake_case          =   {
    '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			(	lowerCamelCase_      ):
 UpperCamelCase					:       Dict			=					'''codegen'''
 UpperCamelCase					:       Optional[int]			=					{
     '''max_position_embeddings''': '''n_positions''',
     '''hidden_size''': '''n_embd''',
     '''num_attention_heads''': '''n_head''',
     '''num_hidden_layers''': '''n_layer''',
 }


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

   _a  :       Dict             =	bos_token_id
   _a  :       Union[str, Any]             =	eos_token_id

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







class        UpperCamelCase			(	lowerCamelCase_      ):


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


 @property
 def _lowercase	(     self		:						Union[str, Any]							)					->       Optional[Any]:
   _a  :       str             =	OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}							)
   if self.use_past:
     self.fill_with_past_key_values_(__a							,						direction="""inputs"""							)
     _a  :       Tuple             =	{0: """batch""", 1: """past_sequence + sequence"""}
   else:
     _a  :       Optional[Any]             =	{0: """batch""", 1: """sequence"""}

   return common_inputs


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


 @property
 def _lowercase	(     self		:						int							)					->       Union[str, Any]:
   return self._config.n_head


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

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

   _a  :       Tuple             =	common_inputs["""attention_mask"""]
   if self.use_past:
     _a  :       Union[str, Any]             =	ordered_inputs["""attention_mask"""].dtype
     _a  :       Union[str, Any]             =	torch.cat(
         [ordered_inputs["""attention_mask"""], torch.ones(__a							,						__a							,						dtype=__a							)]							,						dim=1							)

   return ordered_inputs







 @property
 def _lowercase	(     self		:						int							)					->       List[Any]:
   return 13








'''simple docstring'''







from ....utils import logging


lowerCAmelCase_					:    Union[str, Any]      	=			logging.get_logger(__name__)
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				def __init__(  self     :					Tuple					,				__a     :					int					,				__a     :					Any=None					,				__a     :					Optional[int]=20_48					):
								_a								= config.__dict__
								_a								= modal_hidden_size
								if num_labels:
												_a								= num_labels
