





import warnings

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


__A             =       logging.get_logger(__name__)

__A             =       {
    'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/config.json',
}



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    '''mvp'''
 lowercase_	=    ['''past_key_values''']
 lowercase_	=    {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}

 def __init__(self       :     List[str] ,				UpperCAmelCase_       :     Any=50_267 ,				UpperCAmelCase_       :     List[Any]=1_024 ,				UpperCAmelCase_       :     str=12 ,				UpperCAmelCase_       :     Optional[Any]=4_096 ,				UpperCAmelCase_       :     Optional[int]=16 ,				UpperCAmelCase_       :     Optional[int]=12 ,				UpperCAmelCase_       :     str=4_096 ,				UpperCAmelCase_       :     str=16 ,				UpperCAmelCase_       :     List[Any]=0.0 ,				UpperCAmelCase_       :     Dict=0.0 ,				UpperCAmelCase_       :     Optional[Any]="gelu" ,				UpperCAmelCase_       :     Optional[Any]=1_024 ,				UpperCAmelCase_       :     Dict=0.1 ,				UpperCAmelCase_       :     int=0.0 ,				UpperCAmelCase_       :     List[Any]=0.0 ,				UpperCAmelCase_       :     Optional[int]=0.02 ,				UpperCAmelCase_       :     Union[str, Any]=0.0 ,				UpperCAmelCase_       :     List[Any]=False ,				UpperCAmelCase_       :     List[str]=True ,				UpperCAmelCase_       :     List[str]=1 ,				UpperCAmelCase_       :     Optional[int]=0 ,				UpperCAmelCase_       :     Dict=2 ,				UpperCAmelCase_       :     int=True ,				UpperCAmelCase_       :     int=2 ,				UpperCAmelCase_       :     Optional[Any]=2 ,				UpperCAmelCase_       :     Tuple=False ,				UpperCAmelCase_       :     int=100 ,				UpperCAmelCase_       :     Optional[int]=800 ,				**UpperCAmelCase_       :     List[str] ,				) ->List[Any]:



   '''simple docstring'''



   lowerCamelCase__:   int    						=vocab_size
   lowerCamelCase__:   Optional[Any]    						=max_position_embeddings
   lowerCamelCase__:   Union[str, Any]    						=d_model
   lowerCamelCase__:   int    						=encoder_ffn_dim
   lowerCamelCase__:   List[Any]    						=encoder_layers
   lowerCamelCase__:   Tuple    						=encoder_attention_heads
   lowerCamelCase__:   Tuple    						=decoder_ffn_dim
   lowerCamelCase__:   Optional[Any]    						=decoder_layers
   lowerCamelCase__:   List[Any]    						=decoder_attention_heads
   lowerCamelCase__:   Union[str, Any]    						=dropout
   lowerCamelCase__:   List[Any]    						=attention_dropout
   lowerCamelCase__:   Optional[Any]    						=activation_dropout
   lowerCamelCase__:   List[str]    						=activation_function
   lowerCamelCase__:   List[str]    						=init_std
   lowerCamelCase__:   Optional[int]    						=encoder_layerdrop
   lowerCamelCase__:   str    						=decoder_layerdrop
   lowerCamelCase__:   Dict    						=classifier_dropout
   lowerCamelCase__:   Tuple    						=use_cache
   lowerCamelCase__:   List[str]    						=encoder_layers
   lowerCamelCase__:   str    						=scale_embedding  # scale factor will be sqrt(d_model) if True
   lowerCamelCase__:   Dict    						=use_prompt
   lowerCamelCase__:   Optional[int]    						=prompt_length
   lowerCamelCase__:   int    						=prompt_mid_dim

   super().__init__(
       pad_token_id=A__ ,				bos_token_id=A__ ,				eos_token_id=A__ ,				is_encoder_decoder=A__ ,				decoder_start_token_id=A__ ,				forced_eos_token_id=A__ ,				**A__ ,				)

   if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated" ,				A__):
     lowerCamelCase__:   str    						=self.bos_token_id
     warnings.warn(
         F"""Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. """
         "The config can simply be saved and uploaded again to be fixed.")








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

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



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip_2_vision_model"

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



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

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







 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     Optional[int] ,				UpperCAmelCase_       :     Union[str, os.PathLike] ,				**UpperCAmelCase_       :     List[Any]) ->"PretrainedConfig":



   '''simple docstring'''



   cls._set_token_in_kwargs(UpperCAmelCase_)

   lowerCamelCase__						,      lowerCamelCase__:   str    						=cls.get_config_dict(UpperCAmelCase_ ,				**UpperCAmelCase_)

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



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip_2_qformer"

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



   '''simple docstring'''



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

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







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



   '''simple docstring'''



   cls._set_token_in_kwargs(UpperCAmelCase_)

   lowerCamelCase__						,      lowerCamelCase__:   Tuple    						=cls.get_config_dict(UpperCAmelCase_ ,				**UpperCAmelCase_)

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



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip-2"
 lowercase_	=    True

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



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

   if vision_config is None:
     lowerCamelCase__:   Optional[int]    						={}
     logger.info("vision_config is None. initializing the Blip2VisionConfig with default values.")

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

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

   lowerCamelCase__:   Optional[Any]    						=BlipaVisionConfig(**UpperCAmelCase_)
   lowerCamelCase__:   Optional[int]    						=BlipaQFormerConfig(**UpperCAmelCase_)
   lowerCamelCase__:   Union[str, Any]    						=text_config["model_type"] if "model_type" in text_config else "opt"
   lowerCamelCase__:   Dict    						=CONFIG_MAPPING[text_model_type](**UpperCAmelCase_)

   lowerCamelCase__:   Optional[int]    						=self.text_config.tie_word_embeddings
   lowerCamelCase__:   List[str]    						=self.text_config.is_encoder_decoder

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

 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     Any ,				UpperCAmelCase_       :     BlipaVisionConfig ,				UpperCAmelCase_       :     BlipaQFormerConfig ,				UpperCAmelCase_       :     PretrainedConfig ,				**UpperCAmelCase_       :     int ,				) ->Optional[int]:



   '''simple docstring'''



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







 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str]) ->int:



   '''simple docstring'''



   lowerCamelCase__:   List[Any]    						=copy.deepcopy(self.__dict__)
   lowerCamelCase__:   Any    						=self.vision_config.to_dict()
   lowerCamelCase__:   Any    						=self.qformer_config.to_dict()
   lowerCamelCase__:   Any    						=self.text_config.to_dict()
   lowerCamelCase__:   int    						=self.__class__.model_type
   return output

