


"""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[str]									=  {
    """salesforce/blip2-opt-2.7b""": """https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json""",
}






class       __A				(       _SCREAMING_SNAKE_CASE			):






 """simple docstring"""




 __lowerCAmelCase 					=  "blip_2_vision_model"


 def __init__(		self ,    __A=1408 ,    __A=6144 ,    __A=39 ,    __A=16 ,    __A=224 ,    __A=14 ,    __A="gelu" ,    __A=0.00_001 ,    __A=0.0 ,    __A=1E-1_0 ,    __A=True ,    **__A ,    )					->     Any:
     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       SCREAMING_SNAKE_CASE							(		cls ,    __A ,    **__A						)					->     "PretrainedConfig":
     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				(       _SCREAMING_SNAKE_CASE			):






 """simple docstring"""




 __lowerCAmelCase 					=  "blip_2_qformer"


 def __init__(		self ,    __A=3_0522 ,    __A=768 ,    __A=12 ,    __A=12 ,    __A=3072 ,    __A="gelu" ,    __A=0.1 ,    __A=0.1 ,    __A=512 ,    __A=0.02 ,    __A=1E-1_2 ,    __A=0 ,    __A="absolute" ,    __A=2 ,    __A=1408 ,    **__A ,    )					->     Dict:
     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       SCREAMING_SNAKE_CASE							(		cls ,    __A ,    **__A						)					->     "PretrainedConfig":
     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				(       _SCREAMING_SNAKE_CASE			):






 """simple docstring"""




 __lowerCAmelCase 					=  "blip-2"
 __lowerCAmelCase 					=  True


 def __init__(		self ,    __A=None ,    __A=None ,    __A=None ,    __A=32 ,    **__A						)					->     int:
     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       SCREAMING_SNAKE_CASE							(		cls ,    __A ,    __A ,    __A ,    **__A ,    )					->     Any:
     return cls(
         vision_config=vision_config.to_dict() ,    qformer_config=qformer_config.to_dict() ,    text_config=text_config.to_dict() ,    **__A ,    )





 def       SCREAMING_SNAKE_CASE							(		self						)					->     Tuple:
     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


from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


a__				=		logging.get_logger(__name__)

a__				=		{
    '''google/bit-50''': '''https://huggingface.co/google/bit-50/resolve/main/config.json''',
}

class 				UpperCAmelCase_		(			__lowercase				,       __lowercase   ):
							"""simple docstring"""







							UpperCAmelCase__       :						Any	    =    "bit"
							UpperCAmelCase__       :						Optional[int]	    =    ["preactivation", "bottleneck"]
							UpperCAmelCase__       :						Optional[Any]	    =    ["SAME", "VALID"]


							def __init__(			self       ,							_a=3       ,							_a=6_4       ,							_a=[2_5_6, 5_1_2, 1_0_2_4, 2_0_4_8]       ,							_a=[3, 4, 6, 3]       ,							_a="preactivation"       ,							_a="relu"       ,							_a=None       ,							_a=3_2       ,							_a=0.0       ,							_a=False       ,							_a=3_2       ,							_a=1       ,							_a=None       ,							_a=None       ,							**_a       ,							)    ->    Union[str, Any]:
												super().__init__(**_a       )
												if layer_type not in self.layer_types:
																	raise ValueError(F"""layer_type={layer_type} is not one of {','.join(self.layer_types       )}"""       )
												if global_padding is not None:
																	if global_padding.upper() in self.supported_padding:
																						_a	:    Any         =		global_padding.upper()
																	else:
																						raise ValueError(F"""Padding strategy {global_padding} not supported"""       )
												_a	:    Optional[int]         =		num_channels
												_a	:    List[Any]         =		embedding_size
												_a	:    Any         =		hidden_sizes
												_a	:    int         =		depths
												_a	:    Dict         =		layer_type
												_a	:    int         =		hidden_act
												_a	:    Optional[Any]         =		global_padding
												_a	:    Optional[Any]         =		num_groups
												_a	:    Union[str, Any]         =		drop_path_rate
												_a	:    Tuple         =		embedding_dynamic_padding
												_a	:    Union[str, Any]         =		output_stride
												_a	:    Any         =		width_factor

												_a	:    Any         =		['''stem'''] + [F"""stage{idx}""" for idx in range(1       ,							len(_a       ) + 1       )]
												_a      ,					_a	:    List[str]         =		get_aligned_output_features_output_indices(
												    out_features=_a       ,							out_indices=_a       ,							stage_names=self.stage_names       )



