
'''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 	snake_case__       (      __SCREAMING_SNAKE_CASE					):







		"""simple docstring"""

		lowerCamelCase     							=						"""blip_2_vision_model"""



		def __init__(      self				:			List[Any]  ,	UpperCamelCase__				:			int=1408  ,	UpperCamelCase__				:			Optional[Any]=6144  ,	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.00_001  ,	UpperCamelCase__				:			Optional[int]=0.0  ,	UpperCamelCase__				:			List[Any]=1e-1_0  ,	UpperCamelCase__				:			Dict=True  ,	**UpperCamelCase__				:			int  ,	)						->			Union[str, Any]:






				"""simple docstring"""







				super().__init__(**UpperCamelCase__      )

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



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






				"""simple docstring"""







				cls._set_token_in_kwargs(UpperCamelCase__      )

				snake_case			,snake_case  :       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":
						snake_case  :       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 	snake_case__       (      __SCREAMING_SNAKE_CASE					):







		"""simple docstring"""

		lowerCamelCase     							=						"""blip_2_qformer"""



		def __init__(      self				:			Tuple  ,	UpperCamelCase__				:			int=3_0522  ,	UpperCamelCase__				:			str=768  ,	UpperCamelCase__				:			Dict=12  ,	UpperCamelCase__				:			str=12  ,	UpperCamelCase__				:			Optional[int]=3072  ,	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=1408  ,	**UpperCamelCase__				:			Union[str, Any]  ,	)						->			Optional[int]:






				"""simple docstring"""







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

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



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






				"""simple docstring"""







				cls._set_token_in_kwargs(UpperCamelCase__      )

				snake_case			,snake_case  :       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":
						snake_case  :       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 	snake_case__       (      __SCREAMING_SNAKE_CASE					):







		"""simple docstring"""

		lowerCamelCase     							=						"""blip-2"""
		lowerCamelCase     							=						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:
						snake_case  :       Tuple     			=						{}
						logger.info('''vision_config is None. initializing the Blip2VisionConfig with default values.'''      )

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

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

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

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

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



		@classmethod
		def       lowerCAmelCase				(      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       lowerCAmelCase				(      self				:			str      )						->			Dict:






				"""simple docstring"""







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




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

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowercase__						       =      {
    "configuration_poolformer": [
        "POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "PoolFormerConfig",
        "PoolFormerOnnxConfig",
    ]
}

try:
						if not is_vision_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowercase__						       =      ["PoolFormerFeatureExtractor"]
						lowercase__						       =      ["PoolFormerImageProcessor"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowercase__						       =      [
						    "POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "PoolFormerForImageClassification",
						    "PoolFormerModel",
						    "PoolFormerPreTrainedModel",
						]


if TYPE_CHECKING:
						from .configuration_poolformer import (
						    POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    PoolFormerConfig,
						    PoolFormerOnnxConfig,
						)

						try:
												if not is_vision_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .feature_extraction_poolformer import PoolFormerFeatureExtractor
												from .image_processing_poolformer import PoolFormerImageProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_poolformer import (
												    POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    PoolFormerForImageClassification,
												    PoolFormerModel,
												    PoolFormerPreTrainedModel,
												)


else:
						import sys

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


