




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


__A        =    logging.get_logger(__name__)


__A        =    {
    '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     __lowerCAmelCase (       lowercase_ ):

			"""simple docstring"""







			snake_case_   		=       """codegen"""
			snake_case_   		=       {
			    """max_position_embeddings""": """n_positions""",
			    """hidden_size""": """n_embd""",
			    """num_attention_heads""": """n_head""",
			    """num_hidden_layers""": """n_layer""",
			}


			def __init__(      self			,						lowerCamelCase__=50_400			,						lowerCamelCase__=2_048			,						lowerCamelCase__=2_048			,						lowerCamelCase__=4_096			,						lowerCamelCase__=28			,						lowerCamelCase__=16			,						lowerCamelCase__=64			,						lowerCamelCase__=None			,						lowerCamelCase__="gelu_new"			,						lowerCamelCase__=0.0			,						lowerCamelCase__=0.0			,						lowerCamelCase__=0.0			,						lowerCamelCase__=1e-5			,						lowerCamelCase__=0.02			,						lowerCamelCase__=True			,						lowerCamelCase__=50_256			,						lowerCamelCase__=50_256			,						lowerCamelCase__=False			,						**lowerCamelCase__			,						)    ->      Optional[Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    vocab_size
							__lowerCamelCase		       =    n_ctx
							__lowerCamelCase		       =    n_positions
							__lowerCamelCase		       =    n_embd
							__lowerCamelCase		       =    n_layer
							__lowerCamelCase		       =    n_head
							__lowerCamelCase		       =    n_inner
							__lowerCamelCase		       =    rotary_dim
							__lowerCamelCase		       =    activation_function
							__lowerCamelCase		       =    resid_pdrop
							__lowerCamelCase		       =    embd_pdrop
							__lowerCamelCase		       =    attn_pdrop
							__lowerCamelCase		       =    layer_norm_epsilon
							__lowerCamelCase		       =    initializer_range
							__lowerCamelCase		       =    use_cache

							__lowerCamelCase		       =    bos_token_id
							__lowerCamelCase		       =    eos_token_id

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







class     __lowerCAmelCase (       lowercase_ ):

			"""simple docstring"""







			def __init__(      self			,						lowerCamelCase__			,						lowerCamelCase__ = "default"			,						lowerCamelCase__ = None			,						lowerCamelCase__ = False			,						)    ->      List[str]:



							'''simple docstring'''
							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?
											__lowerCamelCase		       =    0


			@property
			def       lowercase_    (      self							)    ->      Any:



							'''simple docstring'''
							__lowerCamelCase		       =    OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}							)
							if self.use_past:
											self.fill_with_past_key_values_(lowerCamelCase__			,						direction='inputs'							)
											__lowerCamelCase		       =    {0: 'batch', 1: 'past_sequence + sequence'}
							else:
											__lowerCamelCase		       =    {0: 'batch', 1: 'sequence'}

							return common_inputs


			@property
			def       lowercase_    (      self							)    ->      Optional[Any]:



							'''simple docstring'''
							return self._config.n_layer


			@property
			def       lowercase_    (      self							)    ->      Dict:



							'''simple docstring'''
							return self._config.n_head


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__ = -1			,						lowerCamelCase__ = -1			,						lowerCamelCase__ = False			,						lowerCamelCase__ = None			,						)    ->      Dict:



							'''simple docstring'''
							__lowerCamelCase		       =    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()
							__lowerCamelCase		       =    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

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

							__lowerCamelCase		       =    common_inputs['attention_mask']
							if self.use_past:
											__lowerCamelCase		       =    ordered_inputs['attention_mask'].dtype
											__lowerCamelCase		       =    torch.cat(
											    [ordered_inputs['attention_mask'], torch.ones(lowerCamelCase__			,						lowerCamelCase__			,						dtype=lowerCamelCase__							)]			,						dim=1							)

							return ordered_inputs






			@property
			def       lowercase_    (      self							)    ->      Optional[Any]:



							'''simple docstring'''
							return 13






'''simple docstring'''

import warnings

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


lowerCamelCase							:   str  						=	logging.get_logger(__name__)

lowerCamelCase							:   int  						=	{
    'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/config.json',
}
class   __lowerCAmelCase						(lowercase_     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Union[str, Any]  					=							"""mvp"""
      lowerCAmelCase__					:     Optional[Any]  					=							["""past_key_values"""]
      lowerCAmelCase__					:     List[str]  					=							{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}



      def __init__(self    :    Any   ,						UpperCamelCase    :    Optional[int]=50267   ,						UpperCamelCase    :    Tuple=1024   ,						UpperCamelCase    :    int=12   ,						UpperCamelCase    :    Tuple=4096   ,						UpperCamelCase    :    Dict=16   ,						UpperCamelCase    :    int=12   ,						UpperCamelCase    :    Optional[int]=4096   ,						UpperCamelCase    :    Optional[int]=16   ,						UpperCamelCase    :    Tuple=0.0   ,						UpperCamelCase    :    Tuple=0.0   ,						UpperCamelCase    :    List[Any]="gelu"   ,						UpperCamelCase    :    Union[str, Any]=1024   ,						UpperCamelCase    :    Optional[Any]=0.1   ,						UpperCamelCase    :    str=0.0   ,						UpperCamelCase    :    str=0.0   ,						UpperCamelCase    :    Optional[Any]=0.02   ,						UpperCamelCase    :    List[str]=0.0   ,						UpperCamelCase    :    List[str]=False   ,						UpperCamelCase    :    Optional[int]=True   ,						UpperCamelCase    :    Any=1   ,						UpperCamelCase    :    int=0   ,						UpperCamelCase    :    int=2   ,						UpperCamelCase    :    Any=True   ,						UpperCamelCase    :    Optional[Any]=2   ,						UpperCamelCase    :    Optional[Any]=2   ,						UpperCamelCase    :    Tuple=False   ,						UpperCamelCase    :    int=100   ,						UpperCamelCase    :    Optional[Any]=800   ,						**UpperCamelCase    :    str   ,						):

             '''simple docstring'''







             lowercase__      			= vocab_size
             lowercase__      			= max_position_embeddings
             lowercase__      			= d_model
             lowercase__      			= encoder_ffn_dim
             lowercase__      			= encoder_layers
             lowercase__      			= encoder_attention_heads
             lowercase__      			= decoder_ffn_dim
             lowercase__      			= decoder_layers
             lowercase__      			= decoder_attention_heads
             lowercase__      			= dropout
             lowercase__      			= attention_dropout
             lowercase__      			= activation_dropout
             lowercase__      			= activation_function
             lowercase__      			= init_std
             lowercase__      			= encoder_layerdrop
             lowercase__      			= decoder_layerdrop
             lowercase__      			= classifier_dropout
             lowercase__      			= use_cache
             lowercase__      			= encoder_layers
             lowercase__      			= scale_embedding  # scale factor will be sqrt(d_model) if True
             lowercase__      			= use_prompt
             lowercase__      			= prompt_length
             lowercase__      			= prompt_mid_dim

             super().__init__(
                 pad_token_id=UpperCamelCase   ,						bos_token_id=UpperCamelCase   ,						eos_token_id=UpperCamelCase   ,						is_encoder_decoder=UpperCamelCase   ,						decoder_start_token_id=UpperCamelCase   ,						forced_eos_token_id=UpperCamelCase   ,						**UpperCamelCase   ,						)

             if self.forced_bos_token_id is None and kwargs.get('''force_bos_token_to_be_generated'''   ,						UpperCamelCase ):
                    lowercase__      			= self.bos_token_id
                    warnings.warn(
                        f"Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. "
                        '''The config can simply be saved and uploaded again to be fixed.''' )




