


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    UpperCAmelCase__	( A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Optional[int]              =  "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 ,       A_=50400 ,       A_=2048 ,       A_=2048 ,       A_=4096 ,       A_=28 ,       A_=16 ,       A_=64 ,       A_=None ,       A_="gelu_new" ,       A_=0.0 ,       A_=0.0 ,       A_=0.0 ,       A_=1E-5 ,       A_=0.02 ,       A_=True ,       A_=50256 ,       A_=50256 ,       A_=False ,       **A_ ,       )  ->	Optional[int]:
         __UpperCamelCase   							=vocab_size
         __UpperCamelCase   							=n_ctx
         __UpperCamelCase   							=n_positions
         __UpperCamelCase   							=n_embd
         __UpperCamelCase   							=n_layer
         __UpperCamelCase   							=n_head
         __UpperCamelCase   							=n_inner
         __UpperCamelCase   							=rotary_dim
         __UpperCamelCase   							=activation_function
         __UpperCamelCase   							=resid_pdrop
         __UpperCamelCase   							=embd_pdrop
         __UpperCamelCase   							=attn_pdrop
         __UpperCamelCase   							=layer_norm_epsilon
         __UpperCamelCase   							=initializer_range
         __UpperCamelCase   							=use_cache

         __UpperCamelCase   							=bos_token_id
         __UpperCamelCase   							=eos_token_id

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






class    UpperCAmelCase__	( A_		):



    """simple docstring"""






    def __init__(      self ,       A_ ,       A_ = "default" ,       A_ = None ,       A_ = False ,       )  ->	Tuple:
         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?
              __UpperCamelCase   							=0






    @property
    def _a (      self   )  ->	Mapping[str, Mapping[int, str]]:
         __UpperCamelCase   							=OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}   )
         if self.use_past:
              self.fill_with_past_key_values_(A_ ,       direction='inputs'   )
              __UpperCamelCase   							={0: 'batch', 1: 'past_sequence + sequence'}
         else:
              __UpperCamelCase   							={0: 'batch', 1: 'sequence'}

         return common_inputs






    @property
    def _a (      self   )  ->	int:
         return self._config.n_layer






    @property
    def _a (      self   )  ->	int:
         return self._config.n_head






    def _a (      self ,       A_ ,       A_ = -1 ,       A_ = -1 ,       A_ = False ,       A_ = None ,       )  ->	Mapping[str, Any]:
         __UpperCamelCase   							=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()
         __UpperCamelCase   							=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

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

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

         return ordered_inputs






    @property
    def _a (      self   )  ->	int:
         return 13









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


_A			=						{'configuration_vit': ['VIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ViTConfig', 'ViTOnnxConfig']}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			=						['ViTFeatureExtractor']
   _A			=						['ViTImageProcessor']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			=						[
       'VIT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'ViTForImageClassification',
       'ViTForMaskedImageModeling',
       'ViTModel',
       'ViTPreTrainedModel',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			=						[
       'TFViTForImageClassification',
       'TFViTModel',
       'TFViTPreTrainedModel',
   ]

try:
   if not is_flax_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			=						[
       'FlaxViTForImageClassification',
       'FlaxViTModel',
       'FlaxViTPreTrainedModel',
   ]

if TYPE_CHECKING:
   from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_vit import ViTFeatureExtractor
      from .image_processing_vit import ViTImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_vit import (
          VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
          ViTForImageClassification,
          ViTForMaskedImageModeling,
          ViTModel,
          ViTPreTrainedModel,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

   try:
      if not is_flax_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
   import sys

   _A			=						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





