


from importlib import import_module

from .logging import get_logger


a_					:    Dict          =    get_logger(__name__)




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





class  a     :
 _lowerCAmelCase 					=	[]
 def __init__( self      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__=None						)					->							Any:
      _a			      =							obj
      _a			      =							target
      _a			      =							new
      _a			      =							target.split('.'						)[0]
      _a			      =							{}
      _a			      =							attrs or []
 def __enter__( self						)					->							List[str]:
      *_a      ,   _a			      =							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(__magic_name__						)						):
           try:
                _a			      =							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__():
                _a			      =							getattr(self.obj      ,				__magic_name__						)
                # 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(__magic_name__      ,				_PatchedModuleObj						) and obj_attr._original_module is submodule)
                ):
                     _a			      =							obj_attr
                     # patch at top level
                     setattr(self.obj      ,				__magic_name__      ,				_PatchedModuleObj(__magic_name__      ,				attrs=self.attrs						)						)
                     _a			      =							getattr(self.obj      ,				__magic_name__						)
                     # construct lower levels patches
                     for key in submodules[i + 1 :]:
                          setattr(__magic_name__      ,				__magic_name__      ,				_PatchedModuleObj(getattr(__magic_name__      ,				__magic_name__      ,				__magic_name__						)      ,				attrs=self.attrs						)						)
                          _a			      =							getattr(__magic_name__      ,				__magic_name__						)
                     # finally set the target attribute
                     setattr(__magic_name__      ,				__magic_name__      ,				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:
                _a			      =							getattr(import_module('.'.join(__magic_name__						)						)      ,				__magic_name__						)
           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      ,				__magic_name__						) is attr_value:
                     _a			      =							getattr(self.obj      ,				__magic_name__						)
                     setattr(self.obj      ,				__magic_name__      ,				self.new						)
      elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
           _a			      =							globals()['__builtins__'][target_attr]
           setattr(self.obj      ,				__magic_name__      ,				self.new						)
      else:
           raise RuntimeError(f'Tried to patch attribute {target_attr} instead of a submodule.'						)
 def __exit__( self      ,				*__magic_name__						)					->							Tuple:
      for attr in list(self.original						):
           setattr(self.obj      ,				__magic_name__      ,				self.original.pop(__magic_name__						)						)
 def 							__UpperCAmelCase		( self						)					->							int:
      self.__enter__()
      self._active_patches.append(self						)




 def 							__UpperCAmelCase		( 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 typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


a_					:    int          =    {"configuration_vit": ["VIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ViTConfig", "ViTOnnxConfig"]}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    List[Any]          =    ["ViTFeatureExtractor"]
 a_					:    Optional[int]          =    ["ViTImageProcessor"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    Optional[int]          =    [
     "VIT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "ViTForImageClassification",
     "ViTForMaskedImageModeling",
     "ViTModel",
     "ViTPreTrainedModel",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    Any          =    [
     "TFViTForImageClassification",
     "TFViTModel",
     "TFViTPreTrainedModel",
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    Dict          =    [
     "FlaxViTForImageClassification",
     "FlaxViTModel",
     "FlaxViTPreTrainedModel",
 ]

if TYPE_CHECKING:
 from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_vit import ViTFeatureExtractor
  from .image_processing_vit import ViTImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_vit import (
      VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      ViTForImageClassification,
      ViTForMaskedImageModeling,
      ViTModel,
      ViTPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
 import sys

 a_					:    List[str]          =    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

