
'''simple docstring'''
from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
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 import (
		    TF_MODEL_FOR_PRETRAINING_MAPPING,
		    TFMobileBertForMaskedLM,
		    TFMobileBertForMultipleChoice,
		    TFMobileBertForNextSentencePrediction,
		    TFMobileBertForPreTraining,
		    TFMobileBertForQuestionAnswering,
		    TFMobileBertForSequenceClassification,
		    TFMobileBertForTokenClassification,
		    TFMobileBertModel,
		)







@require_tf
class   a_ (      UpperCamelCase__		,  UpperCamelCase__		,  unittest.TestCase					):
			lowerCamelCase__	:			Optional[int]       =    (
			    (
			        TFMobileBertModel,
			        TFMobileBertForMaskedLM,
			        TFMobileBertForNextSentencePrediction,
			        TFMobileBertForPreTraining,
			        TFMobileBertForQuestionAnswering,
			        TFMobileBertForSequenceClassification,
			        TFMobileBertForTokenClassification,
			        TFMobileBertForMultipleChoice,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCamelCase__	:			List[Any]       =    (
			    {
			        'feature-extraction': TFMobileBertModel,
			        'fill-mask': TFMobileBertForMaskedLM,
			        'question-answering': TFMobileBertForQuestionAnswering,
			        'text-classification': TFMobileBertForSequenceClassification,
			        'token-classification': TFMobileBertForTokenClassification,
			        'zero-shot': TFMobileBertForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			lowerCamelCase__	:			Tuple       =    False
			lowerCamelCase__	:			str       =    False




			def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase=False	):
				a_      				=						super()._prepare_for_class(UpperCAmelCase					,   UpperCAmelCase					,   return_labels=UpperCAmelCase	)

				if return_labels:
					if model_class in get_values(UpperCAmelCase	):
						a_      				=						tf.zeros(self.model_tester.batch_size					,   dtype=tf.intaa	)

				return inputs_dict







			class   a_ (      UpperCamelCase__					):




						def __init__(       self					,   UpperCAmelCase					,   UpperCAmelCase=13					,   UpperCAmelCase=7					,   UpperCAmelCase=True					,   UpperCAmelCase=True					,   UpperCAmelCase=True					,   UpperCAmelCase=True					,   UpperCAmelCase=99					,   UpperCAmelCase=32					,   UpperCAmelCase=32					,   UpperCAmelCase=2					,   UpperCAmelCase=4					,   UpperCAmelCase=37					,   UpperCAmelCase="gelu"					,   UpperCAmelCase=0.1					,   UpperCAmelCase=0.1					,   UpperCAmelCase=5_12					,   UpperCAmelCase=16					,   UpperCAmelCase=2					,   UpperCAmelCase=0.02					,   UpperCAmelCase=3					,   UpperCAmelCase=4					,   UpperCAmelCase=None					,   ):
							a_      				=						parent
							a_      				=						batch_size
							a_      				=						seq_length
							a_      				=						is_training
							a_      				=						use_input_mask
							a_      				=						use_token_type_ids
							a_      				=						use_labels
							a_      				=						vocab_size
							a_      				=						hidden_size
							a_      				=						num_hidden_layers
							a_      				=						num_attention_heads
							a_      				=						intermediate_size
							a_      				=						hidden_act
							a_      				=						hidden_dropout_prob
							a_      				=						attention_probs_dropout_prob
							a_      				=						max_position_embeddings
							a_      				=						type_vocab_size
							a_      				=						type_sequence_label_size
							a_      				=						initializer_range
							a_      				=						num_labels
							a_      				=						num_choices
							a_      				=						scope
							a_      				=						embedding_size




						def 					lowerCAmelCase__					(       self	):
							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
							if self.use_token_type_ids:
								a_      				=						ids_tensor([self.batch_size, self.seq_length]					,   self.type_vocab_size	)

							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_      				=						MobileBertConfig(
							    vocab_size=self.vocab_size					,   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					,   max_position_embeddings=self.max_position_embeddings					,   type_vocab_size=self.type_vocab_size					,   initializer_range=self.initializer_range					,   embedding_size=self.embedding_size					,   )

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




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						TFMobileBertModel(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						model(UpperCAmelCase	)

							a_      				=						[input_ids, input_mask]
							a_      				=						model(UpperCAmelCase	)

							a_      				=						model(UpperCAmelCase	)

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




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						TFMobileBertForMaskedLM(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						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					,   UpperCAmelCase	):
							a_      				=						TFMobileBertForNextSentencePrediction(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						model(UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape					,   (self.batch_size, 2)	)




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						TFMobileBertForPreTraining(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						model(UpperCAmelCase	)
							self.parent.assertEqual(
							    result.prediction_logits.shape					,   (self.batch_size, self.seq_length, self.vocab_size)	)
							self.parent.assertEqual(result.seq_relationship_logits.shape					,   (self.batch_size, 2)	)




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						self.num_labels
							a_      				=						TFMobileBertForSequenceClassification(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						model(UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_labels)	)




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						self.num_choices
							a_      				=						TFMobileBertForMultipleChoice(config=UpperCAmelCase	)
							a_      				=						tf.tile(tf.expand_dims(UpperCAmelCase					,   1	)					,   (1, self.num_choices, 1)	)
							a_      				=						tf.tile(tf.expand_dims(UpperCAmelCase					,   1	)					,   (1, self.num_choices, 1)	)
							a_      				=						tf.tile(tf.expand_dims(UpperCAmelCase					,   1	)					,   (1, self.num_choices, 1)	)
							a_      				=						{
							    """input_ids""": multiple_choice_inputs_ids,
							    """attention_mask""": multiple_choice_input_mask,
							    """token_type_ids""": multiple_choice_token_type_ids,
							}
							a_      				=						model(UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_choices)	)




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						self.num_labels
							a_      				=						TFMobileBertForTokenClassification(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						model(UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.seq_length, self.num_labels)	)




						def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	):
							a_      				=						TFMobileBertForQuestionAnswering(config=UpperCAmelCase	)
							a_      				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
							a_      				=						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	):
							a_      				=						self.prepare_config_and_inputs()
							(
							    (
							    a_
							)				,  (
							    a_
							)				,  (
							    a_
							)				,  (
							    a_
							)				,  (
							    a_
							)				,  (
							    a_
							)				,  (
							    a_
							)				,  
							)      				=						config_and_inputs
							a_      				=						{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
							return config, inputs_dict







			def 					lowerCAmelCase__					(       self	):
				a_      				=						TFMobileBertModelTest.TFMobileBertModelTester(self	)
				a_      				=						ConfigTester(self					,   config_class=UpperCAmelCase					,   hidden_size=37	)




			def 					lowerCAmelCase__					(       self	):
				self.config_tester.run_common_tests()




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_model(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_masked_lm(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_multiple_choice(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_pretraining(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_question_answering(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_sequence_classification(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_token_classification(*UpperCAmelCase	)






			@slow
			def 					lowerCAmelCase__					(       self	):
				# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				for model_name in ["google/mobilebert-uncased"]:
					a_      				=						TFMobileBertModel.from_pretrained(UpperCAmelCase	)
					self.assertIsNotNone(UpperCAmelCase	)







@require_tf
class   a_ (      unittest.TestCase					):




			@slow
			def 					lowerCAmelCase__					(       self	):
				a_      				=						TFMobileBertForPreTraining.from_pretrained("""google/mobilebert-uncased"""	)
				a_      				=						tf.constant([[0, 1, 2, 3, 4, 5]]	)
				a_      				=						model(UpperCAmelCase	)[0]

				a_      				=						[1, 6, 3_05_22]
				self.assertEqual(output.shape					,   UpperCAmelCase	)

				a_      				=						tf.constant(
				    [
				        [
				            [-4.5_91_95_47, -9.24_82_95, -9.64_52_56],
				            [-6.7_30_61_75, -6.44_02_84, -6.6_05_28_37],
				            [-7.2_74_35_06, -6.7_84_79_15, -6.02_46_73],
				        ]
				    ]	)
				tf.debugging.assert_near(output[:, :3, :3]					,   UpperCAmelCase					,   atol=1e-4	)


'''simple docstring'''
import math






def      UpperCamelCase_				(      A__ = 1_00						):
	a_      				=						sum(i * i for i in range(1  ,      n + 1						)						)
	a_      				=						int(math.pow(sum(range(1  ,      n + 1						)						)  ,      2						)						)
	return square_of_sum - sum_of_squares


if __name__ == "__main__":
		print(F"""{solution() = }""")
