



'''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_     :       Optional[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 	lowerCamelCase_							(					__UpperCAmelCase			):
      _lowerCAmelCase     :   Union[str, Any]	     =				'codegen'
      _lowerCAmelCase     :   Optional[int]	     =				{
          'max_position_embeddings': 'n_positions',
          'hidden_size': 'n_embd',
          'num_attention_heads': 'n_head',
          'num_hidden_layers': 'n_layer',
      }







      def __init__(  self   :      List[str]				,    lowerCAmelCase__   :      Optional[int]=5_04_00				,    lowerCAmelCase__   :      Optional[Any]=20_48				,    lowerCAmelCase__   :      Union[str, Any]=20_48				,    lowerCAmelCase__   :      Union[str, Any]=40_96				,    lowerCAmelCase__   :      List[Any]=28				,    lowerCAmelCase__   :      str=16				,    lowerCAmelCase__   :      Optional[Any]=64				,    lowerCAmelCase__   :      str=None				,    lowerCAmelCase__   :      Tuple="gelu_new"				,    lowerCAmelCase__   :      List[str]=0.0				,    lowerCAmelCase__   :      Dict=0.0				,    lowerCAmelCase__   :      Dict=0.0				,    lowerCAmelCase__   :      List[Any]=1e-5				,    lowerCAmelCase__   :      str=0.02				,    lowerCAmelCase__   :      Optional[int]=True				,    lowerCAmelCase__   :      Any=5_02_56				,    lowerCAmelCase__   :      Optional[Any]=5_02_56				,    lowerCAmelCase__   :      Tuple=False				,    **lowerCAmelCase__   :      List[Any]				,    ):

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

             SCREAMING_SNAKE_CASE					:      int     					=			bos_token_id
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			eos_token_id

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


class 	lowerCamelCase_							(					__UpperCAmelCase			):







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

             """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?
                    SCREAMING_SNAKE_CASE					:      List[str]     					=			0







      @property
      def 					__lowercase    (  self   :      List[str]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Any     					=			OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}				)
             if self.use_past:
                    self.fill_with_past_key_values_(lowerCAmelCase_				,    direction='''inputs'''				)
                    SCREAMING_SNAKE_CASE					:      Dict     					=			{0: '''batch''', 1: '''past_sequence + sequence'''}
             else:
                    SCREAMING_SNAKE_CASE					:      Optional[int]     					=			{0: '''batch''', 1: '''sequence'''}

             return common_inputs







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

             """simple docstring"""
             return self._config.n_layer







      @property
      def 					__lowercase    (  self   :      Dict				):

             """simple docstring"""
             return self._config.n_head







      def 					__lowercase    (  self   :      Any				,    lowerCAmelCase__   :      PreTrainedTokenizer				,    lowerCAmelCase__   :      int = -1				,    lowerCAmelCase__   :      int = -1				,    lowerCAmelCase__   :      bool = False				,    lowerCAmelCase__   :      Optional[TensorType] = None				,    ):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      str     					=			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()
             SCREAMING_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

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

             SCREAMING_SNAKE_CASE					:      str     					=			common_inputs['''attention_mask''']
             if self.use_past:
                    SCREAMING_SNAKE_CASE					:      List[Any]     					=			ordered_inputs['''attention_mask'''].dtype
                    SCREAMING_SNAKE_CASE					:      Optional[int]     					=			torch.cat(
                        [ordered_inputs['''attention_mask'''], torch.ones(lowerCAmelCase_				,    lowerCAmelCase_				,    dtype=lowerCAmelCase_				)]				,    dim=1				)

             return ordered_inputs







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

             """simple docstring"""
             return 13









'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowerCAmelCase_     :       Tuple								=						{
    'configuration_tapas': ['TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TapasConfig'],
    'tokenization_tapas': ['TapasTokenizer'],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase_     :       Dict								=						[
							    'TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TapasForMaskedLM',
							    'TapasForQuestionAnswering',
							    'TapasForSequenceClassification',
							    'TapasModel',
							    'TapasPreTrainedModel',
							    'load_tf_weights_in_tapas',
							]
try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase_     :       str								=						[
							    'TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFTapasForMaskedLM',
							    'TFTapasForQuestionAnswering',
							    'TFTapasForSequenceClassification',
							    'TFTapasModel',
							    'TFTapasPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_tapas import TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP, TapasConfig
							from .tokenization_tapas import TapasTokenizer

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tapas import (
														    TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TapasForMaskedLM,
														    TapasForQuestionAnswering,
														    TapasForSequenceClassification,
														    TapasModel,
														    TapasPreTrainedModel,
														    load_tf_weights_in_tapas,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_tapas import (
														    TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFTapasForMaskedLM,
														    TFTapasForQuestionAnswering,
														    TFTapasForSequenceClassification,
														    TFTapasModel,
														    TFTapasPreTrainedModel,
														)


else:
							import sys

							lowerCAmelCase_     :       List[Any]								=						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




