





'''simple docstring'''


from importlib import import_module

from .logging import get_logger


_SCREAMING_SNAKE_CASE									=				get_logger(__name__)

class  lowerCAmelCase_		:




 def __init__(						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase=None		)     ->				int:
     _lowerCAmelCase						      =   attrs or []
     if module is not None:
         for key in module.__dict__:
             if key in attrs or not key.startswith("__"		):
                 setattr(self      ,  _lowerCAmelCase      ,  getattr(_lowerCAmelCase      ,  _lowerCAmelCase		)		)
     _lowerCAmelCase						      =   module._original_module if isinstance(_lowerCAmelCase      ,  _PatchedModuleObj		) else module







class  lowerCAmelCase_		:
 __lowerCamelCase    :				Dict								=       []




 def __init__(						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase=None		)     ->				Union[str, Any]:
     _lowerCAmelCase						      =   obj
     _lowerCAmelCase						      =   target
     _lowerCAmelCase						      =   new
     _lowerCAmelCase						      =   target.split("."		)[0]
     _lowerCAmelCase						      =   {}
     _lowerCAmelCase						      =   attrs or []




 def __enter__(						self		)     ->				Optional[int]:
     *_lowerCAmelCase      ,      _lowerCAmelCase						      =   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(_lowerCAmelCase		)		):
         try:
             _lowerCAmelCase						      =   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__():
             _lowerCAmelCase						      =   getattr(self.obj      ,  _lowerCAmelCase		)
             # 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(_lowerCAmelCase      ,  _PatchedModuleObj		) and obj_attr._original_module is submodule)
             ):
                 _lowerCAmelCase						      =   obj_attr
                 # patch at top level
                 setattr(self.obj      ,  _lowerCAmelCase      ,  _PatchedModuleObj(_lowerCAmelCase      ,  attrs=self.attrs		)		)
                 _lowerCAmelCase						      =   getattr(self.obj      ,  _lowerCAmelCase		)
                 # construct lower levels patches
                 for key in submodules[i + 1 :]:
                     setattr(_lowerCAmelCase      ,  _lowerCAmelCase      ,  _PatchedModuleObj(getattr(_lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase		)      ,  attrs=self.attrs		)		)
                     _lowerCAmelCase						      =   getattr(_lowerCAmelCase      ,  _lowerCAmelCase		)
                 # finally set the target attribute
                 setattr(_lowerCAmelCase      ,  _lowerCAmelCase      ,  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:
             _lowerCAmelCase						      =   getattr(import_module(".".join(_lowerCAmelCase		)		)      ,  _lowerCAmelCase		)
         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      ,  _lowerCAmelCase		) is attr_value:
                 _lowerCAmelCase						      =   getattr(self.obj      ,  _lowerCAmelCase		)
                 setattr(self.obj      ,  _lowerCAmelCase      ,  self.new		)
     elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
         _lowerCAmelCase						      =   globals()["__builtins__"][target_attr]
         setattr(self.obj      ,  _lowerCAmelCase      ,  self.new		)
     else:
         raise RuntimeError(f'''Tried to patch attribute {target_attr} instead of a submodule.'''		)




 def __exit__(						self      ,  *_lowerCAmelCase		)     ->				str:
     for attr in list(self.original		):
         setattr(self.obj      ,  _lowerCAmelCase      ,  self.original.pop(_lowerCAmelCase		)		)




 def 				_snake_case (						self		)     ->				Optional[int]:
     self.__enter__()
     self._active_patches.append(self		)





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

     return self.__exit__()









'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE									=				logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE									=				{
    "facebook/deit-base-distilled-patch16-224": (
        "https://huggingface.co/facebook/deit-base-patch16-224/resolve/main/config.json"
    ),
    # See all DeiT models at https://huggingface.co/models?filter=deit
}

class  lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase    :				Optional[int]								=       "deit"




 def __init__(						self      ,  _lowerCAmelCase=768      ,  _lowerCAmelCase=12      ,  _lowerCAmelCase=12      ,  _lowerCAmelCase=3072      ,  _lowerCAmelCase="gelu"      ,  _lowerCAmelCase=0.0      ,  _lowerCAmelCase=0.0      ,  _lowerCAmelCase=0.02      ,  _lowerCAmelCase=1E-12      ,  _lowerCAmelCase=224      ,  _lowerCAmelCase=16      ,  _lowerCAmelCase=3      ,  _lowerCAmelCase=True      ,  _lowerCAmelCase=16      ,  **_lowerCAmelCase      ,  )     ->				Dict:
     super().__init__(**_lowerCAmelCase		)

     _lowerCAmelCase						      =   hidden_size
     _lowerCAmelCase						      =   num_hidden_layers
     _lowerCAmelCase						      =   num_attention_heads
     _lowerCAmelCase						      =   intermediate_size
     _lowerCAmelCase						      =   hidden_act
     _lowerCAmelCase						      =   hidden_dropout_prob
     _lowerCAmelCase						      =   attention_probs_dropout_prob
     _lowerCAmelCase						      =   initializer_range
     _lowerCAmelCase						      =   layer_norm_eps
     _lowerCAmelCase						      =   image_size
     _lowerCAmelCase						      =   patch_size
     _lowerCAmelCase						      =   num_channels
     _lowerCAmelCase						      =   qkv_bias
     _lowerCAmelCase						      =   encoder_stride







class  lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase    :				List[str]								=       version.parse("1.11"		)




 @property
 def 				_snake_case (						self		)     ->				Mapping[str, Mapping[int, str]]:
     return OrderedDict(
         [
             ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
         ]		)





 @property
 def 				_snake_case (						self		)     ->				float:
     return 1E-4


