
from importlib import import_module

from .logging import get_logger


lowerCamelCase      =get_logger(__name__)




class 				_lowerCamelCase :





     """simple docstring"""







     def __init__(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE=None  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   Optional[Any]					=				attrs or []
           if module is not None:
                 for key in module.__dict__:
                       if key in attrs or not key.startswith('''__'''  ):
                             setattr(self						,						_lowercase						,						getattr(_lowercase						,						_lowercase  )  )
           UpperCamelCase__    :   List[str]					=				module._original_module if isinstance(_lowercase						,						_PatchedModuleObj  ) else module




class 				_lowerCamelCase :





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  []






     def __init__(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE=None  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   Optional[Any]					=				obj
           UpperCamelCase__    :   int					=				target
           UpperCamelCase__    :   Tuple					=				new
           UpperCamelCase__    :   Tuple					=				target.split('''.'''  )[0]
           UpperCamelCase__    :   Optional[int]					=				{}
           UpperCamelCase__    :   Union[str, Any]					=				attrs or []






     def __enter__(							self  )  ->   Tuple:




           """simple docstring"""







           *UpperCamelCase__				,UpperCamelCase__    :   Union[str, Any]					=				self.target.split('''.'''  )

           # Patch modules:
           # it's used to patch attributes of submodules like "os.path.join";
           # in this case we need to patch "os" and "os.path"

           for i in range(len(_lowercase  )  ):
                 try:
                       UpperCamelCase__    :   List[Any]					=				import_module('''.'''.join(submodules[: i + 1]  )  )
                 except ModuleNotFoundError:
                       continue
                 # We iterate over all the globals in self.obj in case we find "os" or "os.path"
                 for attr in self.obj.__dir__():
                       UpperCamelCase__    :   str					=				getattr(self.obj						,						_lowercase  )
                       # We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
                       # This allows to patch renamed modules like "from os import path as ospath".
                       if obj_attr is submodule or (
                           (isinstance(_lowercase						,						_PatchedModuleObj  ) and obj_attr._original_module is submodule)
                       ):
                             UpperCamelCase__    :   int					=				obj_attr
                             # patch at top level
                             setattr(self.obj						,						_lowercase						,						_PatchedModuleObj(_lowercase						,						attrs=self.attrs  )  )
                             UpperCamelCase__    :   Optional[int]					=				getattr(self.obj						,						_lowercase  )
                             # construct lower levels patches
                             for key in submodules[i + 1 :]:
                                   setattr(_lowercase						,						_lowercase						,						_PatchedModuleObj(getattr(_lowercase						,						_lowercase						,						_lowercase  )						,						attrs=self.attrs  )  )
                                   UpperCamelCase__    :   Optional[int]					=				getattr(_lowercase						,						_lowercase  )
                             # finally set the target attribute
                             setattr(_lowercase						,						_lowercase						,						self.new  )

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

           if submodules:  # if it's an attribute of a submodule like "os.path.join"
                 try:
                       UpperCamelCase__    :   int					=				getattr(import_module('''.'''.join(_lowercase  )  )						,						_lowercase  )
                 except (AttributeError, ModuleNotFoundError):
                       return
                 # We iterate over all the globals in self.obj in case we find "os.path.join"
                 for attr in self.obj.__dir__():
                       # We don't check for the name of the global, but rather if its value *is* "os.path.join".
                       # This allows to patch renamed attributes like "from os.path import join as pjoin".
                       if getattr(self.obj						,						_lowercase  ) is attr_value:
                             UpperCamelCase__    :   List[str]					=				getattr(self.obj						,						_lowercase  )
                             setattr(self.obj						,						_lowercase						,						self.new  )
           elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
                 UpperCamelCase__    :   List[Any]					=				globals()['''__builtins__'''][target_attr]
                 setattr(self.obj						,						_lowercase						,						self.new  )
           else:
                 raise RuntimeError(F'''Tried to patch attribute {target_attr} instead of a submodule.'''  )






     def __exit__(							self						,						*__SCREAMING_SNAKE_CASE  )  ->   Tuple:




           """simple docstring"""







           for attr in list(self.original  ):
                 setattr(self.obj						,						_lowercase						,						self.original.pop(_lowercase  )  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Any:




           """simple docstring"""







           self.__enter__()
           self._active_patches.append(self  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   str:




           """simple docstring"""







           try:
                 self._active_patches.remove(self  )
           except ValueError:
                 # If the patch hasn't been started this will fail
                 return None

           return self.__exit__()




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


