






'''simple docstring'''






import copy
import os
from typing import Union

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


__A    	=   logging.get_logger(__name__)

__A    	=   {
    '''Salesforce/blip-vqa-base''': '''https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json''',
    '''Salesforce/blip-vqa-capfit-large''': (
        '''https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json'''
    ),
    '''Salesforce/blip-image-captioning-base''': (
        '''https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json'''
    ),
    '''Salesforce/blip-image-captioning-large''': (
        '''https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json'''
    ),
    '''Salesforce/blip-itm-base-coco''': '''https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json''',
    '''Salesforce/blip-itm-large-coco''': '''https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json''',
    '''Salesforce/blip-itm-base-flikr''': '''https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json''',
    '''Salesforce/blip-itm-large-flikr''': (
        '''https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json'''
    ),
}




class a_    (    UpperCamelCase_							):
   _snake_case        =							"""blip_text_model"""







   def __init__(self					,   __a=3_0_5_2_4					,   __a=7_6_8					,   __a=7_6_8					,   __a=3_0_7_2					,   __a=7_6_8					,   __a=1_2					,   __a=8					,   __a=5_1_2					,   __a="gelu"					,   __a=1E-12					,   __a=0.0					,   __a=0.0					,   __a=0.02					,   __a=3_0_5_2_2					,   __a=2					,   __a=0					,   __a=1_0_2					,   __a=True					,   __a=True					,   **__a					,   )			->      Tuple:
      """simple docstring"""






      super().__init__(
          pad_token_id=__a					,   bos_token_id=__a					,   eos_token_id=__a					,   sep_token_id=__a					,   **__a					,   )

      __snake_case				:      int     							= vocab_size
      __snake_case				:      Tuple     							= hidden_size
      __snake_case				:      Optional[Any]     							= encoder_hidden_size
      __snake_case				:      Tuple     							= intermediate_size
      __snake_case				:      Any     							= projection_dim
      __snake_case				:      Any     							= hidden_dropout_prob
      __snake_case				:      List[str]     							= num_hidden_layers
      __snake_case				:      Dict     							= num_attention_heads
      __snake_case				:      Any     							= max_position_embeddings
      __snake_case				:      Any     							= layer_norm_eps
      __snake_case				:      str     							= hidden_act
      __snake_case				:      str     							= initializer_range
      __snake_case				:      int     							= attention_probs_dropout_prob
      __snake_case				:      Any     							= is_decoder
      __snake_case				:      str     							= use_cache







   @classmethod
   def     SCREAMING_SNAKE_CASE__					(cls					,   __a					,   **__a)			->      "PretrainedConfig":
      """simple docstring"""






      cls._set_token_in_kwargs(__a)

      __snake_case							,__snake_case				:      List[str]     							= cls.get_config_dict(__a					,   **__a)

      # get the text config dict if we are loading from BlipConfig
      if config_dict.get('model_type') == "blip":
         __snake_case				:      str     							= config_dict['text_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 a_    (    UpperCamelCase_							):
   _snake_case        =							"""blip_vision_model"""







   def __init__(self					,   __a=7_6_8					,   __a=3_0_7_2					,   __a=5_1_2					,   __a=1_2					,   __a=1_2					,   __a=3_8_4					,   __a=1_6					,   __a="gelu"					,   __a=1E-5					,   __a=0.0					,   __a=1E-10					,   **__a					,   )			->      int:
      """simple docstring"""






      super().__init__(**__a)

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







   @classmethod
   def     SCREAMING_SNAKE_CASE__					(cls					,   __a					,   **__a)			->      "PretrainedConfig":
      """simple docstring"""






      cls._set_token_in_kwargs(__a)

      __snake_case							,__snake_case				:      Dict     							= cls.get_config_dict(__a					,   **__a)

      # get the vision config dict if we are loading from BlipConfig
      if config_dict.get('model_type') == "blip":
         __snake_case				:      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 a_    (    UpperCamelCase_							):
   _snake_case        =							"""blip"""
   _snake_case        =							True







   def __init__(self					,   __a=None					,   __a=None					,   __a=5_1_2					,   __a=2.6_592					,   __a=2_5_6					,   **__a					,   )			->      List[str]:
      """simple docstring"""






      super().__init__(**__a)

      if text_config is None:
         __snake_case				:      str     							= {}
         logger.info('`text_config` is `None`. Initializing the `BlipTextConfig` with default values.')

      if vision_config is None:
         __snake_case				:      Dict     							= {}
         logger.info('`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.')

      __snake_case				:      Union[str, Any]     							= BlipTextConfig(**__a)
      __snake_case				:      List[str]     							= BlipVisionConfig(**__a)

      __snake_case				:      List[Any]     							= self.vision_config.hidden_size

      __snake_case				:      Union[str, Any]     							= projection_dim
      __snake_case				:      Any     							= logit_scale_init_value
      __snake_case				:      Tuple     							= 1.0
      __snake_case				:      Optional[int]     							= 0.02
      __snake_case				:      Union[str, Any]     							= image_text_hidden_size







   @classmethod
   def     SCREAMING_SNAKE_CASE__					(cls					,   __a					,   __a					,   **__a)			->      Any:
      """simple docstring"""






      return cls(text_config=text_config.to_dict()					,   vision_config=vision_config.to_dict()					,   **__a)







   def     SCREAMING_SNAKE_CASE__					(self)			->      Any:
      """simple docstring"""






      __snake_case				:      Union[str, Any]     							= copy.deepcopy(self.__dict__)
      __snake_case				:      Tuple     							= self.text_config.to_dict()
      __snake_case				:      List[str]     							= self.vision_config.to_dict()
      __snake_case				:      str     							= self.__class__.model_type
      return output







'''simple docstring'''






from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
      import accelerate




def        _SCREAMING_SNAKE_CASE  (				A  :       Optional[Any]  )    -> int:







   """simple docstring"""
   if not is_accelerate_available():
      return method
   __snake_case				:      Optional[Any]     							= version.parse(accelerate.__version__  ).base_version
   if version.parse(A  ) < version.parse('0.17.0'  ):
      return method

   def wrapper(self  :       Optional[Any]  ,		*A  :       Optional[Any]  ,		**A  :       Optional[int]  ):
      if hasattr(self  ,		'_hf_hook'  ) and hasattr(self._hf_hook  ,		'pre_forward'  ):
         self._hf_hook.pre_forward(self  )
      return method(self  ,		*A  ,		**A  )

   return wrapper