



'''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_	 =						logging.get_logger(__name__)

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






class __A    (						__lowercase		):



	'''simple docstring'''







	__lowerCamelCase					: Tuple    = 'blip_2_vision_model'



	def __init__(self				,     A=1_408				,     A=6_144				,     A=39				,     A=16				,     A=224				,     A=14				,     A="gelu"				,     A=0.00001				,     A=0.0				,     A=1E-10				,     A=True				,     **A				,     )					->  int:


						"""simple docstring"""



						super().__init__(**__A )

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



	@classmethod
	def       a__						(cls				,     A				,     **A )					->  "PretrainedConfig":


						"""simple docstring"""



						cls._set_token_in_kwargs(__A )

						_a						,					_a											=						cls.get_config_dict(__A				,     **__A )

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






class __A    (						__lowercase		):



	'''simple docstring'''







	__lowerCamelCase					: int    = 'blip_2_qformer'



	def __init__(self				,     A=30_522				,     A=768				,     A=12				,     A=12				,     A=3_072				,     A="gelu"				,     A=0.1				,     A=0.1				,     A=512				,     A=0.02				,     A=1E-12				,     A=0				,     A="absolute"				,     A=2				,     A=1_408				,     **A				,     )					->  List[str]:


						"""simple docstring"""



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

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



	@classmethod
	def       a__						(cls				,     A				,     **A )					->  "PretrainedConfig":


						"""simple docstring"""



						cls._set_token_in_kwargs(__A )

						_a						,					_a											=						cls.get_config_dict(__A				,     **__A )

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






class __A    (						__lowercase		):



	'''simple docstring'''







	__lowerCamelCase					: Optional[int]    = 'blip-2'
	__lowerCamelCase					: Any    = True



	def __init__(self				,     A=None				,     A=None				,     A=None				,     A=32				,     **A )					->  int:


						"""simple docstring"""



						super().__init__(**__A )

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

						if qformer_config is None:
											_a											=						{}
											logger.info('''qformer_config is None. Initializing the Blip2QFormerConfig with default values.''' )

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

						_a											=						BlipaVisionConfig(**__A )
						_a											=						BlipaQFormerConfig(**__A )
						_a											=						text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
						_a											=						CONFIG_MAPPING[text_model_type](**__A )

						_a											=						self.text_config.tie_word_embeddings
						_a											=						self.text_config.is_encoder_decoder

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



	@classmethod
	def       a__						(cls				,     A				,     A				,     A				,     **A				,     )					->  Any:


						"""simple docstring"""



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



	def       a__						(self )					->  Tuple:


						"""simple docstring"""



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








'''simple docstring'''





# This is the module that test_patching.py uses to test patch_submodule()

import os  # noqa: this is just for tests
import os as renamed_os  # noqa: this is just for tests
from os import path  # noqa: this is just for tests
from os import path as renamed_path  # noqa: this is just for tests
from os.path import join  # noqa: this is just for tests
from os.path import join as renamed_join  # noqa: this is just for tests


lowercase_	 =						open  # noqa: we just need to have a builtin inside this module to test it properly



