


"""simple docstring"""



import inspect
import unittest

from datasets import load_dataset
from packaging import version

from transformers import BeitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch
  from torch import nn

  from transformers import (
      MODEL_MAPPING,
      BeitForImageClassification,
      BeitForMaskedImageModeling,
      BeitForSemanticSegmentation,
      BeitModel,
  )
  from transformers.models.beit.modeling_beit import BEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  import PIL
  from PIL import Image

  from transformers import BeitImageProcessor







class _lowerCAmelCase       :







   def __init__(			self		,			UpperCamelCase__		,			UpperCamelCase__=100		,			UpperCamelCase__=13		,			UpperCamelCase__=30		,			UpperCamelCase__=2		,			UpperCamelCase__=3		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=32		,			UpperCamelCase__=4		,			UpperCamelCase__=4		,			UpperCamelCase__=37		,			UpperCamelCase__="gelu"		,			UpperCamelCase__=0.1		,			UpperCamelCase__=0.1		,			UpperCamelCase__=10		,			UpperCamelCase__=0.02		,			UpperCamelCase__=3		,			UpperCamelCase__=None		,			UpperCamelCase__=[0, 1, 2, 3]		,			)			->	List[str]:

       '''simple docstring'''




       snake_case					:   int         =					parent
       snake_case					:   str         =					100
       snake_case					:   Optional[Any]         =					batch_size
       snake_case					:   List[Any]         =					image_size
       snake_case					:   List[Any]         =					patch_size
       snake_case					:   Dict         =					num_channels
       snake_case					:   List[str]         =					is_training
       snake_case					:   int         =					use_labels
       snake_case					:   List[Any]         =					hidden_size
       snake_case					:   Optional[Any]         =					num_hidden_layers
       snake_case					:   Optional[Any]         =					num_attention_heads
       snake_case					:   List[str]         =					intermediate_size
       snake_case					:   str         =					hidden_act
       snake_case					:   Union[str, Any]         =					hidden_dropout_prob
       snake_case					:   Optional[Any]         =					attention_probs_dropout_prob
       snake_case					:   Optional[Any]         =					type_sequence_label_size
       snake_case					:   List[str]         =					initializer_range
       snake_case					:   Dict         =					scope
       snake_case					:   List[str]         =					out_indices
       snake_case					:   Any         =					num_labels

       # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
       snake_case					:   int         =					(image_size // patch_size) ** 2
       snake_case					:   List[str]         =					num_patches + 1







   def 				lowerCamelCase	(			self		)			->	Union[str, Any]:

       '''simple docstring'''




       snake_case					:   Tuple         =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

       snake_case					:   str         =					None
       snake_case					:   Tuple         =					None
       if self.use_labels:
           snake_case					:   Optional[int]         =					ids_tensor([self.batch_size]		,			self.type_sequence_label_size		)
           snake_case					:   List[Any]         =					ids_tensor([self.batch_size, self.image_size, self.image_size]		,			self.num_labels		)

       snake_case					:   Dict         =					self.get_config()

       return config, pixel_values, labels, pixel_labels







   def 				lowerCamelCase	(			self		)			->	Dict:

       '''simple docstring'''




       return BeitConfig(
           vocab_size=self.vocab_size		,			image_size=self.image_size		,			patch_size=self.patch_size		,			num_channels=self.num_channels		,			hidden_size=self.hidden_size		,			num_hidden_layers=self.num_hidden_layers		,			num_attention_heads=self.num_attention_heads		,			intermediate_size=self.intermediate_size		,			hidden_act=self.hidden_act		,			hidden_dropout_prob=self.hidden_dropout_prob		,			attention_probs_dropout_prob=self.attention_probs_dropout_prob		,			is_decoder=UpperCamelCase__		,			initializer_range=self.initializer_range		,			out_indices=self.out_indices		,			)







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	Optional[Any]:

       '''simple docstring'''




       snake_case					:   Tuple         =					BeitModel(config=UpperCamelCase__		)
       model.to(UpperCamelCase__		)
       model.eval()
       snake_case					:   List[Any]         =					model(UpperCamelCase__		)
       self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, self.seq_length, self.hidden_size)		)







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	List[str]:

       '''simple docstring'''




       snake_case					:   Optional[int]         =					BeitForMaskedImageModeling(config=UpperCamelCase__		)
       model.to(UpperCamelCase__		)
       model.eval()
       snake_case					:   List[Any]         =					model(UpperCamelCase__		)
       self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length - 1, self.vocab_size)		)







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	int:

       '''simple docstring'''




       snake_case					:   Dict         =					self.type_sequence_label_size
       snake_case					:   Any         =					BeitForImageClassification(UpperCamelCase__		)
       model.to(UpperCamelCase__		)
       model.eval()
       snake_case					:   str         =					model(UpperCamelCase__		,			labels=UpperCamelCase__		)
       self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.type_sequence_label_size)		)

       # test greyscale images
       snake_case					:   int         =					1
       snake_case					:   Optional[int]         =					BeitForImageClassification(UpperCamelCase__		)
       model.to(UpperCamelCase__		)
       model.eval()

       snake_case					:   Optional[Any]         =					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
       snake_case					:   List[str]         =					model(UpperCamelCase__		,			labels=UpperCamelCase__		)
       self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.type_sequence_label_size)		)







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	List[str]:

       '''simple docstring'''




       snake_case					:   Tuple         =					self.num_labels
       snake_case					:   Any         =					BeitForSemanticSegmentation(UpperCamelCase__		)
       model.to(UpperCamelCase__		)
       model.eval()
       snake_case					:   List[str]         =					model(UpperCamelCase__		)
       self.parent.assertEqual(
           result.logits.shape		,			(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)		)
       snake_case					:   Any         =					model(UpperCamelCase__		,			labels=UpperCamelCase__		)
       self.parent.assertEqual(
           result.logits.shape		,			(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)		)







   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       snake_case					:   Optional[Any]         =					self.prepare_config_and_inputs()
       snake_case      ,snake_case      ,snake_case      ,snake_case					:   List[str]         =					config_and_inputs
       snake_case					:   List[str]         =					{"pixel_values": pixel_values}
       return config, inputs_dict







@require_torch
class _lowerCAmelCase       (   snake_case_					,							snake_case_					,							unittest.TestCase			):
   __UpperCAmelCase				: Any													=						(
       (BeitModel, BeitForImageClassification, BeitForMaskedImageModeling, BeitForSemanticSegmentation)
       if is_torch_available()
       else ()
   )
   __UpperCAmelCase				: Tuple													=						(
       {
           '''feature-extraction''': BeitModel,
           '''image-classification''': BeitForImageClassification,
           '''image-segmentation''': BeitForSemanticSegmentation,
       }
       if is_torch_available()
       else {}
   )

   __UpperCAmelCase				: Dict													=						False
   __UpperCAmelCase				: Optional[Any]													=						False
   __UpperCAmelCase				: int													=						False







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       snake_case					:   str         =					BeitModelTester(self		)
       snake_case					:   Tuple         =					ConfigTester(self		,			config_class=UpperCamelCase__		,			has_text_modality=UpperCamelCase__		,			hidden_size=37		)







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       self.config_tester.run_common_tests()







   @unittest.skip(reason="BEiT does not use inputs_embeds"		)
   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       pass







   @require_torch_multi_gpu
   @unittest.skip(reason="BEiT has some layers using `add_module` which doesn't work well with `nn.DataParallel`"		)
   def 				lowerCamelCase	(			self		)			->	Optional[int]:

       '''simple docstring'''




       pass







   def 				lowerCamelCase	(			self		)			->	Union[str, Any]:

       '''simple docstring'''




       snake_case      ,snake_case					:   Any         =					self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           snake_case					:   str         =					model_class(UpperCamelCase__		)
           self.assertIsInstance(model.get_input_embeddings()		,			(nn.Module)		)
           snake_case					:   Optional[Any]         =					model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(UpperCamelCase__		,			nn.Linear		)		)







   def 				lowerCamelCase	(			self		)			->	Union[str, Any]:

       '''simple docstring'''




       snake_case      ,snake_case					:   List[Any]         =					self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           snake_case					:   List[Any]         =					model_class(UpperCamelCase__		)
           snake_case					:   Any         =					inspect.signature(model.forward		)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           snake_case					:   List[Any]         =					[*signature.parameters.keys()]

           snake_case					:   int         =					["pixel_values"]
           self.assertListEqual(arg_names[:1]		,			UpperCamelCase__		)







   def 				lowerCamelCase	(			self		)			->	int:

       '''simple docstring'''




       snake_case					:   Union[str, Any]         =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCamelCase__		)







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       snake_case					:   List[str]         =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__		)







   def 				lowerCamelCase	(			self		)			->	List[Any]:

       '''simple docstring'''




       snake_case					:   List[Any]         =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__		)







   def 				lowerCamelCase	(			self		)			->	int:

       '''simple docstring'''




       snake_case					:   Any         =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_semantic_segmentation(*UpperCamelCase__		)







   def 				lowerCamelCase	(			self		)			->	Optional[int]:

       '''simple docstring'''




       if not self.model_tester.is_training:
           return

       snake_case      ,snake_case					:   Union[str, Any]         =					self.model_tester.prepare_config_and_inputs_for_common()
       snake_case					:   Any         =					True

       for model_class in self.all_model_classes:
           # we don't test BeitForMaskedImageModeling
           if model_class in [*get_values(UpperCamelCase__		), BeitForMaskedImageModeling]:
               continue

           snake_case					:   int         =					model_class(UpperCamelCase__		)
           model.to(UpperCamelCase__		)
           model.train()
           snake_case					:   Dict         =					self._prepare_for_class(UpperCamelCase__		,			UpperCamelCase__		,			return_labels=UpperCamelCase__		)
           snake_case					:   Tuple         =					model(**UpperCamelCase__		).loss
           loss.backward()







   def 				lowerCamelCase	(			self		)			->	Dict:

       '''simple docstring'''




       snake_case      ,snake_case					:   Union[str, Any]         =					self.model_tester.prepare_config_and_inputs_for_common()
       if not self.model_tester.is_training:
           return

       snake_case					:   List[str]         =					False
       snake_case					:   str         =					True

       for model_class in self.all_model_classes:
           # we don't test BeitForMaskedImageModeling
           if (
               model_class in [*get_values(UpperCamelCase__		), BeitForMaskedImageModeling]
               or not model_class.supports_gradient_checkpointing
           ):
               continue

           snake_case					:   Union[str, Any]         =					model_class(UpperCamelCase__		)
           model.gradient_checkpointing_enable()
           model.to(UpperCamelCase__		)
           model.train()
           snake_case					:   Optional[Any]         =					self._prepare_for_class(UpperCamelCase__		,			UpperCamelCase__		,			return_labels=UpperCamelCase__		)
           snake_case					:   List[str]         =					model(**UpperCamelCase__		).loss
           loss.backward()







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       snake_case      ,snake_case					:   List[Any]         =					self.model_tester.prepare_config_and_inputs_for_common()

       snake_case					:   Tuple         =					_config_zero_init(UpperCamelCase__		)
       for model_class in self.all_model_classes:
           snake_case					:   Union[str, Any]         =					model_class(config=UpperCamelCase__		)
           for name, param in model.named_parameters():
               # we skip lambda parameters as these require special initial values
               # determined by config.layer_scale_init_value
               if "lambda" in name:
                   continue
               if param.requires_grad:
                   self.assertIn(
                       ((param.data.mean() * 1e9).round() / 1e9).item()		,			[0.0, 1.0]		,			msg=F'Parameter {name} of model {model_class} seems not properly initialized'		,			)







   @slow
   def 				lowerCamelCase	(			self		)			->	int:

       '''simple docstring'''




       for model_name in BEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           snake_case					:   str         =					BeitModel.from_pretrained(UpperCamelCase__		)
           self.assertIsNotNone(UpperCamelCase__		)







def 						__lowerCAmelCase		(		)			->		int:


    """simple docstring"""





    snake_case					:   Dict         =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
    return image







@require_torch
@require_vision
class _lowerCAmelCase       (   unittest.TestCase			):







   @cached_property
   def 				lowerCamelCase	(			self		)			->	int:

       '''simple docstring'''




       return BeitImageProcessor.from_pretrained("microsoft/beit-base-patch16-224"		) if is_vision_available() else None







   @slow
   def 				lowerCamelCase	(			self		)			->	Optional[int]:

       '''simple docstring'''




       snake_case					:   Dict         =					BeitForMaskedImageModeling.from_pretrained("microsoft/beit-base-patch16-224-pt22k"		).to(UpperCamelCase__		)

       snake_case					:   Union[str, Any]         =					self.default_image_processor
       snake_case					:   Tuple         =					prepare_img()
       snake_case					:   Union[str, Any]         =					image_processor(images=UpperCamelCase__		,			return_tensors="pt"		).pixel_values.to(UpperCamelCase__		)

       # prepare bool_masked_pos
       snake_case					:   Union[str, Any]         =					torch.ones((1, 196)		,			dtype=torch.bool		).to(UpperCamelCase__		)

       # forward pass
       with torch.no_grad():
           snake_case					:   Union[str, Any]         =					model(pixel_values=UpperCamelCase__		,			bool_masked_pos=UpperCamelCase__		)
       snake_case					:   str         =					outputs.logits

       # verify the logits
       snake_case					:   Optional[Any]         =					torch.Size((1, 196, 8192)		)
       self.assertEqual(logits.shape		,			UpperCamelCase__		)

       snake_case					:   Dict         =					torch.tensor(
           [[-3.2437, 0.5072, -13.9174], [-3.2456, 0.4948, -13.9401], [-3.2033, 0.5121, -13.8550]]		).to(UpperCamelCase__		)

       self.assertTrue(torch.allclose(logits[bool_masked_pos][:3, :3]		,			UpperCamelCase__		,			atol=1e-2		)		)







   @slow
   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       snake_case					:   List[Any]         =					BeitForImageClassification.from_pretrained("microsoft/beit-base-patch16-224"		).to(UpperCamelCase__		)

       snake_case					:   Dict         =					self.default_image_processor
       snake_case					:   Tuple         =					prepare_img()
       snake_case					:   Union[str, Any]         =					image_processor(images=UpperCamelCase__		,			return_tensors="pt"		).to(UpperCamelCase__		)

       # forward pass
       with torch.no_grad():
           snake_case					:   Union[str, Any]         =					model(**UpperCamelCase__		)
       snake_case					:   Dict         =					outputs.logits

       # verify the logits
       snake_case					:   Dict         =					torch.Size((1, 1000)		)
       self.assertEqual(logits.shape		,			UpperCamelCase__		)

       snake_case					:   Optional[Any]         =					torch.tensor([-1.2385, -1.0987, -1.0108]		).to(UpperCamelCase__		)

       self.assertTrue(torch.allclose(logits[0, :3]		,			UpperCamelCase__		,			atol=1e-4		)		)

       snake_case					:   List[Any]         =					281
       self.assertEqual(logits.argmax(-1		).item()		,			UpperCamelCase__		)







   @slow
   def 				lowerCamelCase	(			self		)			->	str:

       '''simple docstring'''




       snake_case					:   Union[str, Any]         =					BeitForImageClassification.from_pretrained("microsoft/beit-large-patch16-224-pt22k-ft22k"		).to(
           UpperCamelCase__		)

       snake_case					:   Optional[Any]         =					self.default_image_processor
       snake_case					:   Union[str, Any]         =					prepare_img()
       snake_case					:   Optional[int]         =					image_processor(images=UpperCamelCase__		,			return_tensors="pt"		).to(UpperCamelCase__		)

       # forward pass
       with torch.no_grad():
           snake_case					:   Optional[int]         =					model(**UpperCamelCase__		)
       snake_case					:   Dict         =					outputs.logits

       # verify the logits
       snake_case					:   Optional[int]         =					torch.Size((1, 2_1841)		)
       self.assertEqual(logits.shape		,			UpperCamelCase__		)

       snake_case					:   str         =					torch.tensor([1.6881, -0.2787, 0.5901]		).to(UpperCamelCase__		)

       self.assertTrue(torch.allclose(logits[0, :3]		,			UpperCamelCase__		,			atol=1e-4		)		)

       snake_case					:   int         =					2396
       self.assertEqual(logits.argmax(-1		).item()		,			UpperCamelCase__		)







   @slow
   def 				lowerCamelCase	(			self		)			->	List[Any]:

       '''simple docstring'''




       snake_case					:   List[Any]         =					BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"		)
       snake_case					:   str         =					model.to(UpperCamelCase__		)

       snake_case					:   str         =					BeitImageProcessor(do_resize=UpperCamelCase__		,			size=640		,			do_center_crop=UpperCamelCase__		)

       snake_case					:   List[Any]         =					load_dataset("hf-internal-testing/fixtures_ade20k"		,			split="test"		)
       snake_case					:   Dict         =					Image.open(ds[0]["file"]		)
       snake_case					:   Optional[Any]         =					image_processor(images=UpperCamelCase__		,			return_tensors="pt"		).to(UpperCamelCase__		)

       # forward pass
       with torch.no_grad():
           snake_case					:   str         =					model(**UpperCamelCase__		)
       snake_case					:   Tuple         =					outputs.logits

       # verify the logits
       snake_case					:   Tuple         =					torch.Size((1, 150, 160, 160)		)
       self.assertEqual(logits.shape		,			UpperCamelCase__		)

       snake_case					:   str         =					version.parse(PIL.__version__		) < version.parse("9.0.0"		)

       if is_pillow_less_than_a:
           snake_case					:   Dict         =					torch.tensor(
               [
                   [[-4.9225, -2.3954, -3.0522], [-2.8822, -1.0046, -1.7561], [-2.9549, -1.3228, -2.1347]],
                   [[-5.8168, -3.4129, -4.0778], [-3.8651, -2.2214, -3.0277], [-3.8356, -2.4643, -3.3535]],
                   [[-0.0078, 3.9952, 4.0754], [2.9856, 4.6944, 5.0035], [3.2413, 4.7813, 4.9969]],
               ]		,			device=UpperCamelCase__		,			)
       else:
           snake_case					:   List[Any]         =					torch.tensor(
               [
                   [[-4.8960, -2.3688, -3.0355], [-2.8478, -0.9836, -1.7418], [-2.9449, -1.3332, -2.1456]],
                   [[-5.8081, -3.4124, -4.1006], [-3.8561, -2.2081, -3.0323], [-3.8365, -2.4601, -3.3669]],
                   [[-0.0309, 3.9868, 4.0540], [2.9640, 4.6877, 4.9976], [3.2081, 4.7690, 4.9942]],
               ]		,			device=UpperCamelCase__		,			)

       self.assertTrue(torch.allclose(logits[0, :3, :3, :3]		,			UpperCamelCase__		,			atol=1e-4		)		)







   @slow
   def 				lowerCamelCase	(			self		)			->	Dict:

       '''simple docstring'''




       snake_case					:   List[Any]         =					BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"		)
       snake_case					:   List[str]         =					model.to(UpperCamelCase__		)

       snake_case					:   List[Any]         =					BeitImageProcessor(do_resize=UpperCamelCase__		,			size=640		,			do_center_crop=UpperCamelCase__		)

       snake_case					:   Union[str, Any]         =					load_dataset("hf-internal-testing/fixtures_ade20k"		,			split="test"		)
       snake_case					:   List[Any]         =					Image.open(ds[0]["file"]		)
       snake_case					:   Optional[int]         =					image_processor(images=UpperCamelCase__		,			return_tensors="pt"		).to(UpperCamelCase__		)

       # forward pass
       with torch.no_grad():
           snake_case					:   Tuple         =					model(**UpperCamelCase__		)

       snake_case					:   Optional[int]         =					outputs.logits.detach().cpu()

       snake_case					:   Any         =					image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase__		,			target_sizes=[(500, 300)]		)
       snake_case					:   Optional[int]         =					torch.Size((500, 300)		)
       self.assertEqual(segmentation[0].shape		,			UpperCamelCase__		)

       snake_case					:   Union[str, Any]         =					image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase__		)
       snake_case					:   Optional[Any]         =					torch.Size((160, 160)		)
       self.assertEqual(segmentation[0].shape		,			UpperCamelCase__		)









"""simple docstring"""



from typing import TYPE_CHECKING

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


__snake_case         =					{
    """configuration_distilbert""": [
        """DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """DistilBertConfig""",
        """DistilBertOnnxConfig""",
    ],
    """tokenization_distilbert""": ["""DistilBertTokenizer"""],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case         =					["""DistilBertTokenizerFast"""]

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

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case         =					[
      """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:
  __snake_case         =					[
      """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

  __snake_case         =					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





