"""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        snake_case :




					"""simple docstring"""

					def __init__(       self     :			int					,lowerCamelCase__     :			Optional[int]					,):
									UpperCAmelCase__    =							parent
									UpperCAmelCase__    =							13
									UpperCAmelCase__    =							7
									UpperCAmelCase__    =							True
									UpperCAmelCase__    =							True
									UpperCAmelCase__    =							False
									UpperCAmelCase__    =							True
									UpperCAmelCase__    =							99
									UpperCAmelCase__    =							32
									UpperCAmelCase__    =							2
									UpperCAmelCase__    =							4
									UpperCAmelCase__    =							37
									UpperCAmelCase__    =							'gelu'
									UpperCAmelCase__    =							0.1
									UpperCAmelCase__    =							0.1
									UpperCAmelCase__    =							512
									UpperCAmelCase__    =							16
									UpperCAmelCase__    =							2
									UpperCAmelCase__    =							0.0_2
									UpperCAmelCase__    =							3
									UpperCAmelCase__    =							4
									UpperCAmelCase__    =							None







					def 	__lowerCAmelCase		(       self     :			Dict    ):
									UpperCAmelCase__    =							ids_tensor([self.batch_size, self.seq_length]					,self.vocab_size    )

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

									UpperCAmelCase__    =							None
									UpperCAmelCase__    =							None
									UpperCAmelCase__    =							None
									if self.use_labels:
													UpperCAmelCase__    =							ids_tensor([self.batch_size]					,self.type_sequence_label_size    )
													UpperCAmelCase__    =							ids_tensor([self.batch_size, self.seq_length]					,self.num_labels    )
													UpperCAmelCase__    =							ids_tensor([self.batch_size]					,self.num_choices    )

									UpperCAmelCase__    =							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     :			Union[str, Any]					,lowerCamelCase__     :			List[str]					,lowerCamelCase__     :			Optional[Any]					,lowerCamelCase__     :			int					,lowerCamelCase__     :			Union[str, Any]					,lowerCamelCase__     :			List[str]					,lowerCamelCase__     :			Any    ):
									UpperCAmelCase__    =							TFDistilBertModel(config=lowerCamelCase__    )
									UpperCAmelCase__    =							{'input_ids': input_ids, 'attention_mask': input_mask}

									UpperCAmelCase__    =							model(lowerCamelCase__    )

									UpperCAmelCase__    =							[input_ids, input_mask]

									UpperCAmelCase__    =							model(lowerCamelCase__    )

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







					def 	__lowerCAmelCase		(       self     :			Union[str, Any]					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			str					,lowerCamelCase__     :			Optional[Any]					,lowerCamelCase__     :			Union[str, Any]					,lowerCamelCase__     :			str					,lowerCamelCase__     :			Any    ):
									UpperCAmelCase__    =							TFDistilBertForMaskedLM(config=lowerCamelCase__    )
									UpperCAmelCase__    =							{'input_ids': input_ids, 'attention_mask': input_mask}
									UpperCAmelCase__    =							model(lowerCamelCase__    )
									self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.seq_length, self.vocab_size)    )







					def 	__lowerCAmelCase		(       self     :			Dict					,lowerCamelCase__     :			List[str]					,lowerCamelCase__     :			Optional[Any]					,lowerCamelCase__     :			int					,lowerCamelCase__     :			List[str]					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			Optional[Any]    ):
									UpperCAmelCase__    =							TFDistilBertForQuestionAnswering(config=lowerCamelCase__    )
									UpperCAmelCase__    =							{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									}
									UpperCAmelCase__    =							model(lowerCamelCase__    )
									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     :			List[Any]					,lowerCamelCase__     :			int					,lowerCamelCase__     :			str					,lowerCamelCase__     :			Optional[Any]					,lowerCamelCase__     :			Optional[Any]					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			Any    ):
									UpperCAmelCase__    =							self.num_labels
									UpperCAmelCase__    =							TFDistilBertForSequenceClassification(lowerCamelCase__    )
									UpperCAmelCase__    =							{'input_ids': input_ids, 'attention_mask': input_mask}
									UpperCAmelCase__    =							model(lowerCamelCase__    )
									self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.num_labels)    )







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







					def 	__lowerCAmelCase		(       self     :			Dict					,lowerCamelCase__     :			str					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			Tuple					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			List[str]    ):
									UpperCAmelCase__    =							self.num_labels
									UpperCAmelCase__    =							TFDistilBertForTokenClassification(lowerCamelCase__    )
									UpperCAmelCase__    =							{'input_ids': input_ids, 'attention_mask': input_mask}
									UpperCAmelCase__    =							model(lowerCamelCase__    )
									self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.seq_length, self.num_labels)    )







					def 	__lowerCAmelCase		(       self     :			Tuple    ):
									UpperCAmelCase__    =							self.prepare_config_and_inputs()
									((UpperCAmelCase__)   ,			(UpperCAmelCase__)   ,			(UpperCAmelCase__)   ,			(UpperCAmelCase__)   ,			(UpperCAmelCase__)   ,			(UpperCAmelCase__))    =							config_and_inputs
									UpperCAmelCase__    =							{'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict






@require_tf
class        snake_case (				__UpperCAmelCase   ,					__UpperCAmelCase   ,					unittest.TestCase       ):




					"""simple docstring"""

					snake_case__       					=				(
					    (
					        TFDistilBertModel,
					        TFDistilBertForMaskedLM,
					        TFDistilBertForQuestionAnswering,
					        TFDistilBertForSequenceClassification,
					        TFDistilBertForTokenClassification,
					        TFDistilBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else None
					)
					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 {}
					)
					snake_case__       					=				False
					snake_case__       					=				False







					def 	__lowerCAmelCase		(       self     :			Optional[int]    ):
									UpperCAmelCase__    =							TFDistilBertModelTester(self    )
									UpperCAmelCase__    =							ConfigTester(self					,config_class=lowerCamelCase__					,dim=37    )







					def 	__lowerCAmelCase		(       self     :			Any    ):
									self.config_tester.run_common_tests()







					def 	__lowerCAmelCase		(       self     :			str    ):
									UpperCAmelCase__    =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_model(*lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			Dict    ):
									UpperCAmelCase__    =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_masked_lm(*lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			Optional[int]    ):
									UpperCAmelCase__    =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_question_answering(*lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			Tuple    ):
									UpperCAmelCase__    =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			List[Any]    ):
									UpperCAmelCase__    =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			int    ):
									UpperCAmelCase__    =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_token_classification(*lowerCamelCase__    )







					@slow
					def 	__lowerCAmelCase		(       self     :			Optional[int]    ):
									for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]    ):
													UpperCAmelCase__    =							TFDistilBertModel.from_pretrained(lowerCamelCase__    )
													self.assertIsNotNone(lowerCamelCase__    )






@require_tf
class        snake_case (				unittest.TestCase       ):




					"""simple docstring"""

					@slow
					def 	__lowerCAmelCase		(       self     :			Tuple    ):
									UpperCAmelCase__    =							TFDistilBertModel.from_pretrained('distilbert-base-uncased'    )
									UpperCAmelCase__    =							tf.constant([[0, 1, 2, 3, 4, 5]]    )
									UpperCAmelCase__    =							model(lowerCamelCase__    )[0]

									UpperCAmelCase__    =							[1, 6, 768]
									self.assertEqual(output.shape					,lowerCamelCase__    )

									UpperCAmelCase__    =							tf.constant(
									    [
									        [
									            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
									            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
									            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
									        ]
									    ]    )
									tf.debugging.assert_near(output[:, :3, :3]					,lowerCamelCase__					,atol=1e-4    )




"""simple docstring"""






import warnings
from functools import wraps
from typing import Callable



def 						a_		(      lowerCamelCase ):

				@wraps(lowerCamelCase )
				def _inner_fn(*lowerCamelCase      ,    **lowerCamelCase ):
								warnings.warn(
								    (f'''\'{fn.__name__}\' is experimental and might be subject to breaking changes in the future.''')      ,    lowerCamelCase      ,    )
								return fn(*lowerCamelCase      ,    **lowerCamelCase )

				return _inner_fn



