


'''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


A__:    List[str]					    =       logging.get_logger(__name__)

A__:    List[str]					    =       {
    '''salesforce/blip2-opt-2.7b''': '''https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json''',
}







class A__       (						UpperCAmelCase__      ):
      __UpperCamelCase       :  Tuple	       =							"blip_2_vision_model"






      def __init__( self			:Any     ,						SCREAMING_SNAKE_CASE			:Optional[int]=1_4_0_8     ,						SCREAMING_SNAKE_CASE			:Optional[Any]=6_1_4_4     ,						SCREAMING_SNAKE_CASE			:List[Any]=3_9     ,						SCREAMING_SNAKE_CASE			:Tuple=1_6     ,						SCREAMING_SNAKE_CASE			:str=2_2_4     ,						SCREAMING_SNAKE_CASE			:Optional[int]=1_4     ,						SCREAMING_SNAKE_CASE			:List[str]="gelu"     ,						SCREAMING_SNAKE_CASE			:List[Any]=0.00_001     ,						SCREAMING_SNAKE_CASE			:Union[str, Any]=0.0     ,						SCREAMING_SNAKE_CASE			:Optional[int]=1e-10     ,						SCREAMING_SNAKE_CASE			:Dict=True     ,						**SCREAMING_SNAKE_CASE			:Optional[Any]     ,						)       ->					Optional[Any]:




             '''simple docstring'''
             super().__init__(**SCREAMING_SNAKE_CASE	)

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






      @classmethod
      def __UpperCAmelCase       ( cls			:List[str]     ,						SCREAMING_SNAKE_CASE			:Union[str, os.PathLike]     ,						**SCREAMING_SNAKE_CASE			:Dict	)       ->					"PretrainedConfig":




             '''simple docstring'''
             cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE	)

             _a					,    _a    : Tuple     					=cls.get_config_dict(SCREAMING_SNAKE_CASE     ,						**SCREAMING_SNAKE_CASE	)

             # 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(SCREAMING_SNAKE_CASE     ,						**SCREAMING_SNAKE_CASE	)







class A__       (						UpperCAmelCase__      ):
      __UpperCamelCase       :  str	       =							"blip_2_qformer"






      def __init__( self			:List[Any]     ,						SCREAMING_SNAKE_CASE			:Any=3_0_5_2_2     ,						SCREAMING_SNAKE_CASE			:Optional[int]=7_6_8     ,						SCREAMING_SNAKE_CASE			:Any=1_2     ,						SCREAMING_SNAKE_CASE			:str=1_2     ,						SCREAMING_SNAKE_CASE			:int=3_0_7_2     ,						SCREAMING_SNAKE_CASE			:Dict="gelu"     ,						SCREAMING_SNAKE_CASE			:List[Any]=0.1     ,						SCREAMING_SNAKE_CASE			:Optional[int]=0.1     ,						SCREAMING_SNAKE_CASE			:List[Any]=5_1_2     ,						SCREAMING_SNAKE_CASE			:int=0.02     ,						SCREAMING_SNAKE_CASE			:Tuple=1e-12     ,						SCREAMING_SNAKE_CASE			:Optional[Any]=0     ,						SCREAMING_SNAKE_CASE			:Optional[int]="absolute"     ,						SCREAMING_SNAKE_CASE			:List[Any]=2     ,						SCREAMING_SNAKE_CASE			:Dict=1_4_0_8     ,						**SCREAMING_SNAKE_CASE			:int     ,						)       ->					Optional[int]:




             '''simple docstring'''
             super().__init__(pad_token_id=SCREAMING_SNAKE_CASE     ,						**SCREAMING_SNAKE_CASE	)

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






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




             '''simple docstring'''
             cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE	)

             _a					,    _a    : Any     					=cls.get_config_dict(SCREAMING_SNAKE_CASE     ,						**SCREAMING_SNAKE_CASE	)

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







class A__       (						UpperCAmelCase__      ):
      __UpperCamelCase       :  Optional[int]	       =							"blip-2"
      __UpperCamelCase       :  Tuple	       =							True






      def __init__( self			:List[str]     ,						SCREAMING_SNAKE_CASE			:List[str]=None     ,						SCREAMING_SNAKE_CASE			:Optional[int]=None     ,						SCREAMING_SNAKE_CASE			:Optional[Any]=None     ,						SCREAMING_SNAKE_CASE			:int=3_2     ,						**SCREAMING_SNAKE_CASE			:Optional[Any]	)       ->					List[str]:




             '''simple docstring'''
             super().__init__(**SCREAMING_SNAKE_CASE	)

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

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

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

             _a    : List[str]     					=BlipaVisionConfig(**SCREAMING_SNAKE_CASE	)
             _a    : List[Any]     					=BlipaQFormerConfig(**SCREAMING_SNAKE_CASE	)
             _a    : Tuple     					=text_config["""model_type"""] if """model_type""" in text_config else """opt"""
             _a    : str     					=CONFIG_MAPPING[text_model_type](**SCREAMING_SNAKE_CASE	)

             _a    : Union[str, Any]     					=self.text_config.tie_word_embeddings
             _a    : Union[str, Any]     					=self.text_config.is_encoder_decoder

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






      @classmethod
      def __UpperCAmelCase       ( cls			:List[Any]     ,						SCREAMING_SNAKE_CASE			:BlipaVisionConfig     ,						SCREAMING_SNAKE_CASE			:BlipaQFormerConfig     ,						SCREAMING_SNAKE_CASE			:PretrainedConfig     ,						**SCREAMING_SNAKE_CASE			:Any     ,						)       ->					Any:




             '''simple docstring'''
             return cls(
                 vision_config=vision_config.to_dict()     ,						qformer_config=qformer_config.to_dict()     ,						text_config=text_config.to_dict()     ,						**SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:Optional[int]	)       ->					Dict:




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






'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


A__:    str					    =       {}

try:
   if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Tuple					    =       ['''GPTSw3Tokenizer''']


if TYPE_CHECKING:
   try:
      if not is_sentencepiece_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_gpt_swa import GPTSwaTokenizer

else:
   import sys

   A__:    str					    =       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


