



from importlib import import_module

from .logging import get_logger


__lowerCamelCase         =			get_logger(__name__)


class   snake_case_ :




       """simple docstring"""






       def __init__(     self     ,lowercase     ,lowercase=None):

             """simple docstring"""





             UpperCAmelCase_  :	List[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_  :	Any				      =		module._original_module if isinstance(_lowercase     ,_PatchedModuleObj) else module


class   snake_case_ :




       """simple docstring"""






       _lowerCamelCase			    =				[]



       def __init__(     self     ,lowercase     ,lowercase     ,lowercase     ,lowercase=None):

             """simple docstring"""





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



       def __enter__(     self):

             """simple docstring"""





             *UpperCAmelCase_      ,      UpperCAmelCase_  :	Dict				      =		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_  :	Dict				      =		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_  :	Any				      =		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_  :	Tuple				      =		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[Any]				      =		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_  :	Optional[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_  :	Union[str, Any]				      =		getattr(self.obj     ,_lowercase)
                               setattr(self.obj     ,_lowercase     ,self.new)
             elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
                   UpperCAmelCase_  :	Union[str, 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     ,*lowercase):

             """simple docstring"""





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



       def  A_   (     self):

             """simple docstring"""





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



       def  A_   (     self):

             """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__()











import logging

from transformers import PretrainedConfig


__lowerCamelCase         =			logging.getLogger(__name__)


__lowerCamelCase         =			{
    '''bertabs-finetuned-cnndm''': '''https://huggingface.co/remi/bertabs-finetuned-cnndm-extractive-abstractive-summarization/resolve/main/config.json''',
}


class   snake_case_ (lowercase__  ):




       """simple docstring"""






       _lowerCamelCase			    =				"""bertabs"""



       def __init__(     self     ,lowercase=30522     ,lowercase=512     ,lowercase=6     ,lowercase=512     ,lowercase=8     ,lowercase=512     ,lowercase=0.2     ,lowercase=6     ,lowercase=768     ,lowercase=8     ,lowercase=2048     ,lowercase=0.2     ,**lowercase     ,):

             """simple docstring"""





             super().__init__(**lowercase)

             UpperCAmelCase_  :	Any				      =		vocab_size
             UpperCAmelCase_  :	int				      =		max_pos

             UpperCAmelCase_  :	List[str]				      =		enc_layers
             UpperCAmelCase_  :	List[str]				      =		enc_hidden_size
             UpperCAmelCase_  :	Any				      =		enc_heads
             UpperCAmelCase_  :	Any				      =		enc_ff_size
             UpperCAmelCase_  :	Optional[int]				      =		enc_dropout

             UpperCAmelCase_  :	List[str]				      =		dec_layers
             UpperCAmelCase_  :	List[Any]				      =		dec_hidden_size
             UpperCAmelCase_  :	List[str]				      =		dec_heads
             UpperCAmelCase_  :	List[Any]				      =		dec_ff_size
             UpperCAmelCase_  :	List[str]				      =		dec_dropout
