






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


__a:     str   					=					logging.get_logger(__name__)

__a:     Union[str, Any]   					=					{
    '''salesforce/blip2-opt-2.7b''': '''https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json''',
}
class 		SCREAMING_SNAKE_CASE__	(  UpperCAmelCase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blip_2_vision_model'''


  def __init__(      self		:			str       ,				lowerCamelCase		:			Optional[int]=1408       ,				lowerCamelCase		:			List[str]=6144       ,				lowerCamelCase		:			int=39       ,				lowerCamelCase		:			Optional[Any]=16       ,				lowerCamelCase		:			List[Any]=224       ,				lowerCamelCase		:			Dict=14       ,				lowerCamelCase		:			List[str]="gelu"       ,				lowerCamelCase		:			List[str]=0.0_0001       ,				lowerCamelCase		:			Optional[Any]=0.0       ,				lowerCamelCase		:			Union[str, Any]=1E-10       ,				lowerCamelCase		:			List[Any]=True       ,				**lowerCamelCase		:			Tuple       ,				)						->	str:


         """simple docstring"""
         super().__init__(**lowerCamelCase							)

         _UpperCAmelCase							=    hidden_size
         _UpperCAmelCase							=    intermediate_size
         _UpperCAmelCase							=    num_hidden_layers
         _UpperCAmelCase							=    num_attention_heads
         _UpperCAmelCase							=    patch_size
         _UpperCAmelCase							=    image_size
         _UpperCAmelCase							=    initializer_range
         _UpperCAmelCase							=    attention_dropout
         _UpperCAmelCase							=    layer_norm_eps
         _UpperCAmelCase							=    hidden_act
         _UpperCAmelCase							=    qkv_bias





  @classmethod
  def  lowerCamelCase       (      cls		:			Optional[Any]       ,				lowerCamelCase		:			Union[str, os.PathLike]       ,				**lowerCamelCase		:			Dict							)						->	"PretrainedConfig":


         """simple docstring"""
         cls._set_token_in_kwargs(lowerCamelCase							)

         _UpperCAmelCase	,			_UpperCAmelCase							=    cls.get_config_dict(lowerCamelCase       ,				**lowerCamelCase							)

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



class 		SCREAMING_SNAKE_CASE__	(  UpperCAmelCase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blip_2_qformer'''


  def __init__(      self		:			List[Any]       ,				lowerCamelCase		:			List[Any]=3_0522       ,				lowerCamelCase		:			str=768       ,				lowerCamelCase		:			Optional[Any]=12       ,				lowerCamelCase		:			List[str]=12       ,				lowerCamelCase		:			str=3072       ,				lowerCamelCase		:			Union[str, Any]="gelu"       ,				lowerCamelCase		:			Union[str, Any]=0.1       ,				lowerCamelCase		:			Optional[Any]=0.1       ,				lowerCamelCase		:			Optional[Any]=512       ,				lowerCamelCase		:			List[Any]=0.02       ,				lowerCamelCase		:			List[Any]=1E-12       ,				lowerCamelCase		:			Optional[Any]=0       ,				lowerCamelCase		:			Optional[int]="absolute"       ,				lowerCamelCase		:			List[Any]=2       ,				lowerCamelCase		:			Optional[Any]=1408       ,				**lowerCamelCase		:			List[str]       ,				)						->	str:


         """simple docstring"""
         super().__init__(pad_token_id=lowerCamelCase       ,				**lowerCamelCase							)

         _UpperCAmelCase							=    vocab_size
         _UpperCAmelCase							=    hidden_size
         _UpperCAmelCase							=    num_hidden_layers
         _UpperCAmelCase							=    num_attention_heads
         _UpperCAmelCase							=    hidden_act
         _UpperCAmelCase							=    intermediate_size
         _UpperCAmelCase							=    hidden_dropout_prob
         _UpperCAmelCase							=    attention_probs_dropout_prob
         _UpperCAmelCase							=    max_position_embeddings
         _UpperCAmelCase							=    initializer_range
         _UpperCAmelCase							=    layer_norm_eps
         _UpperCAmelCase							=    position_embedding_type
         _UpperCAmelCase							=    cross_attention_frequency
         _UpperCAmelCase							=    encoder_hidden_size





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


         """simple docstring"""
         cls._set_token_in_kwargs(lowerCamelCase							)

         _UpperCAmelCase	,			_UpperCAmelCase							=    cls.get_config_dict(lowerCamelCase       ,				**lowerCamelCase							)

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



class 		SCREAMING_SNAKE_CASE__	(  UpperCAmelCase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blip-2'''
  _lowerCamelCase    =  True


  def __init__(      self		:			Optional[Any]       ,				lowerCamelCase		:			str=None       ,				lowerCamelCase		:			Optional[Any]=None       ,				lowerCamelCase		:			str=None       ,				lowerCamelCase		:			Optional[Any]=32       ,				**lowerCamelCase		:			Tuple							)						->	Optional[int]:


         """simple docstring"""
         super().__init__(**lowerCamelCase							)

         if vision_config is None:
                _UpperCAmelCase							=    {}
                logger.info("""vision_config is None. initializing the Blip2VisionConfig with default values."""							)

         if qformer_config is None:
                _UpperCAmelCase							=    {}
                logger.info("""qformer_config is None. Initializing the Blip2QFormerConfig with default values."""							)

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

         _UpperCAmelCase							=    BlipaVisionConfig(**lowerCamelCase							)
         _UpperCAmelCase							=    BlipaQFormerConfig(**lowerCamelCase							)
         _UpperCAmelCase							=    text_config["""model_type"""] if """model_type""" in text_config else """opt"""
         _UpperCAmelCase							=    CONFIG_MAPPING[text_model_type](**lowerCamelCase							)

         _UpperCAmelCase							=    self.text_config.tie_word_embeddings
         _UpperCAmelCase							=    self.text_config.is_encoder_decoder

         _UpperCAmelCase							=    num_query_tokens
         _UpperCAmelCase							=    self.vision_config.hidden_size
         _UpperCAmelCase							=    self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
         _UpperCAmelCase							=    1.0
         _UpperCAmelCase							=    0.02


  @classmethod
  def  lowerCamelCase       (      cls		:			List[Any]       ,				lowerCamelCase		:			BlipaVisionConfig       ,				lowerCamelCase		:			BlipaQFormerConfig       ,				lowerCamelCase		:			PretrainedConfig       ,				**lowerCamelCase		:			Union[str, Any]       ,				)						->	Dict:


         """simple docstring"""
         return cls(
             vision_config=vision_config.to_dict()       ,				qformer_config=qformer_config.to_dict()       ,				text_config=text_config.to_dict()       ,				**lowerCamelCase       ,				)





  def  lowerCamelCase       (      self		:			int							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    copy.deepcopy(self.__dict__							)
         _UpperCAmelCase							=    self.vision_config.to_dict()
         _UpperCAmelCase							=    self.qformer_config.to_dict()
         _UpperCAmelCase							=    self.text_config.to_dict()
         _UpperCAmelCase							=    self.__class__.model_type
         return output





'''simple docstring'''







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


lowercase      :   Tuple      =       logging.get_logger(__name__)

lowercase      :   Dict      =       {
    """ut/deta""": """https://huggingface.co/ut/deta/resolve/main/config.json""",
}







class 					_a (a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     str          =					"""deta"""
     lowerCAmelCase_  :     Any          =					{
         """hidden_size""": """d_model""",
         """num_attention_heads""": """encoder_attention_heads""",
     }







     def __init__(				self							,__a=None							,__a=900							,__a=2_048							,__a=6							,__a=2_048							,__a=8							,__a=6							,__a=1_024							,__a=8							,__a=0.0							,__a=True							,__a="relu"							,__a=256							,__a=0.1							,__a=0.0							,__a=0.0							,__a=0.02							,__a=1.0							,__a=True							,__a=False							,__a="sine"							,__a=5							,__a=4							,__a=4							,__a=True							,__a=300							,__a=True							,__a=True							,__a=1							,__a=5							,__a=2							,__a=1							,__a=1							,__a=5							,__a=2							,__a=0.1							,__a=0.25							,**__a							,)      ->				int:
          if backbone_config is None:
               logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""							)
               snake_case			:      int        =			CONFIG_MAPPING["""resnet"""](out_features=["""stage2""", """stage3""", """stage4"""]							)
          else:
               if isinstance(__a							,__a							):
                    snake_case			:      str        =			backbone_config.pop("""model_type"""							)
                    snake_case			:      Optional[Any]        =			CONFIG_MAPPING[backbone_model_type]
                    snake_case			:      List[Any]        =			config_class.from_dict(__a							)

          snake_case			:      Any        =			backbone_config
          snake_case			:      Optional[Any]        =			num_queries
          snake_case			:      Dict        =			max_position_embeddings
          snake_case			:      int        =			d_model
          snake_case			:      str        =			encoder_ffn_dim
          snake_case			:      Dict        =			encoder_layers
          snake_case			:      List[Any]        =			encoder_attention_heads
          snake_case			:      int        =			decoder_ffn_dim
          snake_case			:      List[Any]        =			decoder_layers
          snake_case			:      Dict        =			decoder_attention_heads
          snake_case			:      Dict        =			dropout
          snake_case			:      Dict        =			attention_dropout
          snake_case			:      List[Any]        =			activation_dropout
          snake_case			:      Dict        =			activation_function
          snake_case			:      List[Any]        =			init_std
          snake_case			:      Any        =			init_xavier_std
          snake_case			:      List[Any]        =			encoder_layerdrop
          snake_case			:      Optional[Any]        =			auxiliary_loss
          snake_case			:      Optional[int]        =			position_embedding_type
          # deformable attributes
          snake_case			:      Tuple        =			num_feature_levels
          snake_case			:      List[Any]        =			encoder_n_points
          snake_case			:      Dict        =			decoder_n_points
          snake_case			:      int        =			two_stage
          snake_case			:      Any        =			two_stage_num_proposals
          snake_case			:      List[str]        =			with_box_refine
          snake_case			:      Tuple        =			assign_first_stage
          if two_stage is True and with_box_refine is False:
               raise ValueError("""If two_stage is True, with_box_refine must be True."""							)
          # Hungarian matcher
          snake_case			:      Optional[int]        =			class_cost
          snake_case			:      int        =			bbox_cost
          snake_case			:      Optional[int]        =			giou_cost
          # Loss coefficients
          snake_case			:      str        =			mask_loss_coefficient
          snake_case			:      Any        =			dice_loss_coefficient
          snake_case			:      List[Any]        =			bbox_loss_coefficient
          snake_case			:      List[Any]        =			giou_loss_coefficient
          snake_case			:      List[str]        =			eos_coefficient
          snake_case			:      Optional[Any]        =			focal_alpha
          super().__init__(is_encoder_decoder=__a							,**__a							)







     @property
     def 			snake_case_      (				self							)      ->				int:
          return self.encoder_attention_heads







     @property
     def 			snake_case_      (				self							)      ->				int:
          return self.d_model







     def 			snake_case_      (				self							)      ->				List[str]:
          snake_case			:      List[str]        =			copy.deepcopy(self.__dict__							)
          snake_case			:      List[str]        =			self.backbone_config.to_dict()
          snake_case			:      List[Any]        =			self.__class__.model_type
          return output



