



"""simple docstring"""
import copy
import os
from typing import Union

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


SCREAMING_SNAKE_CASE_				= logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_				= {
    """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 			snake_case_						(						a_				):
       __lowerCAmelCase    					=					"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_			,     ):
         super().__init__(
             pad_token_id=a_			,     bos_token_id=a_			,     eos_token_id=a_			,     sep_token_id=a_			,     **a_			,     )

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






       @classmethod
       def snake_case_  (   cls			,     a_			,     **a_      ):
         cls._set_token_in_kwargs(a_      )

         a_     :      int 						=     cls.get_config_dict(a_			,     **a_      )

         # get the text config dict if we are loading from BlipConfig
         if config_dict.get("model_type"      ) == "blip":
           a_     :      List[Any] 						=     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 			snake_case_						(						a_				):
       __lowerCAmelCase    					=					"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_			,     ):
         super().__init__(**a_      )

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






       @classmethod
       def snake_case_  (   cls			,     a_			,     **a_      ):
         cls._set_token_in_kwargs(a_      )

         a_     :      Optional[Any] 						=     cls.get_config_dict(a_			,     **a_      )

         # get the vision config dict if we are loading from BlipConfig
         if config_dict.get("model_type"      ) == "blip":
           a_     :      List[str] 						=     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 			snake_case_						(						a_				):
       __lowerCAmelCase    					=					"blip"
       __lowerCAmelCase    					=					True






       def __init__(   self			,     a_=None			,     a_=None			,     a_=5_1_2			,     a_=2.6_592			,     a_=2_5_6			,     **a_			,     ):
         super().__init__(**a_      )

         if text_config is None:
           a_     :      List[Any] 						=     {}
           logger.info("`text_config` is `None`. Initializing the `BlipTextConfig` with default values."      )

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

         a_     :      str 						=     BlipTextConfig(**a_      )
         a_     :      List[Any] 						=     BlipVisionConfig(**a_      )

         a_     :      Any 						=     self.vision_config.hidden_size

         a_     :      Optional[int] 						=     projection_dim
         a_     :      Optional[Any] 						=     logit_scale_init_value
         a_     :      Optional[Any] 						=     1.0
         a_     :      Union[str, Any] 						=     0.02
         a_     :      List[str] 						=     image_text_hidden_size






       @classmethod
       def snake_case_  (   cls			,     a_			,     a_			,     **a_      ):
         return cls(text_config=text_config.to_dict()			,     vision_config=vision_config.to_dict()			,     **a_      )






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




"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_				= logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_				= {
    """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 			snake_case_						(						a_				):
							__lowerCAmelCase    					=					"realm"






							def __init__(   self			,     a_=3_0_5_2_2			,     a_=7_6_8			,     a_=1_2_8			,     a_=1_2			,     a_=1_2			,     a_=8			,     a_=3_0_7_2			,     a_="gelu_new"			,     a_=0.1			,     a_=0.1			,     a_=5_1_2			,     a_=2			,     a_=0.02			,     a_=1e-12			,     a_=2_5_6			,     a_=1_0			,     a_=1e-3			,     a_=5			,     a_=3_2_0			,     a_=1_3_3_5_3_7_1_8			,     a_=5_0_0_0			,     a_=1			,     a_=0			,     a_=2			,     **a_			,     ):
									super().__init__(pad_token_id=a_			,     bos_token_id=a_			,     eos_token_id=a_			,     **a_      )

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

									# Reader config
									a_     :      str 						=     span_hidden_size
									a_     :      Union[str, Any] 						=     max_span_width
									a_     :      Tuple 						=     reader_layer_norm_eps
									a_     :      List[Any] 						=     reader_beam_size
									a_     :      str 						=     reader_seq_len

									# Retrieval config
									a_     :      str 						=     num_block_records
									a_     :      int 						=     searcher_beam_size