
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 				lowerCamelCase__							(       __lowercase  ,		__lowercase  ,		unittest.TestCase):




	'''simple docstring'''




	_A			=  (
	    (
	        TFMobileBertModel,
	        TFMobileBertForMaskedLM,
	        TFMobileBertForNextSentencePrediction,
	        TFMobileBertForPreTraining,
	        TFMobileBertForQuestionAnswering,
	        TFMobileBertForSequenceClassification,
	        TFMobileBertForTokenClassification,
	        TFMobileBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	_A			=  (
	    {
	        'feature-extraction': TFMobileBertModel,
	        'fill-mask': TFMobileBertForMaskedLM,
	        'question-answering': TFMobileBertForQuestionAnswering,
	        'text-classification': TFMobileBertForSequenceClassification,
	        'token-classification': TFMobileBertForTokenClassification,
	        'zero-shot': TFMobileBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	_A			=  False
	_A			=  False







	def      _lowerCamelCase       (      self	:str  ,     a	:Tuple  ,     a	:Tuple  ,     a	:List[Any]=False		)	->				Dict:
								__UpperCamelCase			:     Optional[Any]         =      super()._prepare_for_class(a  ,     a  ,     return_labels=a		)

								if return_labels:
															if model_class in get_values(a		):
																						__UpperCamelCase			:     Optional[int]         =      tf.zeros(self.model_tester.batch_size  ,     dtype=tf.intaa		)

								return inputs_dict




	class 				lowerCamelCase__							(       __lowercase):




		'''simple docstring'''




		def __init__(      self	:int  ,     a	:List[Any]  ,     a	:List[Any]=1_3  ,     a	:Tuple=7  ,     a	:List[str]=True  ,     a	:str=True  ,     a	:Any=True  ,     a	:Union[str, Any]=True  ,     a	:Union[str, Any]=9_9  ,     a	:Dict=3_2  ,     a	:Dict=3_2  ,     a	:int=2  ,     a	:Union[str, Any]=4  ,     a	:int=3_7  ,     a	:Dict="gelu"  ,     a	:int=0.1  ,     a	:Dict=0.1  ,     a	:Optional[int]=5_1_2  ,     a	:Optional[int]=1_6  ,     a	:str=2  ,     a	:Tuple=0.02  ,     a	:List[Any]=3  ,     a	:Dict=4  ,     a	:Tuple=None  ,     )	->				Union[str, Any]:
									__UpperCamelCase			:     Any         =      parent
									__UpperCamelCase			:     Optional[Any]         =      batch_size
									__UpperCamelCase			:     Tuple         =      seq_length
									__UpperCamelCase			:     Optional[int]         =      is_training
									__UpperCamelCase			:     List[str]         =      use_input_mask
									__UpperCamelCase			:     Dict         =      use_token_type_ids
									__UpperCamelCase			:     List[str]         =      use_labels
									__UpperCamelCase			:     Union[str, Any]         =      vocab_size
									__UpperCamelCase			:     Optional[int]         =      hidden_size
									__UpperCamelCase			:     Tuple         =      num_hidden_layers
									__UpperCamelCase			:     Optional[int]         =      num_attention_heads
									__UpperCamelCase			:     int         =      intermediate_size
									__UpperCamelCase			:     List[Any]         =      hidden_act
									__UpperCamelCase			:     Optional[Any]         =      hidden_dropout_prob
									__UpperCamelCase			:     Union[str, Any]         =      attention_probs_dropout_prob
									__UpperCamelCase			:     Dict         =      max_position_embeddings
									__UpperCamelCase			:     Any         =      type_vocab_size
									__UpperCamelCase			:     int         =      type_sequence_label_size
									__UpperCamelCase			:     Dict         =      initializer_range
									__UpperCamelCase			:     Tuple         =      num_labels
									__UpperCamelCase			:     Union[str, Any]         =      num_choices
									__UpperCamelCase			:     Optional[Any]         =      scope
									__UpperCamelCase			:     Optional[int]         =      embedding_size







		def      _lowerCamelCase       (      self	:Union[str, Any]		)	->				Dict:
									__UpperCamelCase			:     Union[str, Any]         =      ids_tensor([self.batch_size, self.seq_length]  ,     self.vocab_size		)

									__UpperCamelCase			:     Optional[Any]         =      None
									if self.use_input_mask:
																__UpperCamelCase			:     Any         =      random_attention_mask([self.batch_size, self.seq_length]		)

									__UpperCamelCase			:     Any         =      None
									if self.use_token_type_ids:
																__UpperCamelCase			:     List[str]         =      ids_tensor([self.batch_size, self.seq_length]  ,     self.type_vocab_size		)

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

									__UpperCamelCase			:     int         =      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	:Union[str, Any]  ,     a	:Tuple  ,     a	:Dict  ,     a	:Dict  ,     a	:Dict  ,     a	:Optional[int]  ,     a	:Optional[int]  ,     a	:Optional[int]		)	->				str:
									__UpperCamelCase			:     Union[str, Any]         =      TFMobileBertModel(config=a		)
									__UpperCamelCase			:     Optional[Any]         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									__UpperCamelCase			:     List[Any]         =      model(a		)

									__UpperCamelCase			:     str         =      [input_ids, input_mask]
									__UpperCamelCase			:     Tuple         =      model(a		)

									__UpperCamelCase			:     Any         =      model(a		)

									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	:Union[str, Any]  ,     a	:Any  ,     a	:Tuple  ,     a	:int  ,     a	:List[Any]  ,     a	:Union[str, Any]  ,     a	:Dict  ,     a	:Optional[int]		)	->				Dict:
									__UpperCamelCase			:     Optional[Any]         =      TFMobileBertForMaskedLM(config=a		)
									__UpperCamelCase			:     Union[str, Any]         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									__UpperCamelCase			:     Optional[Any]         =      model(a		)
									self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.seq_length, self.vocab_size)		)







		def      _lowerCamelCase       (      self	:str  ,     a	:Dict  ,     a	:List[Any]  ,     a	:List[Any]  ,     a	:List[str]  ,     a	:List[str]  ,     a	:Dict  ,     a	:Dict		)	->				Any:
									__UpperCamelCase			:     Optional[Any]         =      TFMobileBertForNextSentencePrediction(config=a		)
									__UpperCamelCase			:     Dict         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									__UpperCamelCase			:     int         =      model(a		)
									self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, 2)		)







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







		def      _lowerCamelCase       (      self	:Union[str, Any]  ,     a	:Tuple  ,     a	:Any  ,     a	:List[Any]  ,     a	:int  ,     a	:Union[str, Any]  ,     a	:str  ,     a	:List[Any]		)	->				int:
									__UpperCamelCase			:     str         =      self.num_choices
									__UpperCamelCase			:     int         =      TFMobileBertForMultipleChoice(config=a		)
									__UpperCamelCase			:     str         =      tf.tile(tf.expand_dims(a  ,     1		)  ,     (1, self.num_choices, 1)		)
									__UpperCamelCase			:     Any         =      tf.tile(tf.expand_dims(a  ,     1		)  ,     (1, self.num_choices, 1)		)
									__UpperCamelCase			:     Dict         =      tf.tile(tf.expand_dims(a  ,     1		)  ,     (1, self.num_choices, 1)		)
									__UpperCamelCase			:     str         =      {
									    "input_ids": multiple_choice_inputs_ids,
									    "attention_mask": multiple_choice_input_mask,
									    "token_type_ids": multiple_choice_token_type_ids,
									}
									__UpperCamelCase			:     str         =      model(a		)
									self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.num_choices)		)







		def      _lowerCamelCase       (      self	:List[Any]  ,     a	:Tuple  ,     a	:List[Any]  ,     a	:str  ,     a	:Optional[Any]  ,     a	:List[str]  ,     a	:Any  ,     a	:Dict		)	->				Union[str, Any]:
									__UpperCamelCase			:     List[str]         =      self.num_labels
									__UpperCamelCase			:     Optional[Any]         =      TFMobileBertForTokenClassification(config=a		)
									__UpperCamelCase			:     int         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									__UpperCamelCase			:     List[Any]         =      model(a		)
									self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.seq_length, self.num_labels)		)







		def      _lowerCamelCase       (      self	:Any  ,     a	:Union[str, Any]  ,     a	:Any  ,     a	:str  ,     a	:str  ,     a	:Dict  ,     a	:str  ,     a	:Optional[Any]		)	->				Any:
									__UpperCamelCase			:     Any         =      TFMobileBertForQuestionAnswering(config=a		)
									__UpperCamelCase			:     Optional[int]         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									__UpperCamelCase			:     Optional[Any]         =      model(a		)
									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	:Any		)	->				List[Any]:
									__UpperCamelCase			:     Any         =      self.prepare_config_and_inputs()
									(
									    (
									    __UpperCamelCase
									)     ,		(
									    __UpperCamelCase
									)     ,		(
									    __UpperCamelCase
									)     ,		(
									    __UpperCamelCase
									)     ,		(
									    __UpperCamelCase
									)     ,		(
									    __UpperCamelCase
									)     ,		(
									    __UpperCamelCase
									)     ,		
									)			:     Any         =      config_and_inputs
									__UpperCamelCase			:     List[str]         =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
									return config, inputs_dict







	def      _lowerCamelCase       (      self	:Tuple		)	->				List[str]:
								__UpperCamelCase			:     Union[str, Any]         =      TFMobileBertModelTest.TFMobileBertModelTester(self		)
								__UpperCamelCase			:     List[str]         =      ConfigTester(self  ,     config_class=a  ,     hidden_size=3_7		)







	def      _lowerCamelCase       (      self	:List[Any]		)	->				str:
								self.config_tester.run_common_tests()







	def      _lowerCamelCase       (      self	:str		)	->				str:
								__UpperCamelCase			:     str         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_model(*a		)







	def      _lowerCamelCase       (      self	:Dict		)	->				List[Any]:
								__UpperCamelCase			:     Optional[Any]         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_masked_lm(*a		)







	def      _lowerCamelCase       (      self	:Union[str, Any]		)	->				int:
								__UpperCamelCase			:     Dict         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_multiple_choice(*a		)







	def      _lowerCamelCase       (      self	:Tuple		)	->				Tuple:
								__UpperCamelCase			:     Dict         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*a		)







	def      _lowerCamelCase       (      self	:Tuple		)	->				List[Any]:
								__UpperCamelCase			:     List[Any]         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_pretraining(*a		)







	def      _lowerCamelCase       (      self	:Dict		)	->				List[Any]:
								__UpperCamelCase			:     Optional[int]         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_question_answering(*a		)







	def      _lowerCamelCase       (      self	:List[str]		)	->				List[Any]:
								__UpperCamelCase			:     Optional[int]         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_sequence_classification(*a		)







	def      _lowerCamelCase       (      self	:str		)	->				List[str]:
								__UpperCamelCase			:     Optional[Any]         =      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_token_classification(*a		)







	@slow
	def      _lowerCamelCase       (      self	:List[str]		)	->				Dict:
								# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								for model_name in ["google/mobilebert-uncased"]:
															__UpperCamelCase			:     Any         =      TFMobileBertModel.from_pretrained(a		)
															self.assertIsNotNone(a		)




@require_tf
class 				lowerCamelCase__							(       unittest.TestCase):




	'''simple docstring'''




	@slow
	def      _lowerCamelCase       (      self	:Tuple		)	->				str:
								__UpperCamelCase			:     Optional[int]         =      TFMobileBertForPreTraining.from_pretrained("google/mobilebert-uncased"		)
								__UpperCamelCase			:     Optional[int]         =      tf.constant([[0, 1, 2, 3, 4, 5]]		)
								__UpperCamelCase			:     List[str]         =      model(a		)[0]

								__UpperCamelCase			:     Any         =      [1, 6, 3_0_5_2_2]
								self.assertEqual(output.shape  ,     a		)

								__UpperCamelCase			:     str         =      tf.constant(
								    [
								        [
								            [-4.5919547, -9.248295, -9.645256],
								            [-6.7306175, -6.440284, -6.6052837],
								            [-7.2743506, -6.7847915, -6.024673],
								        ]
								    ]		)
								tf.debugging.assert_near(output[:, :3, :3]  ,     a  ,     atol=1E-4		)

def 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    int = 200)      ->					int:






							'''simple docstring'''





							__UpperCamelCase			:     Any         =      [1, 2, 5, 10, 20, 50, 100, 200]
							__UpperCamelCase			:     Any         =      [0] * (pence + 1)
							__UpperCamelCase			:     Union[str, Any]         =      1  # base case: 1 way to make 0 pence

							for coin in coins:
														for i in range(_lowerCamelCase		,						pence + 1		,						1):
																					number_of_ways[i] += number_of_ways[i - coin]
							return number_of_ways[pence]


if __name__ == "__main__":
		assert solution(200) == 73682