


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      :					Optional[int]    							=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 			_lowercase (     SCREAMING_SNAKE_CASE_			):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__							:     Dict         =						'''blip_2_vision_model'''


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

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



				@classmethod
				def 						__magic_name__(			cls     :Union[str, Any]     ,     lowerCAmelCase__     :Union[str, os.PathLike]     ,     **lowerCAmelCase__     :Union[str, Any]      )						->     "PretrainedConfig":
										cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE      )

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

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




class 			_lowercase (     SCREAMING_SNAKE_CASE_			):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__							:     Optional[Any]         =						'''blip_2_qformer'''


				def __init__(			self     :int     ,     lowerCAmelCase__     :int=30_522     ,     lowerCAmelCase__     :List[Any]=768     ,     lowerCAmelCase__     :Any=12     ,     lowerCAmelCase__     :List[Any]=12     ,     lowerCAmelCase__     :List[Any]=3_072     ,     lowerCAmelCase__     :int="gelu"     ,     lowerCAmelCase__     :Optional[int]=0.1     ,     lowerCAmelCase__     :Union[str, Any]=0.1     ,     lowerCAmelCase__     :List[Any]=512     ,     lowerCAmelCase__     :Tuple=0.02     ,     lowerCAmelCase__     :str=1E-1_2     ,     lowerCAmelCase__     :Optional[Any]=0     ,     lowerCAmelCase__     :int="absolute"     ,     lowerCAmelCase__     :Optional[Any]=2     ,     lowerCAmelCase__     :Tuple=1_408     ,     **lowerCAmelCase__     :List[str]     ,     )						->     Optional[Any]:
										super().__init__(pad_token_id=__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE      )

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



				@classmethod
				def 						__magic_name__(			cls     :Optional[Any]     ,     lowerCAmelCase__     :Union[str, os.PathLike]     ,     **lowerCAmelCase__     :int      )						->     "PretrainedConfig":
										cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE      )

										__SCREAMING_SNAKE_CASE		:	int						     =						cls.get_config_dict(__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE      )

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




class 			_lowercase (     SCREAMING_SNAKE_CASE_			):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__							:     Dict         =						'''blip-2'''
				SCREAMING_SNAKE_CASE__							:     Any         =						True


				def __init__(			self     :Optional[Any]     ,     lowerCAmelCase__     :Any=None     ,     lowerCAmelCase__     :List[Any]=None     ,     lowerCAmelCase__     :Dict=None     ,     lowerCAmelCase__     :int=32     ,     **lowerCAmelCase__     :int      )						->     List[str]:
										super().__init__(**__SCREAMING_SNAKE_CASE      )

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

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

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

										__SCREAMING_SNAKE_CASE		:	List[str]						     =						BlipaVisionConfig(**__SCREAMING_SNAKE_CASE      )
										__SCREAMING_SNAKE_CASE		:	str						     =						BlipaQFormerConfig(**__SCREAMING_SNAKE_CASE      )
										__SCREAMING_SNAKE_CASE		:	int						     =						text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						CONFIG_MAPPING[text_model_type](**__SCREAMING_SNAKE_CASE      )

										__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						self.text_config.tie_word_embeddings
										__SCREAMING_SNAKE_CASE		:	Any						     =						self.text_config.is_encoder_decoder

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


				@classmethod
				def 						__magic_name__(			cls     :Optional[Any]     ,     lowerCAmelCase__     :BlipaVisionConfig     ,     lowerCAmelCase__     :BlipaQFormerConfig     ,     lowerCAmelCase__     :PretrainedConfig     ,     **lowerCAmelCase__     :Dict     ,     )						->     Optional[int]:
										return cls(
										    vision_config=vision_config.to_dict()     ,     qformer_config=qformer_config.to_dict()     ,     text_config=text_config.to_dict()     ,     **__SCREAMING_SNAKE_CASE     ,     )



				def 						__magic_name__(			self     :Any      )						->     Tuple:
										__SCREAMING_SNAKE_CASE		:	Dict						     =						copy.deepcopy(self.__dict__      )
										__SCREAMING_SNAKE_CASE		:	Any						     =						self.vision_config.to_dict()
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						self.qformer_config.to_dict()
										__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						self.text_config.to_dict()
										__SCREAMING_SNAKE_CASE		:	Optional[Any]						     =						self.__class__.model_type
										return output








'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase									=   {'configuration_sew': ['SEW_PRETRAINED_CONFIG_ARCHIVE_MAP', 'SEWConfig']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase									=   [
		    'SEW_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'SEWForCTC',
		    'SEWForSequenceClassification',
		    'SEWModel',
		    'SEWPreTrainedModel',
		]

if TYPE_CHECKING:
		from .configuration_sew import SEW_PRETRAINED_CONFIG_ARCHIVE_MAP, SEWConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_sew import (
				    SEW_PRETRAINED_MODEL_ARCHIVE_LIST,
				    SEWForCTC,
				    SEWForSequenceClassification,
				    SEWModel,
				    SEWPreTrainedModel,
				)


else:
		import sys

		__lowerCAmelCase									=   _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




