



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


UpperCAmelCase						:		List[str]			= logging.get_logger(__name__)


UpperCAmelCase						:		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    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):
    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			:				List[str] ,  lowerCAmelCase_			:				Optional[int]=5_0_4_0_0 ,  lowerCAmelCase_			:				Optional[Any]=2_0_4_8 ,  lowerCAmelCase_			:				Union[str, Any]=2_0_4_8 ,  lowerCAmelCase_			:				Union[str, Any]=4_0_9_6 ,  lowerCAmelCase_			:				List[Any]=2_8 ,  lowerCAmelCase_			:				str=1_6 ,  lowerCAmelCase_			:				Optional[Any]=6_4 ,  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_0_2_5_6 ,  lowerCAmelCase_			:				Optional[Any]=5_0_2_5_6 ,  lowerCAmelCase_			:				Tuple=False ,  **lowerCAmelCase_			:				List[Any] ,  ):







      """simple docstring"""







      lowercase_								= vocab_size
      lowercase_								= n_ctx
      lowercase_								= n_positions
      lowercase_								= n_embd
      lowercase_								= n_layer
      lowercase_								= n_head
      lowercase_								= n_inner
      lowercase_								= rotary_dim
      lowercase_								= activation_function
      lowercase_								= resid_pdrop
      lowercase_								= embd_pdrop
      lowercase_								= attn_pdrop
      lowercase_								= layer_norm_epsilon
      lowercase_								= initializer_range
      lowercase_								= use_cache

      lowercase_								= bos_token_id
      lowercase_								= eos_token_id

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







class    SCREAMING_SNAKE_CASE__ (							__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?
        lowercase_								= 0

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







      """simple docstring"""







      lowercase_								= OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}})
      if self.use_past:
        self.fill_with_past_key_values_(lowerCAmelCase_ ,  direction="""inputs""")
        lowercase_								= {0: """batch""", 1: """past_sequence + sequence"""}
      else:
        lowercase_								= {0: """batch""", 1: """sequence"""}

      return common_inputs

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







      """simple docstring"""







      return self._config.n_layer

    @property
    def 					_UpperCAmelCase	(				self			:				Dict):







      """simple docstring"""







      return self._config.n_head

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







      """simple docstring"""







      lowercase_								= 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()
      lowercase_								= 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_								= common_inputs["""input_ids"""].shape
          # Not using the same length for past_key_values
          lowercase_								= seqlen + 2
          lowercase_								= (
              batch,
              self.num_attention_heads,
              past_key_values_length,
              self._config.hidden_size // self.num_attention_heads,
          )
          lowercase_								= [
              (torch.zeros(lowerCAmelCase_), torch.zeros(lowerCAmelCase_)) for _ in range(self.num_layers)
          ]

      lowercase_								= common_inputs["""attention_mask"""]
      if self.use_past:
        lowercase_								= ordered_inputs["""attention_mask"""].dtype
        lowercase_								= torch.cat(
            [ordered_inputs["""attention_mask"""], torch.ones(lowerCAmelCase_ ,  lowerCAmelCase_ ,  dtype=lowerCAmelCase_)] ,  dim=1)

      return ordered_inputs




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







      """simple docstring"""







      return 1_3






"""simple docstring"""
from typing import TYPE_CHECKING

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


UpperCAmelCase						:		Any			= {
    "configuration_blip": [
        "BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "BlipConfig",
        "BlipTextConfig",
        "BlipVisionConfig",
    ],
    "processing_blip": ["BlipProcessor"],
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase						:		Any			= ["BlipImageProcessor"]


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase						:		Optional[int]			= [
           "BLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
           "BlipModel",
           "BlipPreTrainedModel",
           "BlipForConditionalGeneration",
           "BlipForQuestionAnswering",
           "BlipVisionModel",
           "BlipTextModel",
           "BlipForImageTextRetrieval",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase						:		str			= [
           "TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFBlipModel",
           "TFBlipPreTrainedModel",
           "TFBlipForConditionalGeneration",
           "TFBlipForQuestionAnswering",
           "TFBlipVisionModel",
           "TFBlipTextModel",
           "TFBlipForImageTextRetrieval",
       ]

if TYPE_CHECKING:
       from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
       from .processing_blip import BlipProcessor

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_blip import BlipImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_blip import (
                  BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                  BlipForConditionalGeneration,
                  BlipForImageTextRetrieval,
                  BlipForQuestionAnswering,
                  BlipModel,
                  BlipPreTrainedModel,
                  BlipTextModel,
                  BlipVisionModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_blip import (
                  TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFBlipForConditionalGeneration,
                  TFBlipForImageTextRetrieval,
                  TFBlipForQuestionAnswering,
                  TFBlipModel,
                  TFBlipPreTrainedModel,
                  TFBlipTextModel,
                  TFBlipVisionModel,
              )

else:
       import sys

       UpperCAmelCase						:		Any			= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

