
import copy
import os
from typing import Union

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


lowerCamelCase      =logging.get_logger(__name__)

lowerCamelCase      ={
    "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 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  '''blip_text_model'''






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=3_0_5_2_4						,						__SCREAMING_SNAKE_CASE=7_6_8						,						__SCREAMING_SNAKE_CASE=7_6_8						,						__SCREAMING_SNAKE_CASE=3_0_7_2						,						__SCREAMING_SNAKE_CASE=7_6_8						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=8						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE="gelu"						,						__SCREAMING_SNAKE_CASE=1e-12						,						__SCREAMING_SNAKE_CASE=0.0						,						__SCREAMING_SNAKE_CASE=0.0						,						__SCREAMING_SNAKE_CASE=0.02						,						__SCREAMING_SNAKE_CASE=3_0_5_2_2						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=0						,						__SCREAMING_SNAKE_CASE=1_0_2						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						**__SCREAMING_SNAKE_CASE						,						)  ->   Union[str, Any]:




           """simple docstring"""







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

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






     @classmethod
     def    __SCREAMING_SNAKE_CASE			(							cls						,						__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   "PretrainedConfig":




           """simple docstring"""







           cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__				,UpperCamelCase__    :   str					=				cls.get_config_dict(__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )

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




class 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  '''blip_vision_model'''






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=7_6_8						,						__SCREAMING_SNAKE_CASE=3_0_7_2						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=3_8_4						,						__SCREAMING_SNAKE_CASE=1_6						,						__SCREAMING_SNAKE_CASE="gelu"						,						__SCREAMING_SNAKE_CASE=1e-5						,						__SCREAMING_SNAKE_CASE=0.0						,						__SCREAMING_SNAKE_CASE=1e-10						,						**__SCREAMING_SNAKE_CASE						,						)  ->   Tuple:




           """simple docstring"""







           super().__init__(**__SCREAMING_SNAKE_CASE  )

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






     @classmethod
     def    __SCREAMING_SNAKE_CASE			(							cls						,						__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   "PretrainedConfig":




           """simple docstring"""







           cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__				,UpperCamelCase__    :   Dict					=				cls.get_config_dict(__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )

           # get the vision config dict if we are loading from BlipConfig
           if config_dict.get('''model_type'''  ) == "blip":
                 UpperCamelCase__    :   Optional[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 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  '''blip'''
     SCREAMING_SNAKE_CASE_		   =  True






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE=2.6592						,						__SCREAMING_SNAKE_CASE=2_5_6						,						**__SCREAMING_SNAKE_CASE						,						)  ->   List[Any]:




           """simple docstring"""







           super().__init__(**__SCREAMING_SNAKE_CASE  )

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

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

           UpperCamelCase__    :   int					=				BlipTextConfig(**__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   List[Any]					=				BlipVisionConfig(**__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__    :   Any					=				self.vision_config.hidden_size

           UpperCamelCase__    :   int					=				projection_dim
           UpperCamelCase__    :   Optional[Any]					=				logit_scale_init_value
           UpperCamelCase__    :   Optional[Any]					=				1.0
           UpperCamelCase__    :   Optional[Any]					=				0.02
           UpperCamelCase__    :   int					=				image_text_hidden_size






     @classmethod
     def    __SCREAMING_SNAKE_CASE			(							cls						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   Dict:




           """simple docstring"""







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






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Any:




           """simple docstring"""







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




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


lowerCamelCase      =logging.get_logger(__name__)

lowerCamelCase      ={
    "google/realm-cc-news-pretrained-embedder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-encoder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-scorer": (
        "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-openqa": (
        "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json"
    ),
    "google/realm-orqa-nq-openqa": "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json",
    "google/realm-orqa-nq-reader": "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json",
    "google/realm-orqa-wq-openqa": "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json",
    "google/realm-orqa-wq-reader": "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json",
    # See all REALM models at https://huggingface.co/models?filter=realm
}




class 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  '''realm'''






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=3_0_5_2_2						,						__SCREAMING_SNAKE_CASE=7_6_8						,						__SCREAMING_SNAKE_CASE=1_2_8						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=8						,						__SCREAMING_SNAKE_CASE=3_0_7_2						,						__SCREAMING_SNAKE_CASE="gelu_new"						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=0.02						,						__SCREAMING_SNAKE_CASE=1e-12						,						__SCREAMING_SNAKE_CASE=2_5_6						,						__SCREAMING_SNAKE_CASE=1_0						,						__SCREAMING_SNAKE_CASE=1e-3						,						__SCREAMING_SNAKE_CASE=5						,						__SCREAMING_SNAKE_CASE=3_2_0						,						__SCREAMING_SNAKE_CASE=1_3_3_5_3_7_1_8						,						__SCREAMING_SNAKE_CASE=5_0_0_0						,						__SCREAMING_SNAKE_CASE=1						,						__SCREAMING_SNAKE_CASE=0						,						__SCREAMING_SNAKE_CASE=2						,						**__SCREAMING_SNAKE_CASE						,						)  ->   List[str]:




           """simple docstring"""







           super().__init__(pad_token_id=__SCREAMING_SNAKE_CASE						,						bos_token_id=__SCREAMING_SNAKE_CASE						,						eos_token_id=__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )

           # Common config
           UpperCamelCase__    :   int					=				vocab_size
           UpperCamelCase__    :   Any					=				max_position_embeddings
           UpperCamelCase__    :   List[str]					=				hidden_size
           UpperCamelCase__    :   Union[str, Any]					=				retriever_proj_size
           UpperCamelCase__    :   int					=				num_hidden_layers
           UpperCamelCase__    :   Union[str, Any]					=				num_attention_heads
           UpperCamelCase__    :   str					=				num_candidates
           UpperCamelCase__    :   int					=				intermediate_size
           UpperCamelCase__    :   Dict					=				hidden_act
           UpperCamelCase__    :   Any					=				hidden_dropout_prob
           UpperCamelCase__    :   Any					=				attention_probs_dropout_prob
           UpperCamelCase__    :   Any					=				initializer_range
           UpperCamelCase__    :   Optional[Any]					=				type_vocab_size
           UpperCamelCase__    :   List[Any]					=				layer_norm_eps

           # Reader config
           UpperCamelCase__    :   List[Any]					=				span_hidden_size
           UpperCamelCase__    :   List[Any]					=				max_span_width
           UpperCamelCase__    :   Optional[Any]					=				reader_layer_norm_eps
           UpperCamelCase__    :   Optional[Any]					=				reader_beam_size
           UpperCamelCase__    :   int					=				reader_seq_len

           # Retrieval config
           UpperCamelCase__    :   List[str]					=				num_block_records
           UpperCamelCase__    :   Union[str, Any]					=				searcher_beam_size


