



"""simple docstring"""
import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


UpperCAmelCase						:		Union[str, Any]			= logging.get_logger(__name__)

UpperCAmelCase						:		Tuple			= {
    "Salesforce/instruct-blip-flan-t5": "https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json",
}


class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):
    lowercase__      =   "instructblip_vision_model"

    def __init__(				self			:				List[Any] ,  lowerCAmelCase_			:				Optional[Any]=1_4_0_8 ,  lowerCAmelCase_			:				Tuple=6_1_4_4 ,  lowerCAmelCase_			:				List[Any]=3_9 ,  lowerCAmelCase_			:				Dict=1_6 ,  lowerCAmelCase_			:				Optional[Any]=2_2_4 ,  lowerCAmelCase_			:				List[Any]=1_4 ,  lowerCAmelCase_			:				Optional[Any]="gelu" ,  lowerCAmelCase_			:				Dict=1E-6 ,  lowerCAmelCase_			:				Optional[Any]=0.0 ,  lowerCAmelCase_			:				Any=1E-10 ,  lowerCAmelCase_			:				str=True ,  **lowerCAmelCase_			:				Optional[int] ,  ):







      """simple docstring"""







      super().__init__(**lowerCAmelCase_)

      lowercase_								= hidden_size
      lowercase_								= intermediate_size
      lowercase_								= num_hidden_layers
      lowercase_								= num_attention_heads
      lowercase_								= patch_size
      lowercase_								= image_size
      lowercase_								= initializer_range
      lowercase_								= attention_dropout
      lowercase_								= layer_norm_eps
      lowercase_								= hidden_act
      lowercase_								= qkv_bias




    @classmethod
    def 					_UpperCAmelCase	(				cls			:				Any ,  lowerCAmelCase_			:				Union[str, os.PathLike] ,  **lowerCAmelCase_			:				str):







      """simple docstring"""







      cls._set_token_in_kwargs(lowerCAmelCase_)

      lowercase_					,    lowercase_								= cls.get_config_dict(lowerCAmelCase_ ,  **lowerCAmelCase_)

      # get the vision config dict if we are loading from InstructBlipConfig
      if config_dict.get("""model_type""") == "instructblip":
        lowercase_								= config_dict["""vision_config"""]

      if "model_type" in config_dict and hasattr(cls ,  """model_type""") and config_dict["model_type"] != cls.model_type:
        logger.warning(
            F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
            F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.''')

      return cls.from_dict(lowerCAmelCase_ ,  **lowerCAmelCase_)







class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):
    lowercase__      =   "instructblip_qformer"

    def __init__(				self			:				List[str] ,  lowerCAmelCase_			:				Union[str, Any]=3_0_5_2_2 ,  lowerCAmelCase_			:				Tuple=7_6_8 ,  lowerCAmelCase_			:				Union[str, Any]=1_2 ,  lowerCAmelCase_			:				Any=1_2 ,  lowerCAmelCase_			:				Optional[Any]=3_0_7_2 ,  lowerCAmelCase_			:				Union[str, Any]="gelu" ,  lowerCAmelCase_			:				Optional[int]=0.1 ,  lowerCAmelCase_			:				Optional[int]=0.1 ,  lowerCAmelCase_			:				Tuple=5_1_2 ,  lowerCAmelCase_			:				List[str]=0.02 ,  lowerCAmelCase_			:				List[str]=1E-12 ,  lowerCAmelCase_			:				List[str]=0 ,  lowerCAmelCase_			:				Dict="absolute" ,  lowerCAmelCase_			:				Any=2 ,  lowerCAmelCase_			:				str=1_4_0_8 ,  **lowerCAmelCase_			:				int ,  ):







      """simple docstring"""







      super().__init__(pad_token_id=lowerCAmelCase_ ,  **lowerCAmelCase_)

      lowercase_								= vocab_size
      lowercase_								= hidden_size
      lowercase_								= num_hidden_layers
      lowercase_								= num_attention_heads
      lowercase_								= hidden_act
      lowercase_								= intermediate_size
      lowercase_								= hidden_dropout_prob
      lowercase_								= attention_probs_dropout_prob
      lowercase_								= max_position_embeddings
      lowercase_								= initializer_range
      lowercase_								= layer_norm_eps
      lowercase_								= position_embedding_type
      lowercase_								= cross_attention_frequency
      lowercase_								= encoder_hidden_size




    @classmethod
    def 					_UpperCAmelCase	(				cls			:				Tuple ,  lowerCAmelCase_			:				Union[str, os.PathLike] ,  **lowerCAmelCase_			:				Union[str, Any]):







      """simple docstring"""







      cls._set_token_in_kwargs(lowerCAmelCase_)

      lowercase_					,    lowercase_								= cls.get_config_dict(lowerCAmelCase_ ,  **lowerCAmelCase_)

      # get the qformer config dict if we are loading from InstructBlipConfig
      if config_dict.get("""model_type""") == "instructblip":
        lowercase_								= config_dict["""qformer_config"""]

      if "model_type" in config_dict and hasattr(cls ,  """model_type""") and config_dict["model_type"] != cls.model_type:
        logger.warning(
            F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
            F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.''')

      return cls.from_dict(lowerCAmelCase_ ,  **lowerCAmelCase_)







class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):
    lowercase__      =   "instructblip"
    lowercase__      =   True

    def __init__(				self			:				Union[str, Any] ,  lowerCAmelCase_			:				Tuple=None ,  lowerCAmelCase_			:				Optional[Any]=None ,  lowerCAmelCase_			:				Union[str, Any]=None ,  lowerCAmelCase_			:				str=3_2 ,  **lowerCAmelCase_			:				List[str]):







      """simple docstring"""







      super().__init__(**lowerCAmelCase_)

      if vision_config is None:
        lowercase_								= {}
        logger.info("""vision_config is None. initializing the InstructBlipVisionConfig with default values.""")

      if qformer_config is None:
        lowercase_								= {}
        logger.info("""qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.""")

      if text_config is None:
        lowercase_								= {}
        logger.info("""text_config is None. Initializing the text config with default values (`OPTConfig`).""")

      lowercase_								= InstructBlipVisionConfig(**lowerCAmelCase_)
      lowercase_								= InstructBlipQFormerConfig(**lowerCAmelCase_)
      lowercase_								= text_config["""model_type"""] if """model_type""" in text_config else """opt"""
      lowercase_								= CONFIG_MAPPING[text_model_type](**lowerCAmelCase_)

      lowercase_								= self.text_config.tie_word_embeddings
      lowercase_								= self.text_config.is_encoder_decoder

      lowercase_								= num_query_tokens
      lowercase_								= self.vision_config.hidden_size
      lowercase_								= self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
      lowercase_								= 1.0
      lowercase_								= 0.02

    @classmethod
    def 					_UpperCAmelCase	(				cls			:				Dict ,  lowerCAmelCase_			:				InstructBlipVisionConfig ,  lowerCAmelCase_			:				InstructBlipQFormerConfig ,  lowerCAmelCase_			:				PretrainedConfig ,  **lowerCAmelCase_			:				Optional[int] ,  ):







      """simple docstring"""







      return cls(
          vision_config=vision_config.to_dict() ,  qformer_config=qformer_config.to_dict() ,  text_config=text_config.to_dict() ,  **lowerCAmelCase_ ,  )




    def 					_UpperCAmelCase	(				self			:				Optional[Any]):







      """simple docstring"""







      lowercase_								= copy.deepcopy(self.__dict__)
      lowercase_								= self.vision_config.to_dict()
      lowercase_								= self.qformer_config.to_dict()
      lowercase_								= self.text_config.to_dict()
      lowercase_								= self.__class__.model_type
      return output






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

from ...utils import _LazyModule


UpperCAmelCase						:		List[Any]			= {"tokenization_bertweet": ["BertweetTokenizer"]}


if TYPE_CHECKING:
       from .tokenization_bertweet import BertweetTokenizer

else:
       import sys

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

