


'''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   lowercase      :

		"""simple docstring"""

		def __init__(						self       ,  UpperCamelCase_       ,  ):

							'''simple docstring'''


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




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :str				   =					ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size				)

							UpperCamelCase__  :List[str]				   =					None
							if self.use_input_mask:
												UpperCamelCase__  :Tuple				   =					random_attention_mask([self.batch_size, self.seq_length]				)

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

							UpperCamelCase__  :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        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					TFDistilBertModel(config=UpperCamelCase_				)
							UpperCamelCase__  :int				   =					{'''input_ids''': input_ids, '''attention_mask''': input_mask}

							UpperCamelCase__  :int				   =					model(UpperCamelCase_				)

							UpperCamelCase__  :Optional[Any]				   =					[input_ids, input_mask]

							UpperCamelCase__  :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_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


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




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :int				   =					TFDistilBertForQuestionAnswering(config=UpperCamelCase_				)
							UpperCamelCase__  :int				   =					{
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							}
							UpperCamelCase__  :int				   =					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        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


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




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


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




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


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




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


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



@require_tf
class   lowercase      (				A__      ,						A__      ,						unittest.TestCase   ):

		"""simple docstring"""

		_a       					=							(
		    (
		        TFDistilBertModel,
		        TFDistilBertForMaskedLM,
		        TFDistilBertForQuestionAnswering,
		        TFDistilBertForSequenceClassification,
		        TFDistilBertForTokenClassification,
		        TFDistilBertForMultipleChoice,
		    )
		    if is_tf_available()
		    else None
		)
		_a       					=							(
		    {
		        'feature-extraction': TFDistilBertModel,
		        'fill-mask': TFDistilBertForMaskedLM,
		        'question-answering': TFDistilBertForQuestionAnswering,
		        'text-classification': TFDistilBertForSequenceClassification,
		        'token-classification': TFDistilBertForTokenClassification,
		        'zero-shot': TFDistilBertForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		_a       					=							False
		_a       					=							False




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Dict				   =					TFDistilBertModelTester(self				)
							UpperCamelCase__  :Dict				   =					ConfigTester(self       ,  config_class=UpperCamelCase_       ,  dim=37				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[Any]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_model(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Dict				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_masked_lm(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[int]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_question_answering(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_sequence_classification(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_multiple_choice(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[int]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_token_classification(*UpperCamelCase_				)




		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]				):
												UpperCamelCase__  :Tuple				   =					TFDistilBertModel.from_pretrained(UpperCamelCase_				)
												self.assertIsNotNone(UpperCamelCase_				)



@require_tf
class   lowercase      (				unittest.TestCase   ):

		"""simple docstring"""

		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


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

							UpperCamelCase__  :Union[str, Any]				   =					[1, 6, 768]
							self.assertEqual(output.shape       ,  UpperCamelCase_				)

							UpperCamelCase__  :Tuple				   =					tf.constant(
							    [
							        [
							            [0.19261885, -0.13732955, 0.4119799],
							            [0.22150156, -0.07422661, 0.39037204],
							            [0.22756018, -0.0896414, 0.3701467],
							        ]
							    ]				)
							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_tokenizers_available,
    is_torch_available,
)


__snake_case				 =	{
    '''configuration_convbert''': ['''CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ConvBertConfig''', '''ConvBertOnnxConfig'''],
    '''tokenization_convbert''': ['''ConvBertTokenizer'''],
}

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

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case				 =	[
		    '''CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ConvBertForMaskedLM''',
		    '''ConvBertForMultipleChoice''',
		    '''ConvBertForQuestionAnswering''',
		    '''ConvBertForSequenceClassification''',
		    '''ConvBertForTokenClassification''',
		    '''ConvBertLayer''',
		    '''ConvBertModel''',
		    '''ConvBertPreTrainedModel''',
		    '''load_tf_weights_in_convbert''',
		]


try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case				 =	[
		    '''TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFConvBertForMaskedLM''',
		    '''TFConvBertForMultipleChoice''',
		    '''TFConvBertForQuestionAnswering''',
		    '''TFConvBertForSequenceClassification''',
		    '''TFConvBertForTokenClassification''',
		    '''TFConvBertLayer''',
		    '''TFConvBertModel''',
		    '''TFConvBertPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
		from .tokenization_convbert import ConvBertTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_convbert_fast import ConvBertTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_convbert import (
				    CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ConvBertForMaskedLM,
				    ConvBertForMultipleChoice,
				    ConvBertForQuestionAnswering,
				    ConvBertForSequenceClassification,
				    ConvBertForTokenClassification,
				    ConvBertLayer,
				    ConvBertModel,
				    ConvBertPreTrainedModel,
				    load_tf_weights_in_convbert,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_convbert import (
				    TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFConvBertForMaskedLM,
				    TFConvBertForMultipleChoice,
				    TFConvBertForQuestionAnswering,
				    TFConvBertForSequenceClassification,
				    TFConvBertForTokenClassification,
				    TFConvBertLayer,
				    TFConvBertModel,
				    TFConvBertPreTrainedModel,
				)


else:
		import sys

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