





'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers.models.distilbert.modeling_tf_distilbert import (
	    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TFDistilBertForMaskedLM,
	    TFDistilBertForMultipleChoice,
	    TFDistilBertForQuestionAnswering,
	    TFDistilBertForSequenceClassification,
	    TFDistilBertForTokenClassification,
	    TFDistilBertModel,
	)







class 			lowerCamelCase					:


					def __init__(					self	:  Dict       ,     __snake_case	:  Tuple       ,     ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		parent
											_snake_case:   Union[str, Any]  					=		13
											_snake_case:   str  					=		7
											_snake_case:   Tuple  					=		True
											_snake_case:   Optional[Any]  					=		True
											_snake_case:   Dict  					=		False
											_snake_case:   str  					=		True
											_snake_case:   Optional[int]  					=		99
											_snake_case:   List[Any]  					=		32
											_snake_case:   Optional[int]  					=		2
											_snake_case:   Union[str, Any]  					=		4
											_snake_case:   Dict  					=		37
											_snake_case:   Tuple  					=		'gelu'
											_snake_case:   Union[str, Any]  					=		0.1
											_snake_case:   str  					=		0.1
											_snake_case:   int  					=		5_12
											_snake_case:   Optional[Any]  					=		16
											_snake_case:   str  					=		2
											_snake_case:   str  					=		0.02
											_snake_case:   Any  					=		3
											_snake_case:   Union[str, Any]  					=		4
											_snake_case:   Tuple  					=		None


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   Any  					=		ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size       )

											_snake_case:   int  					=		None
											if self.use_input_mask:
																	_snake_case:   int  					=		random_attention_mask([self.batch_size, self.seq_length]       )

											_snake_case:   Optional[Any]  					=		None
											_snake_case:   str  					=		None
											_snake_case:   Tuple  					=		None
											if self.use_labels:
																	_snake_case:   Dict  					=		ids_tensor([self.batch_size]       ,     self.type_sequence_label_size       )
																	_snake_case:   List[Any]  					=		ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels       )
																	_snake_case:   int  					=		ids_tensor([self.batch_size]       ,     self.num_choices       )

											_snake_case:   Tuple  					=		DistilBertConfig(
											    vocab_size=self.vocab_size       ,     dim=self.hidden_size       ,     n_layers=self.num_hidden_layers       ,     n_heads=self.num_attention_heads       ,     hidden_dim=self.intermediate_size       ,     hidden_act=self.hidden_act       ,     dropout=self.hidden_dropout_prob       ,     attention_dropout=self.attention_probs_dropout_prob       ,     max_position_embeddings=self.max_position_embeddings       ,     initializer_range=self.initializer_range       ,     )

											return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ,     __snake_case	:  int       ,     __snake_case	:  str       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  int       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		TFDistilBertModel(config=__UpperCamelCase       )
											_snake_case:   List[str]  					=		{'input_ids': input_ids, 'attention_mask': input_mask}

											_snake_case:   List[Any]  					=		model(__UpperCamelCase       )

											_snake_case:   Union[str, Any]  					=		[input_ids, input_mask]

											_snake_case:   Union[str, Any]  					=		model(__UpperCamelCase       )

											self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ,     __snake_case	:  Any       ,     __snake_case	:  List[str]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  int       ,     __snake_case	:  List[str]       ,     __snake_case	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Tuple  					=		TFDistilBertForMaskedLM(config=__UpperCamelCase       )
											_snake_case:   Optional[int]  					=		{'input_ids': input_ids, 'attention_mask': input_mask}
											_snake_case:   Dict  					=		model(__UpperCamelCase       )
											self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ,     __snake_case	:  Any       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  str       ,     __snake_case	:  Dict       ,     __snake_case	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   int  					=		TFDistilBertForQuestionAnswering(config=__UpperCamelCase       )
											_snake_case:   List[str]  					=		{
											    'input_ids': input_ids,
											    'attention_mask': input_mask,
											}
											_snake_case:   str  					=		model(__UpperCamelCase       )
											self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length)       )
											self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[Any]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		self.num_labels
											_snake_case:   Dict  					=		TFDistilBertForSequenceClassification(__UpperCamelCase       )
											_snake_case:   Optional[int]  					=		{'input_ids': input_ids, 'attention_mask': input_mask}
											_snake_case:   Optional[int]  					=		model(__UpperCamelCase       )
											self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  List[Any]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  int       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.num_choices
											_snake_case:   List[str]  					=		TFDistilBertForMultipleChoice(__UpperCamelCase       )
											_snake_case:   Optional[int]  					=		tf.tile(tf.expand_dims(__UpperCamelCase       ,     1       )       ,     (1, self.num_choices, 1)       )
											_snake_case:   List[str]  					=		tf.tile(tf.expand_dims(__UpperCamelCase       ,     1       )       ,     (1, self.num_choices, 1)       )
											_snake_case:   Optional[int]  					=		{
											    'input_ids': multiple_choice_inputs_ids,
											    'attention_mask': multiple_choice_input_mask,
											}
											_snake_case:   Union[str, Any]  					=		model(__UpperCamelCase       )
											self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_choices)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ,     __snake_case	:  List[str]       ,     __snake_case	:  str       ,     __snake_case	:  str       ,     __snake_case	:  str       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.num_labels
											_snake_case:   List[str]  					=		TFDistilBertForTokenClassification(__UpperCamelCase       )
											_snake_case:   Union[str, Any]  					=		{'input_ids': input_ids, 'attention_mask': input_mask}
											_snake_case:   Optional[Any]  					=		model(__UpperCamelCase       )
											self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels)       )




					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   str  					=		self.prepare_config_and_inputs()
											((_snake_case)					,						(_snake_case)					,						(_snake_case)					,						(_snake_case)					,						(_snake_case)					,						(_snake_case)):   int  					=		config_and_inputs
											_snake_case:   List[Any]  					=		{'input_ids': input_ids, 'attention_mask': input_mask}
											return config, inputs_dict







@require_tf
class 			lowerCamelCase					(						__UpperCAmelCase     ,							__UpperCAmelCase     ,							unittest.TestCase  ):
					_SCREAMING_SNAKE_CASE							   =    (
					    (
					        TFDistilBertModel,
					        TFDistilBertForMaskedLM,
					        TFDistilBertForQuestionAnswering,
					        TFDistilBertForSequenceClassification,
					        TFDistilBertForTokenClassification,
					        TFDistilBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else None
					)
					_SCREAMING_SNAKE_CASE							   =    (
					    {
					        "feature-extraction": TFDistilBertModel,
					        "fill-mask": TFDistilBertForMaskedLM,
					        "question-answering": TFDistilBertForQuestionAnswering,
					        "text-classification": TFDistilBertForSequenceClassification,
					        "token-classification": TFDistilBertForTokenClassification,
					        "zero-shot": TFDistilBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   str  					=		TFDistilBertModelTester(self       )
											_snake_case:   Any  					=		ConfigTester(self       ,     config_class=__UpperCamelCase       ,     dim=37       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											self.config_tester.run_common_tests()


					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_model(*__UpperCamelCase       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_masked_lm(*__UpperCamelCase       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   str  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_question_answering(*__UpperCamelCase       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_sequence_classification(*__UpperCamelCase       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_multiple_choice(*__UpperCamelCase       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_token_classification(*__UpperCamelCase       )




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]       ):
																	_snake_case:   Optional[int]  					=		TFDistilBertModel.from_pretrained(__UpperCamelCase       )
																	self.assertIsNotNone(__UpperCamelCase       )







@require_tf
class 			lowerCamelCase					(						unittest.TestCase  ):


					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   int  					=		TFDistilBertModel.from_pretrained('distilbert-base-uncased'       )
											_snake_case:   Any  					=		tf.constant([[0, 1, 2, 3, 4, 5]]       )
											_snake_case:   Union[str, Any]  					=		model(__UpperCamelCase       )[0]

											_snake_case:   Tuple  					=		[1, 6, 7_68]
											self.assertEqual(output.shape       ,     __UpperCamelCase       )

											_snake_case:   str  					=		tf.constant(
											    [
											        [
											            [0.19_261_885, -0.13_732_955, 0.4_119_799],
											            [0.22_150_156, -0.07_422_661, 0.39_037_204],
											            [0.22_756_018, -0.0_896_414, 0.3_701_467],
											        ]
											    ]       )
											tf.debugging.assert_near(output[:, :3, :3]       ,     __UpperCamelCase       ,     atol=1e-4       )












'''simple docstring'''






from typing import TYPE_CHECKING

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


A   : Optional[Any]             =			{'configuration_deit': ['DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DeiTConfig', 'DeiTOnnxConfig']}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A   : str             =			['DeiTFeatureExtractor']
		A   : Optional[int]             =			['DeiTImageProcessor']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A   : Optional[Any]             =			[
		    'DEIT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'DeiTForImageClassification',
		    'DeiTForImageClassificationWithTeacher',
		    'DeiTForMaskedImageModeling',
		    'DeiTModel',
		    'DeiTPreTrainedModel',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A   : int             =			[
		    'TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'TFDeiTForImageClassification',
		    'TFDeiTForImageClassificationWithTeacher',
		    'TFDeiTForMaskedImageModeling',
		    'TFDeiTModel',
		    'TFDeiTPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_deit import DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, DeiTConfig, DeiTOnnxConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_deit import DeiTFeatureExtractor
				from .image_processing_deit import DeiTImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_deit import (
				    DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DeiTForImageClassification,
				    DeiTForImageClassificationWithTeacher,
				    DeiTForMaskedImageModeling,
				    DeiTModel,
				    DeiTPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_deit import (
				    TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFDeiTForImageClassification,
				    TFDeiTForImageClassificationWithTeacher,
				    TFDeiTForMaskedImageModeling,
				    TFDeiTModel,
				    TFDeiTPreTrainedModel,
				)


else:
		import sys

		A   : Union[str, Any]             =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





