
'''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			:  int   							=	logging.get_logger(__name__)

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






class 			lowerCAmelCase__       (  a_					):
     lowerCAmelCase_					       =					'''blip_2_vision_model'''






     def __init__(       self    ,							__SCREAMING_SNAKE_CASE=14_08    ,							__SCREAMING_SNAKE_CASE=61_44    ,							__SCREAMING_SNAKE_CASE=39    ,							__SCREAMING_SNAKE_CASE=16    ,							__SCREAMING_SNAKE_CASE=2_24    ,							__SCREAMING_SNAKE_CASE=14    ,							__SCREAMING_SNAKE_CASE="gelu"    ,							__SCREAMING_SNAKE_CASE=0.00_001    ,							__SCREAMING_SNAKE_CASE=0.0    ,							__SCREAMING_SNAKE_CASE=1E-1_0    ,							__SCREAMING_SNAKE_CASE=True    ,							**__SCREAMING_SNAKE_CASE    ,							):


           """simple docstring"""





           super().__init__(**lowercase_		)

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






     @classmethod
     def      _snake_case   (       cls    ,							__SCREAMING_SNAKE_CASE    ,							**__SCREAMING_SNAKE_CASE		):


           """simple docstring"""





           cls._set_token_in_kwargs(lowercase_		)

           lowercase_						,			lowercase_     :					Optional[int]													=	cls.get_config_dict(lowercase_    ,							**lowercase_		)

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







class 			lowerCAmelCase__       (  a_					):
     lowerCAmelCase_					       =					'''blip_2_qformer'''






     def __init__(       self    ,							__SCREAMING_SNAKE_CASE=3_05_22    ,							__SCREAMING_SNAKE_CASE=7_68    ,							__SCREAMING_SNAKE_CASE=12    ,							__SCREAMING_SNAKE_CASE=12    ,							__SCREAMING_SNAKE_CASE=30_72    ,							__SCREAMING_SNAKE_CASE="gelu"    ,							__SCREAMING_SNAKE_CASE=0.1    ,							__SCREAMING_SNAKE_CASE=0.1    ,							__SCREAMING_SNAKE_CASE=5_12    ,							__SCREAMING_SNAKE_CASE=0.02    ,							__SCREAMING_SNAKE_CASE=1E-1_2    ,							__SCREAMING_SNAKE_CASE=0    ,							__SCREAMING_SNAKE_CASE="absolute"    ,							__SCREAMING_SNAKE_CASE=2    ,							__SCREAMING_SNAKE_CASE=14_08    ,							**__SCREAMING_SNAKE_CASE    ,							):


           """simple docstring"""





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

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






     @classmethod
     def      _snake_case   (       cls    ,							__SCREAMING_SNAKE_CASE    ,							**__SCREAMING_SNAKE_CASE		):


           """simple docstring"""





           cls._set_token_in_kwargs(lowercase_		)

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

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







class 			lowerCAmelCase__       (  a_					):
     lowerCAmelCase_					       =					'''blip-2'''
     lowerCAmelCase_					       =					True






     def __init__(       self    ,							__SCREAMING_SNAKE_CASE=None    ,							__SCREAMING_SNAKE_CASE=None    ,							__SCREAMING_SNAKE_CASE=None    ,							__SCREAMING_SNAKE_CASE=32    ,							**__SCREAMING_SNAKE_CASE		):


           """simple docstring"""





           super().__init__(**lowercase_		)

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

           if qformer_config is None:
                 lowercase_     :					List[Any]													=	{}
                 logger.info('''qformer_config is None. Initializing the Blip2QFormerConfig with default values.'''		)

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

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

           lowercase_     :					Dict													=	self.text_config.tie_word_embeddings
           lowercase_     :					List[str]													=	self.text_config.is_encoder_decoder

           lowercase_     :					Optional[Any]													=	num_query_tokens
           lowercase_     :					str													=	self.vision_config.hidden_size
           lowercase_     :					List[str]													=	self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
           lowercase_     :					Any													=	1.0
           lowercase_     :					Optional[Any]													=	0.02






     @classmethod
     def      _snake_case   (       cls    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							**__SCREAMING_SNAKE_CASE    ,							):


           """simple docstring"""





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






     def      _snake_case   (       self		):


           """simple docstring"""





           lowercase_     :					Any													=	copy.deepcopy(self.__dict__		)
           lowercase_     :					Tuple													=	self.vision_config.to_dict()
           lowercase_     :					int													=	self.qformer_config.to_dict()
           lowercase_     :					Tuple													=	self.text_config.to_dict()
           lowercase_     :					int													=	self.__class__.model_type
           return output





'''simple docstring'''







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


_lowercase			:  Any   							=	logging.get_logger(__name__)

_lowercase			:  Dict   							=	{
    "EleutherAI/gpt-neox-20b": "https://huggingface.co/EleutherAI/gpt-neox-20b/resolve/main/config.json",
    # See all GPTNeoX models at https://huggingface.co/models?filter=gpt_neox
}






class 			lowerCAmelCase__       (  lowerCamelCase_					):
					lowerCAmelCase_					       =					'''gpt_neox'''






					def __init__(       self    ,							__SCREAMING_SNAKE_CASE=5_04_32    ,							__SCREAMING_SNAKE_CASE=61_44    ,							__SCREAMING_SNAKE_CASE=44    ,							__SCREAMING_SNAKE_CASE=64    ,							__SCREAMING_SNAKE_CASE=2_45_76    ,							__SCREAMING_SNAKE_CASE="gelu"    ,							__SCREAMING_SNAKE_CASE=0.25    ,							__SCREAMING_SNAKE_CASE=1_00_00    ,							__SCREAMING_SNAKE_CASE=0.0    ,							__SCREAMING_SNAKE_CASE=0.0    ,							__SCREAMING_SNAKE_CASE=0.1    ,							__SCREAMING_SNAKE_CASE=20_48    ,							__SCREAMING_SNAKE_CASE=0.02    ,							__SCREAMING_SNAKE_CASE=1E-5    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=0    ,							__SCREAMING_SNAKE_CASE=2    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=None    ,							**__SCREAMING_SNAKE_CASE    ,							):


											"""simple docstring"""





											super().__init__(bos_token_id=__SCREAMING_SNAKE_CASE    ,							eos_token_id=__SCREAMING_SNAKE_CASE    ,							**__SCREAMING_SNAKE_CASE		)
											lowercase_     :					Optional[Any]													=	vocab_size
											lowercase_     :					Optional[Any]													=	max_position_embeddings
											lowercase_     :					Optional[int]													=	hidden_size
											lowercase_     :					Tuple													=	num_hidden_layers
											lowercase_     :					Any													=	num_attention_heads
											lowercase_     :					str													=	intermediate_size
											lowercase_     :					Any													=	hidden_act
											lowercase_     :					Tuple													=	rotary_pct
											lowercase_     :					Optional[Any]													=	rotary_emb_base
											lowercase_     :					Any													=	attention_dropout
											lowercase_     :					str													=	hidden_dropout
											lowercase_     :					Dict													=	classifier_dropout
											lowercase_     :					Tuple													=	initializer_range
											lowercase_     :					List[str]													=	layer_norm_eps
											lowercase_     :					Union[str, Any]													=	use_cache
											lowercase_     :					int													=	tie_word_embeddings
											lowercase_     :					Tuple													=	use_parallel_residual
											lowercase_     :					Optional[Any]													=	rope_scaling
											self._rope_scaling_validation()

											if self.hidden_size % self.num_attention_heads != 0:
																	raise ValueError(
																	    '''The hidden size is not divisble by the number of attention heads! Make sure to update them!'''		)






					def      _snake_case   (       self		):


											"""simple docstring"""





											if self.rope_scaling is None:
																	return

											if not isinstance(self.rope_scaling    ,							__SCREAMING_SNAKE_CASE		) or len(self.rope_scaling		) != 2:
																	raise ValueError(
																	    '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
																	    F'''got {self.rope_scaling}'''		)
											lowercase_     :					List[Any]													=	self.rope_scaling.get('''type'''    ,							__SCREAMING_SNAKE_CASE		)
											lowercase_     :					int													=	self.rope_scaling.get('''factor'''    ,							__SCREAMING_SNAKE_CASE		)
											if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
																	raise ValueError(
																	    F'''`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'''		)
											if rope_scaling_factor is None or not isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) or rope_scaling_factor <= 1.0:
																	raise ValueError(F'''`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'''		)



