



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


lowercase__		:    Optional[int]						   =     logging.get_logger(__name__)

lowercase__		:    Any						   =     {
    """salesforce/blip2-opt-2.7b""": """https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json""",
}







class 				UpperCamelCase__       (     a_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					'''blip_2_vision_model'''



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

        lowerCAmelCase_       :    Optional[int]								=			hidden_size
        lowerCAmelCase_       :    str								=			intermediate_size
        lowerCAmelCase_       :    Optional[Any]								=			num_hidden_layers
        lowerCAmelCase_       :    List[Any]								=			num_attention_heads
        lowerCAmelCase_       :    Optional[Any]								=			patch_size
        lowerCAmelCase_       :    Tuple								=			image_size
        lowerCAmelCase_       :    Tuple								=			initializer_range
        lowerCAmelCase_       :    Optional[int]								=			attention_dropout
        lowerCAmelCase_       :    List[Any]								=			layer_norm_eps
        lowerCAmelCase_       :    Optional[int]								=			hidden_act
        lowerCAmelCase_       :    Optional[int]								=			qkv_bias





      @classmethod
      def 					SCREAMING_SNAKE_CASE__			(				cls    :				List[str]   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]   ,      **SCREAMING_SNAKE_CASE_    :				str	):
        cls._set_token_in_kwargs(lowercase_	)

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

        # get the vision config dict if we are loading from Blip2Config
        if config_dict.get('model_type'	) == "blip-2":
          lowerCAmelCase_       :    Dict								=			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(lowercase_   ,      **lowercase_	)







class 				UpperCamelCase__       (     a_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					'''blip_2_qformer'''



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

        lowerCAmelCase_       :    int								=			vocab_size
        lowerCAmelCase_       :    Union[str, Any]								=			hidden_size
        lowerCAmelCase_       :    Union[str, Any]								=			num_hidden_layers
        lowerCAmelCase_       :    List[Any]								=			num_attention_heads
        lowerCAmelCase_       :    Optional[int]								=			hidden_act
        lowerCAmelCase_       :    int								=			intermediate_size
        lowerCAmelCase_       :    str								=			hidden_dropout_prob
        lowerCAmelCase_       :    Optional[int]								=			attention_probs_dropout_prob
        lowerCAmelCase_       :    str								=			max_position_embeddings
        lowerCAmelCase_       :    List[str]								=			initializer_range
        lowerCAmelCase_       :    str								=			layer_norm_eps
        lowerCAmelCase_       :    Union[str, Any]								=			position_embedding_type
        lowerCAmelCase_       :    Optional[int]								=			cross_attention_frequency
        lowerCAmelCase_       :    str								=			encoder_hidden_size





      @classmethod
      def 					SCREAMING_SNAKE_CASE__			(				cls    :				Optional[int]   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      **SCREAMING_SNAKE_CASE_    :				Any	):
        cls._set_token_in_kwargs(lowercase_	)

        lowerCAmelCase_						,lowerCAmelCase_       :    List[str]								=			cls.get_config_dict(lowercase_   ,      **lowercase_	)

        # get the qformer config dict if we are loading from Blip2Config
        if config_dict.get('model_type'	) == "blip-2":
          lowerCAmelCase_       :    Union[str, Any]								=			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(lowercase_   ,      **lowercase_	)







class 				UpperCamelCase__       (     a_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					'''blip-2'''
      _SCREAMING_SNAKE_CASE      =					True



      def __init__(				self    :				Dict   ,      SCREAMING_SNAKE_CASE_    :				List[str]=None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Any]=None   ,      SCREAMING_SNAKE_CASE_    :				int=None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Any]=3_2   ,      **SCREAMING_SNAKE_CASE_    :				List[str]	):
        super().__init__(**lowercase_	)

        if vision_config is None:
          lowerCAmelCase_       :    str								=			{}
          logger.info('vision_config is None. initializing the Blip2VisionConfig with default values.'	)

        if qformer_config is None:
          lowerCAmelCase_       :    List[Any]								=			{}
          logger.info('qformer_config is None. Initializing the Blip2QFormerConfig with default values.'	)

        if text_config is None:
          lowerCAmelCase_       :    Union[str, Any]								=			{}
          logger.info('text_config is None. Initializing the text config with default values (`OPTConfig`).'	)

        lowerCAmelCase_       :    Any								=			BlipaVisionConfig(**lowercase_	)
        lowerCAmelCase_       :    Optional[Any]								=			BlipaQFormerConfig(**lowercase_	)
        lowerCAmelCase_       :    Optional[int]								=			text_config['model_type'] if 'model_type' in text_config else 'opt'
        lowerCAmelCase_       :    str								=			CONFIG_MAPPING[text_model_type](**lowercase_	)

        lowerCAmelCase_       :    List[Any]								=			self.text_config.tie_word_embeddings
        lowerCAmelCase_       :    Any								=			self.text_config.is_encoder_decoder

        lowerCAmelCase_       :    str								=			num_query_tokens
        lowerCAmelCase_       :    Any								=			self.vision_config.hidden_size
        lowerCAmelCase_       :    List[str]								=			self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
        lowerCAmelCase_       :    Union[str, Any]								=			1.0
        lowerCAmelCase_       :    Dict								=			0.02



      @classmethod
      def 					SCREAMING_SNAKE_CASE__			(				cls    :				int   ,      SCREAMING_SNAKE_CASE_    :				List[str]   ,      SCREAMING_SNAKE_CASE_    :				int   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      **SCREAMING_SNAKE_CASE_    :				Any   ,      ):
        return cls(
            vision_config=vision_config.to_dict()   ,      qformer_config=qformer_config.to_dict()   ,      text_config=text_config.to_dict()   ,      **lowercase_   ,      )





      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        lowerCAmelCase_       :    List[Any]								=			copy.deepcopy(self.__dict__	)
        lowerCAmelCase_       :    Tuple								=			self.vision_config.to_dict()
        lowerCAmelCase_       :    Union[str, Any]								=			self.qformer_config.to_dict()
        lowerCAmelCase_       :    List[str]								=			self.text_config.to_dict()
        lowerCAmelCase_       :    List[Any]								=			self.__class__.model_type
        return output










"""simple docstring"""







from diffusers.utils.testing_utils import require_onnxruntime







@require_onnxruntime
class 				UpperCamelCase__       :




      """simple docstring"""




      pass





