"""simple docstring"""


from importlib import import_module

from .logging import get_logger


lowerCAmelCase_:					int     =					get_logger(__name__)






class    a__    :


			def __init__(     self,				_UpperCAmelCase,				_UpperCAmelCase=None  ):
								'''simple docstring'''



								lowercase__				 =							attrs or []
								if module is not None:
													for key in module.__dict__:
																		if key in attrs or not key.startswith("__"  ):
																							setattr(self,				__A,				getattr(__A,				__A  )  )
								lowercase__				 =							module._original_module if isinstance(__A,				_PatchedModuleObj  ) else module






class    a__    :
			snake_case_							=      []


			def __init__(     self,				_UpperCAmelCase,				_UpperCAmelCase,				_UpperCAmelCase,				_UpperCAmelCase=None  ):
								'''simple docstring'''



								lowercase__				 =							obj
								lowercase__				 =							target
								lowercase__				 =							new
								lowercase__				 =							target.split("."  )[0]
								lowercase__				 =							{}
								lowercase__				 =							attrs or []


			def __enter__(     self  ):
								'''simple docstring'''



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


			def __exit__(     self,				*_UpperCAmelCase  ):
								'''simple docstring'''



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


			def 	snake_case__	(     self  ):
								'''simple docstring'''



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


			def 	snake_case__	(     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__()





"""simple docstring"""


from typing import TYPE_CHECKING

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


lowerCAmelCase_:					Union[str, Any]     =					{
    "configuration_distilbert": [
        "DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "DistilBertConfig",
        "DistilBertOnnxConfig",
    ],
    "tokenization_distilbert": ["DistilBertTokenizer"],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_:					Union[str, Any]     =					["DistilBertTokenizerFast"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_:					Any     =					[
     "DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "DistilBertForMaskedLM",
     "DistilBertForMultipleChoice",
     "DistilBertForQuestionAnswering",
     "DistilBertForSequenceClassification",
     "DistilBertForTokenClassification",
     "DistilBertModel",
     "DistilBertPreTrainedModel",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_:					Tuple     =					[
     "TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFDistilBertForMaskedLM",
     "TFDistilBertForMultipleChoice",
     "TFDistilBertForQuestionAnswering",
     "TFDistilBertForSequenceClassification",
     "TFDistilBertForTokenClassification",
     "TFDistilBertMainLayer",
     "TFDistilBertModel",
     "TFDistilBertPreTrainedModel",
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_:					Optional[Any]     =					[
     "FlaxDistilBertForMaskedLM",
     "FlaxDistilBertForMultipleChoice",
     "FlaxDistilBertForQuestionAnswering",
     "FlaxDistilBertForSequenceClassification",
     "FlaxDistilBertForTokenClassification",
     "FlaxDistilBertModel",
     "FlaxDistilBertPreTrainedModel",
 ]


if TYPE_CHECKING:
 from .configuration_distilbert import (
     DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
     DistilBertConfig,
     DistilBertOnnxConfig,
 )
 from .tokenization_distilbert import DistilBertTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_distilbert_fast import DistilBertTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_distilbert import (
      DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      DistilBertForMaskedLM,
      DistilBertForMultipleChoice,
      DistilBertForQuestionAnswering,
      DistilBertForSequenceClassification,
      DistilBertForTokenClassification,
      DistilBertModel,
      DistilBertPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_distilbert import (
      TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFDistilBertForMaskedLM,
      TFDistilBertForMultipleChoice,
      TFDistilBertForQuestionAnswering,
      TFDistilBertForSequenceClassification,
      TFDistilBertForTokenClassification,
      TFDistilBertMainLayer,
      TFDistilBertModel,
      TFDistilBertPreTrainedModel,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_distilbert import (
      FlaxDistilBertForMaskedLM,
      FlaxDistilBertForMultipleChoice,
      FlaxDistilBertForQuestionAnswering,
      FlaxDistilBertForSequenceClassification,
      FlaxDistilBertForTokenClassification,
      FlaxDistilBertModel,
      FlaxDistilBertPreTrainedModel,
  )

else:
 import sys

 lowerCAmelCase_:					Optional[int]     =					_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




