
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__    :		Tuple          =   logging.get_logger(__name__)


lowerCamelCase__    :		List[str]          =   {
    """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       _snake_case   (	UpperCAmelCase_							):
 __lowerCAmelCase  :     List[Any]        =			'codegen'
 __lowerCAmelCase  :     Dict        =			{
     'max_position_embeddings': 'n_positions',
     'hidden_size': 'n_embd',
     'num_attention_heads': 'n_head',
     'num_hidden_layers': 'n_layer',
 }


 def __init__(					self					,  SCREAMING_SNAKE_CASE_=5_04_00					,  SCREAMING_SNAKE_CASE_=20_48					,  SCREAMING_SNAKE_CASE_=20_48					,  SCREAMING_SNAKE_CASE_=40_96					,  SCREAMING_SNAKE_CASE_=28					,  SCREAMING_SNAKE_CASE_=16					,  SCREAMING_SNAKE_CASE_=64					,  SCREAMING_SNAKE_CASE_=None					,  SCREAMING_SNAKE_CASE_="gelu_new"					,  SCREAMING_SNAKE_CASE_=0.0					,  SCREAMING_SNAKE_CASE_=0.0					,  SCREAMING_SNAKE_CASE_=0.0					,  SCREAMING_SNAKE_CASE_=1E-5					,  SCREAMING_SNAKE_CASE_=0.0_2					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=5_02_56					,  SCREAMING_SNAKE_CASE_=5_02_56					,  SCREAMING_SNAKE_CASE_=False					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




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

   lowercase__  :   Dict    		=      bos_token_id
   lowercase__  :   Optional[Any]    		=      eos_token_id

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



class       _snake_case   (	UpperCAmelCase_							):


 def __init__(					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = "default"					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = False					,  ):


   '''simple docstring'''




   super().__init__(SCREAMING_SNAKE_CASE_					,  task=SCREAMING_SNAKE_CASE_					,  patching_specs=SCREAMING_SNAKE_CASE_					,  use_past=SCREAMING_SNAKE_CASE_)
   if not getattr(self._config					,  """pad_token_id"""					,  SCREAMING_SNAKE_CASE_):
     # TODO: how to do that better?
     lowercase__  :   Optional[Any]    		=      0


 @property
 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Union[str, Any]    		=      OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}})
   if self.use_past:
     self.fill_with_past_key_values_(SCREAMING_SNAKE_CASE_					,  direction="""inputs""")
     lowercase__  :   Union[str, Any]    		=      {0: """batch""", 1: """past_sequence + sequence"""}
   else:
     lowercase__  :   str    		=      {0: """batch""", 1: """sequence"""}

   return common_inputs


 @property
 def      lowercase__     (					self):


   '''simple docstring'''




   return self._config.n_layer


 @property
 def      lowercase__     (					self):


   '''simple docstring'''




   return self._config.n_head


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = -1					,  SCREAMING_SNAKE_CASE_ = -1					,  SCREAMING_SNAKE_CASE_ = False					,  SCREAMING_SNAKE_CASE_ = None					,  ):


   '''simple docstring'''




   lowercase__  :   Any    		=      super(SCREAMING_SNAKE_CASE_					,  self).generate_dummy_inputs(
       SCREAMING_SNAKE_CASE_					,  batch_size=SCREAMING_SNAKE_CASE_					,  seq_length=SCREAMING_SNAKE_CASE_					,  is_pair=SCREAMING_SNAKE_CASE_					,  framework=SCREAMING_SNAKE_CASE_)

   # We need to order the input in the way they appears in the forward()
   lowercase__  :   Dict    		=      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

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

   lowercase__  :   Optional[int]    		=      common_inputs["""attention_mask"""]
   if self.use_past:
     lowercase__  :   str    		=      ordered_inputs["""attention_mask"""].dtype
     lowercase__  :   int    		=      torch.cat(
         [ordered_inputs["""attention_mask"""], torch.ones(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  dtype=SCREAMING_SNAKE_CASE_)]					,  dim=1)

   return ordered_inputs



 @property
 def      lowercase__     (					self):


   '''simple docstring'''




   return 13








from ..utils import DummyObject, requires_backends



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Any        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Any        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Union[str, Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     int        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Optional[Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Tuple        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     List[str]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Union[str, Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Optional[Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Dict        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Optional[Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     Optional[Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



class       _snake_case   (	metaclass=UpperCAmelCase_							):
 __lowerCAmelCase  :     List[Any]        =			['flax']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""flax"""])


 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])



 @classmethod
 def      lowercase__     (					cls					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(cls					,  ["""flax"""])






