






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


__lowerCamelCase						:    Dict     				=  logging.get_logger(__name__)

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



class   lowerCAmelCase__ ( __SCREAMING_SNAKE_CASE  ):
			A     				= "blip_2_vision_model"

			def __init__(					self					:		List[Any]     ,		UpperCamelCase_					:		int=1_408     ,		UpperCamelCase_					:		Optional[Any]=6_144     ,		UpperCamelCase_					:		Union[str, Any]=39     ,		UpperCamelCase_					:		Union[str, Any]=16     ,		UpperCamelCase_					:		Union[str, Any]=224     ,		UpperCamelCase_					:		Dict=14     ,		UpperCamelCase_					:		Any="gelu"     ,		UpperCamelCase_					:		List[Any]=0.0_0001     ,		UpperCamelCase_					:		Optional[int]=0.0     ,		UpperCamelCase_					:		List[Any]=1e-1_0     ,		UpperCamelCase_					:		Dict=True     ,		**UpperCamelCase_					:		int     ,		) ->  Union[str, Any]:







				"""simple docstring"""






				super().__init__(**UpperCamelCase__	)

				lowerCamelCase_					:  int						=    hidden_size
				lowerCamelCase_					:  Any						=    intermediate_size
				lowerCamelCase_					:  Union[str, Any]						=    num_hidden_layers
				lowerCamelCase_					:  int						=    num_attention_heads
				lowerCamelCase_					:  int						=    patch_size
				lowerCamelCase_					:  Any						=    image_size
				lowerCamelCase_					:  Dict						=    initializer_range
				lowerCamelCase_					:  str						=    attention_dropout
				lowerCamelCase_					:  Optional[int]						=    layer_norm_eps
				lowerCamelCase_					:  List[Any]						=    hidden_act
				lowerCamelCase_					:  Dict						=    qkv_bias





			@classmethod
			def 						__UpperCamelCase				(					cls					:		Optional[int]     ,		UpperCamelCase_					:		Union[str, os.PathLike]     ,		**UpperCamelCase_					:		Tuple	) ->  "PretrainedConfig":







				"""simple docstring"""






				cls._set_token_in_kwargs(UpperCamelCase__	)

				lowerCamelCase_					:  List[str]						=    cls.get_config_dict(UpperCamelCase__     ,		**UpperCamelCase__	)

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






class   lowerCAmelCase__ ( __SCREAMING_SNAKE_CASE  ):
			A     				= "blip_2_qformer"

			def __init__(					self					:		Tuple     ,		UpperCamelCase_					:		int=30_522     ,		UpperCamelCase_					:		str=768     ,		UpperCamelCase_					:		Dict=12     ,		UpperCamelCase_					:		str=12     ,		UpperCamelCase_					:		Optional[int]=3_072     ,		UpperCamelCase_					:		int="gelu"     ,		UpperCamelCase_					:		Union[str, Any]=0.1     ,		UpperCamelCase_					:		str=0.1     ,		UpperCamelCase_					:		Union[str, Any]=512     ,		UpperCamelCase_					:		Tuple=0.02     ,		UpperCamelCase_					:		str=1e-1_2     ,		UpperCamelCase_					:		Optional[Any]=0     ,		UpperCamelCase_					:		Any="absolute"     ,		UpperCamelCase_					:		Dict=2     ,		UpperCamelCase_					:		Any=1_408     ,		**UpperCamelCase_					:		Union[str, Any]     ,		) ->  Optional[int]:







				"""simple docstring"""






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

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





			@classmethod
			def 						__UpperCamelCase				(					cls					:		int     ,		UpperCamelCase_					:		Union[str, os.PathLike]     ,		**UpperCamelCase_					:		Union[str, Any]	) ->  "PretrainedConfig":







				"""simple docstring"""






				cls._set_token_in_kwargs(UpperCamelCase__	)

				lowerCamelCase_					:  List[Any]						=    cls.get_config_dict(UpperCamelCase__     ,		**UpperCamelCase__	)

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






class   lowerCAmelCase__ ( __SCREAMING_SNAKE_CASE  ):
			A     				= "blip-2"
			A     				= True

			def __init__(					self					:		Union[str, Any]     ,		UpperCamelCase_					:		int=None     ,		UpperCamelCase_					:		List[Any]=None     ,		UpperCamelCase_					:		int=None     ,		UpperCamelCase_					:		Optional[Any]=32     ,		**UpperCamelCase_					:		Optional[Any]	) ->  Dict:







				"""simple docstring"""






				super().__init__(**UpperCamelCase__	)

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

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

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

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

				lowerCamelCase_					:  Tuple						=    self.text_config.tie_word_embeddings
				lowerCamelCase_					:  Union[str, Any]						=    self.text_config.is_encoder_decoder

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

			@classmethod
			def 						__UpperCamelCase				(					cls					:		int     ,		UpperCamelCase_					:		BlipaVisionConfig     ,		UpperCamelCase_					:		BlipaQFormerConfig     ,		UpperCamelCase_					:		PretrainedConfig     ,		**UpperCamelCase_					:		Union[str, Any]     ,		) ->  str:







				"""simple docstring"""






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





			def 						__UpperCamelCase				(					self					:		str	) ->  Dict:







				"""simple docstring"""






				lowerCamelCase_					:  Dict						=    copy.deepcopy(self.__dict__	)
				lowerCamelCase_					:  Optional[int]						=    self.vision_config.to_dict()
				lowerCamelCase_					:  Union[str, Any]						=    self.qformer_config.to_dict()
				lowerCamelCase_					:  Optional[int]						=    self.text_config.to_dict()
				lowerCamelCase_					:  Optional[int]						=    self.__class__.model_type
				return output








'''simple docstring'''
from typing import TYPE_CHECKING

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


lowercase__						       =      {"configuration_encoder_decoder": ["EncoderDecoderConfig"]}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowercase__						       =      ["EncoderDecoderModel"]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowercase__						       =      ["TFEncoderDecoderModel"]

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowercase__						       =      ["FlaxEncoderDecoderModel"]

if TYPE_CHECKING:
						from .configuration_encoder_decoder import EncoderDecoderConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_encoder_decoder import EncoderDecoderModel

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_encoder_decoder import TFEncoderDecoderModel

						try:
												if not is_flax_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_flax_encoder_decoder import FlaxEncoderDecoderModel

else:
						import sys

						lowercase__						       =      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


