





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      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip_text_model"

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



   '''simple docstring'''



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

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







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



   '''simple docstring'''



   cls._set_token_in_kwargs(UpperCAmelCase_)

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

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



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip_vision_model"

 def __init__(self       :     Union[str, Any] ,				UpperCAmelCase_       :     Tuple=768 ,				UpperCAmelCase_       :     List[Any]=3_072 ,				UpperCAmelCase_       :     Union[str, Any]=512 ,				UpperCAmelCase_       :     Any=12 ,				UpperCAmelCase_       :     List[str]=12 ,				UpperCAmelCase_       :     Optional[int]=384 ,				UpperCAmelCase_       :     int=16 ,				UpperCAmelCase_       :     Union[str, Any]="gelu" ,				UpperCAmelCase_       :     Optional[Any]=1E-5 ,				UpperCAmelCase_       :     str=0.0 ,				UpperCAmelCase_       :     List[str]=1E-1_0 ,				**UpperCAmelCase_       :     Optional[Any] ,				) ->Union[str, Any]:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

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







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



   '''simple docstring'''



   cls._set_token_in_kwargs(UpperCAmelCase_)

   lowerCamelCase__:   Optional[int]    						=cls.get_config_dict(UpperCAmelCase_ ,				**UpperCAmelCase_)

   # get the vision config dict if we are loading from BlipConfig
   if config_dict.get("model_type") == "blip":
     lowerCamelCase__:   Optional[int]    						=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"
 lowercase_	=    True

 def __init__(self       :     Optional[int] ,				UpperCAmelCase_       :     Any=None ,				UpperCAmelCase_       :     str=None ,				UpperCAmelCase_       :     Optional[int]=512 ,				UpperCAmelCase_       :     Union[str, Any]=2.6592 ,				UpperCAmelCase_       :     List[str]=256 ,				**UpperCAmelCase_       :     int ,				) ->Optional[int]:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

   if text_config is None:
     lowerCamelCase__:   Tuple    						={}
     logger.info("`text_config` is `None`. Initializing the `BlipTextConfig` with default values.")

   if vision_config is None:
     lowerCamelCase__:   Tuple    						={}
     logger.info("`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.")

   lowerCamelCase__:   Tuple    						=BlipTextConfig(**UpperCAmelCase_)
   lowerCamelCase__:   Optional[int]    						=BlipVisionConfig(**UpperCAmelCase_)

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

   lowerCamelCase__:   Dict    						=projection_dim
   lowerCamelCase__:   Optional[int]    						=logit_scale_init_value
   lowerCamelCase__:   Optional[int]    						=1.0
   lowerCamelCase__:   List[str]    						=0.02
   lowerCamelCase__:   Optional[Any]    						=image_text_hidden_size

 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     List[str] ,				UpperCAmelCase_       :     BlipTextConfig ,				UpperCAmelCase_       :     BlipVisionConfig ,				**UpperCAmelCase_       :     Optional[Any]) ->Dict:



   '''simple docstring'''



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







 def 							SCREAMING_SNAKE_CASE_      (self       :     Union[str, Any]) ->Optional[int]:



   '''simple docstring'''



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








# Lint as: python3
import dataclasses
import re
from dataclasses import dataclass
from functools import total_ordering
from typing import Optional, Union


__A             =       re.compile(R"^(?P<major>\d+)" R"\.(?P<minor>\d+)" R"\.(?P<patch>\d+)$")



@total_ordering
@dataclass
class      _SCREAMING_SNAKE_CASE		:







 '''simple docstring'''
 lowercase_	=    42
 lowercase_	=    None
 lowercase_	=    None
 lowercase_	=    None
 lowercase_	=    None

 def 							SCREAMING_SNAKE_CASE_      (self       :     List[Any]) ->Tuple:



   '''simple docstring'''



   lowerCamelCase__						,      lowerCamelCase__						,      lowerCamelCase__:   List[str]    						=_str_to_version_tuple(self.version_str)

 def __repr__(self       :     Union[str, Any]) ->Union[str, Any]:



   '''simple docstring'''



   return F"""{self.tuple[0]}.{self.tuple[1]}.{self.tuple[2]}"""

 @property
 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[Any]) ->Optional[Any]:



   '''simple docstring'''



   return self.major, self.minor, self.patch

 def 							SCREAMING_SNAKE_CASE_      (self       :     Dict ,				UpperCAmelCase_       :     Tuple) ->Any:



   '''simple docstring'''



   if isinstance(UpperCAmelCase_ ,				UpperCAmelCase_):
     return Version(UpperCAmelCase_)
   elif isinstance(UpperCAmelCase_ ,				UpperCAmelCase_):
     return other
   raise TypeError(F"""{other} (type {type(UpperCAmelCase_)}) cannot be compared to version.""")

 def __eq__(self       :     Optional[Any] ,				UpperCAmelCase_       :     Tuple) ->List[str]:



   '''simple docstring'''



   try:
     lowerCamelCase__:   List[Any]    						=self._validate_operand(UpperCAmelCase_)
   except (TypeError, ValueError):
     return False
   else:
     return self.tuple == other.tuple

 def __lt__(self       :     Dict ,				UpperCAmelCase_       :     List[str]) ->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:   Tuple    						=self._validate_operand(UpperCAmelCase_)
   return self.tuple < other.tuple

 def __hash__(self       :     Any) ->Dict:



   '''simple docstring'''



   return hash(_version_tuple_to_str(self.tuple))

 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     Union[str, Any] ,				UpperCAmelCase_       :     Optional[Any]) ->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:   str    						={f.name for f in dataclasses.fields(cls)}
   return cls(**{k: v for k, v in dic.items() if k in field_names})







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



   '''simple docstring'''



   return self.version_str





def   lowerCAmelCase_				( __a	)  ->	List[Any]:







  """simple docstring"""





  lowerCamelCase__:   Optional[int]    						=_VERSION_REG.match(__a	)
  if not res:
    raise ValueError(F"""Invalid version '{version_str}'. Format should be x.y.z with {{x,y,z}} being digits."""	)
  return tuple(int(__a	) for v in [res.group("major"	), res.group("minor"	), res.group("patch"	)]	)






def   lowerCAmelCase_				( __a	)  ->	Dict:







  """simple docstring"""





  return ".".join(str(__a	) for v in version_tuple	)

