




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       :  List[Any]      ,   __lowerCamelCase       :  Optional[Any]      ,   )      ->  Optional[Any]:
							a					=    parent
							a					=    13
							a					=    7
							a					=    True
							a					=    True
							a					=    False
							a					=    True
							a					=    99
							a					=    32
							a					=    2
							a					=    4
							a					=    37
							a					=    "gelu"
							a					=    0.1
							a					=    0.1
							a					=    5_12
							a					=    16
							a					=    2
							a					=    0.02
							a					=    3
							a					=    4
							a					=    None





				def 							__UpperCAmelCase							(   self       :  int							)      ->  Any:
							a					=    ids_tensor([self.batch_size, self.seq_length]      ,   self.vocab_size							)

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

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

							a					=    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 							__UpperCAmelCase							(   self       :  Union[str, Any]      ,   __lowerCamelCase       :  int      ,   __lowerCamelCase       :  List[Any]      ,   __lowerCamelCase       :  Optional[int]      ,   __lowerCamelCase       :  List[Any]      ,   __lowerCamelCase       :  Dict      ,   __lowerCamelCase       :  int							)      ->  Any:
							a					=    TFDistilBertModel(config=__lowerCamelCase							)
							a					=    {"input_ids": input_ids, "attention_mask": input_mask}

							a					=    model(__lowerCamelCase							)

							a					=    [input_ids, input_mask]

							a					=    model(__lowerCamelCase							)

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





				def 							__UpperCAmelCase							(   self       :  Dict      ,   __lowerCamelCase       :  int      ,   __lowerCamelCase       :  Optional[int]      ,   __lowerCamelCase       :  Optional[int]      ,   __lowerCamelCase       :  str      ,   __lowerCamelCase       :  Tuple      ,   __lowerCamelCase       :  Dict							)      ->  Any:
							a					=    TFDistilBertForMaskedLM(config=__lowerCamelCase							)
							a					=    {"input_ids": input_ids, "attention_mask": input_mask}
							a					=    model(__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.seq_length, self.vocab_size)							)





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





				def 							__UpperCAmelCase							(   self       :  Dict      ,   __lowerCamelCase       :  List[str]      ,   __lowerCamelCase       :  Optional[Any]      ,   __lowerCamelCase       :  List[str]      ,   __lowerCamelCase       :  Union[str, Any]      ,   __lowerCamelCase       :  Any      ,   __lowerCamelCase       :  Dict							)      ->  Dict:
							a					=    self.num_choices
							a					=    TFDistilBertForMultipleChoice(__lowerCamelCase							)
							a					=    tf.tile(tf.expand_dims(__lowerCamelCase      ,   1							)      ,   (1, self.num_choices, 1)							)
							a					=    tf.tile(tf.expand_dims(__lowerCamelCase      ,   1							)      ,   (1, self.num_choices, 1)							)
							a					=    {
							    "input_ids": multiple_choice_inputs_ids,
							    "attention_mask": multiple_choice_input_mask,
							}
							a					=    model(__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.num_choices)							)





				def 							__UpperCAmelCase							(   self       :  int      ,   __lowerCamelCase       :  Tuple      ,   __lowerCamelCase       :  Optional[int]      ,   __lowerCamelCase       :  Tuple      ,   __lowerCamelCase       :  Tuple      ,   __lowerCamelCase       :  Optional[Any]      ,   __lowerCamelCase       :  Any							)      ->  Dict:
							a					=    self.num_labels
							a					=    TFDistilBertForTokenClassification(__lowerCamelCase							)
							a					=    {"input_ids": input_ids, "attention_mask": input_mask}
							a					=    model(__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.seq_length, self.num_labels)							)





				def 							__UpperCAmelCase							(   self       :  Tuple							)      ->  Optional[Any]:
							a					=    self.prepare_config_and_inputs()
							((a)					,	(a)					,	(a)					,	(a)					,	(a)					,	(a))					=    config_and_inputs
							a					=    {"input_ids": input_ids, "attention_mask": input_mask}
							return config, inputs_dict




@require_tf
class 					snake_case__							(_UpperCamelCase					, _UpperCamelCase					, unittest.TestCase     ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_ :							Optional[int]											=      (
				    (
				        TFDistilBertModel,
				        TFDistilBertForMaskedLM,
				        TFDistilBertForQuestionAnswering,
				        TFDistilBertForSequenceClassification,
				        TFDistilBertForTokenClassification,
				        TFDistilBertForMultipleChoice,
				    )
				    if is_tf_available()
				    else None
				)
				SCREAMING_SNAKE_CASE_ :							Tuple											=      (
				    {
				        """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_ :							Optional[int]											=      False
				SCREAMING_SNAKE_CASE_ :							List[str]											=      False





				def 							__UpperCAmelCase							(   self       :  Optional[int]							)      ->  Any:
							a					=    TFDistilBertModelTester(self							)
							a					=    ConfigTester(self      ,   config_class=__lowerCamelCase      ,   dim=37							)





				def 							__UpperCAmelCase							(   self       :  List[Any]							)      ->  Union[str, Any]:
							self.config_tester.run_common_tests()





				def 							__UpperCAmelCase							(   self       :  Any							)      ->  Any:
							a					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_model(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(   self       :  Dict							)      ->  Union[str, Any]:
							a					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_masked_lm(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(   self       :  Tuple							)      ->  Dict:
							a					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_question_answering(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(   self       :  Tuple							)      ->  Optional[int]:
							a					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_sequence_classification(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(   self       :  List[str]							)      ->  List[str]:
							a					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_multiple_choice(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(   self       :  List[Any]							)      ->  int:
							a					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_token_classification(*__lowerCamelCase							)





				@slow
				def 							__UpperCAmelCase							(   self       :  List[Any]							)      ->  Union[str, Any]:
							for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]							):
										a					=    TFDistilBertModel.from_pretrained(__lowerCamelCase							)
										self.assertIsNotNone(__lowerCamelCase							)




@require_tf
class 					snake_case__							(unittest.TestCase     ):
				"""simple docstring"""



				@slow
				def 							__UpperCAmelCase							(   self       :  Optional[int]							)      ->  int:
							a					=    TFDistilBertModel.from_pretrained("distilbert-base-uncased"							)
							a					=    tf.constant([[0, 1, 2, 3, 4, 5]]							)
							a					=    model(__lowerCamelCase							)[0]

							a					=    [1, 6, 7_68]
							self.assertEqual(output.shape      ,   __lowerCamelCase							)

							a					=    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]      ,   __lowerCamelCase      ,   atol=1e-4							)












__lowerCAmelCase	:       List[Any]     =	{str(digit): digit**5 for digit in range(10)}




def     __magic_name__       (				A	:      int     ):






			'''simple docstring'''







			return sum(DIGITS_FIFTH_POWER[digit] for digit in str(A     )     )




def     __magic_name__       (				):






			'''simple docstring'''







			return sum(
			    number
			    for number in range(1000,						1000000     )
			    if number == digits_fifth_powers_sum(A     )     )


if __name__ == "__main__":
		print(solution())






