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

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







class UpperCAmelCase__	( lowercase__	):





  """simple docstring"""

  __UpperCAmelCase				:				Dict   =					'''blip_2_vision_model'''


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


     '''simple docstring'''






     super().__init__(**_a       )

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


  @classmethod
  def   __lowercase		(		cls      :     List[str]							,_a      :     Union[str, os.PathLike]							,**_a      :     Optional[Any]       ):


     '''simple docstring'''






     cls._set_token_in_kwargs(_a       )

     _a,  _a				:	Optional[Any]			=   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				:	List[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(_a							,**_a       )







class UpperCAmelCase__	( lowercase__	):





  """simple docstring"""

  __UpperCAmelCase				:				Any   =					'''blip_2_qformer'''


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


     '''simple docstring'''






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

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


  @classmethod
  def   __lowercase		(		cls      :     Tuple							,_a      :     Union[str, os.PathLike]							,**_a      :     Any       ):


     '''simple docstring'''






     cls._set_token_in_kwargs(_a       )

     _a,  _a				:	Any			=   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				:	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(_a							,**_a       )







class UpperCAmelCase__	( lowercase__	):





  """simple docstring"""

  __UpperCAmelCase				:				Optional[Any]   =					'''blip-2'''
  __UpperCAmelCase				:				Dict   =					True


  def __init__(		self      :     List[str]							,_a      :     str=None							,_a      :     Optional[Any]=None							,_a      :     Tuple=None							,_a      :     Optional[int]=32							,**_a      :     Union[str, Any]       ):


     '''simple docstring'''






     super().__init__(**_a       )

     if vision_config is None:
        _a				:	List[str]			=   {}
        logger.info('vision_config is None. initializing the Blip2VisionConfig with default values.'       )

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

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

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

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

     _a				:	Tuple			=   num_query_tokens
     _a				:	Dict			=   self.vision_config.hidden_size
     _a				:	Tuple			=   self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
     _a				:	int			=   1.0
     _a				:	Dict			=   0.02


  @classmethod
  def   __lowercase		(		cls      :     int							,_a      :     BlipaVisionConfig							,_a      :     BlipaQFormerConfig							,_a      :     PretrainedConfig							,**_a      :     Tuple							,):


     '''simple docstring'''






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


  def   __lowercase		(		self      :     List[str]       ):


     '''simple docstring'''






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





'''simple docstring'''







import warnings

from ...utils import logging
from .image_processing_beit import BeitImageProcessor


__lowerCAmelCase         =    logging.get_logger(__name__)







class UpperCAmelCase__	( lowercase__	):





  """simple docstring"""

  def __init__(		self      :     int							,*_a      :     Optional[int]							,**_a      :     str       ):


     '''simple docstring'''






     warnings.warn(
         'The class BeitFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'
         ' use BeitImageProcessor instead.'							,_a							,)
     super().__init__(*_a							,**_a       )



