




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


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       lowercase(  __a				):
 lowercase__				      =      """codegen"""
 lowercase__				      =      {
     """max_position_embeddings""": """n_positions""",
     """hidden_size""": """n_embd""",
     """num_attention_heads""": """n_head""",
     """num_hidden_layers""": """n_layer""",
 }


 def __init__(       self:	int,   a_:	Dict=50_400,   a_:	Dict=2_048,   a_:	str=2_048,   a_:	int=4_096,   a_:	Union[str, Any]=28,   a_:	Optional[Any]=16,   a_:	str=64,   a_:	Tuple=None,   a_:	Any="gelu_new",   a_:	Optional[Any]=0.0,   a_:	Optional[Any]=0.0,   a_:	Any=0.0,   a_:	Any=1E-5,   a_:	Dict=0.02,   a_:	List[Any]=True,   a_:	Optional[Any]=50_256,   a_:	List[Any]=50_256,   a_:	Dict=False,   **a_:	int,   ):




   '''simple docstring'''



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

   _snake_case							:	str			=						bos_token_id
   _snake_case							:	Union[str, Any]			=						eos_token_id

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







class       lowercase(  __a				):


 def __init__(       self:	Tuple,   a_:	PretrainedConfig,   a_:	str = "default",   a_:	List[PatchingSpec] = None,   a_:	bool = False,   ):




   '''simple docstring'''



   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?
     _snake_case							:	Tuple			=						0


 @property
 def 				UpperCamelCase_     (       self:	List[Any]	):




   '''simple docstring'''



   _snake_case							:	List[str]			=						OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}	)
   if self.use_past:
     self.fill_with_past_key_values_(a_,   direction="""inputs"""	)
     _snake_case							:	int			=						{0: """batch""", 1: """past_sequence + sequence"""}
   else:
     _snake_case							:	List[str]			=						{0: """batch""", 1: """sequence"""}

   return common_inputs


 @property
 def 				UpperCamelCase_     (       self:	List[Any]	):




   '''simple docstring'''



   return self._config.n_layer


 @property
 def 				UpperCamelCase_     (       self:	int	):




   '''simple docstring'''



   return self._config.n_head


 def 				UpperCamelCase_     (       self:	Optional[int],   a_:	PreTrainedTokenizer,   a_:	int = -1,   a_:	int = -1,   a_:	bool = False,   a_:	Optional[TensorType] = None,   ):




   '''simple docstring'''



   _snake_case							:	str			=						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()
   _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							:	Optional[int]			=						common_inputs["""input_ids"""].shape
       # Not using the same length for past_key_values
       _snake_case							:	int			=						seqlen + 2
       _snake_case							:	Dict			=						(
           batch,
           self.num_attention_heads,
           past_key_values_length,
           self._config.hidden_size // self.num_attention_heads,
       )
       _snake_case							:	List[Any]			=						[
           (torch.zeros(a_	), torch.zeros(a_	)) for _ in range(self.num_layers	)
       ]

   _snake_case							:	Optional[Any]			=						common_inputs["""attention_mask"""]
   if self.use_past:
     _snake_case							:	Optional[Any]			=						ordered_inputs["""attention_mask"""].dtype
     _snake_case							:	Dict			=						torch.cat(
         [ordered_inputs["""attention_mask"""], torch.ones(a_,   a_,   dtype=a_	)],   dim=1	)

   return ordered_inputs


 @property
 def 				UpperCamelCase_     (       self:	Any	):




   '''simple docstring'''



   return 13








"""simple docstring"""


from abc import ABC, abstractmethod
from argparse import ArgumentParser






class       lowercase(  __a				):







 '''simple docstring'''





 @staticmethod
 @abstractmethod
 def 				UpperCamelCase_     (       a_:	ArgumentParser	):




   '''simple docstring'''



   raise NotImplementedError()


 @abstractmethod
 def 				UpperCamelCase_     (       self:	List[str]	):




   '''simple docstring'''



   raise NotImplementedError()


