





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

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



class 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     int       			=      '''blip_2_vision_model'''






			def __init__(self					,							__magic_name__=1408					,							__magic_name__=6144					,							__magic_name__=39					,							__magic_name__=16					,							__magic_name__=224					,							__magic_name__=14					,							__magic_name__="gelu"					,							__magic_name__=0.00_001					,							__magic_name__=0.0					,							__magic_name__=1e-10					,							__magic_name__=True					,							**__magic_name__					,							)     ->   List[str]:


							'''simple docstring'''



							super().__init__(**__magic_name__    )

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






			@classmethod
			def 			lowerCamelCase  (cls					,							__magic_name__					,							**__magic_name__    )     ->   "PretrainedConfig":


							'''simple docstring'''



							cls._set_token_in_kwargs(__magic_name__    )

							snake_case_			,							snake_case_						:    List[str]				=  cls.get_config_dict(__magic_name__					,							**__magic_name__    )

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




class 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     List[Any]       			=      '''blip_2_qformer'''






			def __init__(self					,							__magic_name__=3_0522					,							__magic_name__=768					,							__magic_name__=12					,							__magic_name__=12					,							__magic_name__=3072					,							__magic_name__="gelu"					,							__magic_name__=0.1					,							__magic_name__=0.1					,							__magic_name__=512					,							__magic_name__=0.02					,							__magic_name__=1e-12					,							__magic_name__=0					,							__magic_name__="absolute"					,							__magic_name__=2					,							__magic_name__=1408					,							**__magic_name__					,							)     ->   Dict:


							'''simple docstring'''



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

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






			@classmethod
			def 			lowerCamelCase  (cls					,							__magic_name__					,							**__magic_name__    )     ->   "PretrainedConfig":


							'''simple docstring'''



							cls._set_token_in_kwargs(__magic_name__    )

							snake_case_			,							snake_case_						:    Optional[Any]				=  cls.get_config_dict(__magic_name__					,							**__magic_name__    )

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




class 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     Any       			=      '''blip-2'''
			lowerCamelCase_     :     List[str]       			=      True






			def __init__(self					,							__magic_name__=None					,							__magic_name__=None					,							__magic_name__=None					,							__magic_name__=32					,							**__magic_name__    )     ->   Optional[int]:


							'''simple docstring'''



							super().__init__(**__magic_name__    )

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

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

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

							snake_case_						:    Optional[int]				=  BlipaVisionConfig(**__magic_name__    )
							snake_case_						:    Dict				=  BlipaQFormerConfig(**__magic_name__    )
							snake_case_						:    int				=  text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
							snake_case_						:    Optional[Any]				=  CONFIG_MAPPING[text_model_type](**__magic_name__    )

							snake_case_						:    Any				=  self.text_config.tie_word_embeddings
							snake_case_						:    str				=  self.text_config.is_encoder_decoder

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






			@classmethod
			def 			lowerCamelCase  (cls					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							**__magic_name__					,							)     ->   List[Any]:


							'''simple docstring'''



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






			def 			lowerCamelCase  (self    )     ->   Optional[Any]:


							'''simple docstring'''



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







from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase_    =				logging.get_logger(__name__)

lowerCAmelCase_    =				{
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}



class 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     Any       			=      '''megatron-bert'''






			def __init__(self					,							__magic_name__=2_9056					,							__magic_name__=1024					,							__magic_name__=24					,							__magic_name__=16					,							__magic_name__=4096					,							__magic_name__="gelu"					,							__magic_name__=0.1					,							__magic_name__=0.1					,							__magic_name__=512					,							__magic_name__=2					,							__magic_name__=0.02					,							__magic_name__=1e-12					,							__magic_name__=0					,							__magic_name__="absolute"					,							__magic_name__=True					,							**__magic_name__					,							)     ->   Any:


							'''simple docstring'''



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

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