





'''simple docstring'''






import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
		import tensorflow as tf

		from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments







@require_tf
class 			lowerCamelCase					(						unittest.TestCase  ):


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ,     __snake_case	:  Any       ):





											'''simple docstring'''





											for model_result in results.values():
																	for batch_size, sequence_length in zip(model_result['bs']       ,     model_result['ss']       ):
																							_snake_case:   Optional[Any]  					=		model_result['result'][batch_size][sequence_length]
																							self.assertIsNotNone(__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		'sshleifer/tiny-gpt2'
											_snake_case:   List[Any]  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     eager_mode=__snake_case       ,     multi_process=__snake_case       ,     )
											_snake_case:   List[str]  					=		TensorFlowBenchmark(__snake_case       )
											_snake_case:   Any  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   List[Any]  					=		'sgugger/tiny-distilbert-classification'
											_snake_case:   str  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     multi_process=__snake_case       ,     only_pretrain_model=__snake_case       ,     )
											_snake_case:   Union[str, Any]  					=		TensorFlowBenchmark(__snake_case       )
											_snake_case:   Tuple  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		'sshleifer/tiny-gpt2'
											_snake_case:   Union[str, Any]  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     multi_process=__snake_case       ,     )
											_snake_case:   Optional[Any]  					=		TensorFlowBenchmark(__snake_case       )
											_snake_case:   List[Any]  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		'sshleifer/tiny-gpt2'
											_snake_case:   Optional[int]  					=		AutoConfig.from_pretrained(__snake_case       )
											_snake_case:   Any  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     eager_mode=__snake_case       ,     multi_process=__snake_case       ,     )
											_snake_case:   Optional[int]  					=		TensorFlowBenchmark(__snake_case       ,     [config]       )
											_snake_case:   Dict  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   int  					=		'sshleifer/tiny-gpt2'
											_snake_case:   str  					=		AutoConfig.from_pretrained(__snake_case       )
											_snake_case:   List[str]  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     multi_process=__snake_case       ,     )
											_snake_case:   Dict  					=		TensorFlowBenchmark(__snake_case       ,     [config]       )
											_snake_case:   Union[str, Any]  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											_snake_case:   int  					=		'sshleifer/tiny-gpt2'
											_snake_case:   Tuple  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     multi_process=__snake_case       ,     )
											_snake_case:   Optional[Any]  					=		TensorFlowBenchmark(__snake_case       )
											_snake_case:   Tuple  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_train_result       )
											self.check_results_dict_not_empty(results.memory_train_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		'sshleifer/tiny-gpt2'
											_snake_case:   str  					=		AutoConfig.from_pretrained(__snake_case       )
											_snake_case:   int  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     multi_process=__snake_case       ,     )
											_snake_case:   List[Any]  					=		TensorFlowBenchmark(__snake_case       ,     [config]       )
											_snake_case:   Dict  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_train_result       )
											self.check_results_dict_not_empty(results.memory_train_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		'patrickvonplaten/t5-tiny-random'
											_snake_case:   Any  					=		AutoConfig.from_pretrained(__snake_case       )
											_snake_case:   Optional[int]  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     multi_process=__snake_case       ,     )
											_snake_case:   List[str]  					=		TensorFlowBenchmark(__snake_case       ,     configs=[config]       )
											_snake_case:   int  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					@unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices('GPU'       )       ) == 0       ,     'Cannot do xla on CPU.'       )
					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   Tuple  					=		'sshleifer/tiny-gpt2'
											_snake_case:   List[str]  					=		TensorFlowBenchmarkArguments(
											    models=[MODEL_ID]       ,     training=__snake_case       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     use_xla=__snake_case       ,     multi_process=__snake_case       ,     )
											_snake_case:   int  					=		TensorFlowBenchmark(__snake_case       )
											_snake_case:   Dict  					=		benchmark.run()
											self.check_results_dict_not_empty(results.time_inference_result       )
											self.check_results_dict_not_empty(results.memory_inference_result       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		'sshleifer/tiny-gpt2'
											with tempfile.TemporaryDirectory() as tmp_dir:
																	_snake_case:   Union[str, Any]  					=		TensorFlowBenchmarkArguments(
																	    models=[MODEL_ID]       ,     inference=__snake_case       ,     save_to_csv=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     inference_time_csv_file=os.path.join(__snake_case       ,     'inf_time.csv'       )       ,     inference_memory_csv_file=os.path.join(__snake_case       ,     'inf_mem.csv'       )       ,     env_info_csv_file=os.path.join(__snake_case       ,     'env.csv'       )       ,     multi_process=__snake_case       ,     )
																	_snake_case:   Any  					=		TensorFlowBenchmark(__snake_case       )
																	benchmark.run()
																	self.assertTrue(Path(os.path.join(__snake_case       ,     'inf_time.csv'       )       ).exists()       )
																	self.assertTrue(Path(os.path.join(__snake_case       ,     'inf_mem.csv'       )       ).exists()       )
																	self.assertTrue(Path(os.path.join(__snake_case       ,     'env.csv'       )       ).exists()       )




					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		'sshleifer/tiny-gpt2'

											def _check_summary_is_not_empty(__snake_case	:  int       ):
																	self.assertTrue(hasattr(__snake_case       ,     'sequential'       )       )
																	self.assertTrue(hasattr(__snake_case       ,     'cumulative'       )       )
																	self.assertTrue(hasattr(__snake_case       ,     'current'       )       )
																	self.assertTrue(hasattr(__snake_case       ,     'total'       )       )

											with tempfile.TemporaryDirectory() as tmp_dir:
																	_snake_case:   Any  					=		TensorFlowBenchmarkArguments(
																	    models=[MODEL_ID]       ,     inference=__snake_case       ,     sequence_lengths=[8]       ,     batch_sizes=[1]       ,     log_filename=os.path.join(__snake_case       ,     'log.txt'       )       ,     log_print=__snake_case       ,     trace_memory_line_by_line=__snake_case       ,     eager_mode=__snake_case       ,     multi_process=__snake_case       ,     )
																	_snake_case:   str  					=		TensorFlowBenchmark(__snake_case       )
																	_snake_case:   str  					=		benchmark.run()
																	_check_summary_is_not_empty(result.inference_summary       )
																	self.assertTrue(Path(os.path.join(__snake_case       ,     'log.txt'       )       ).exists()       )












'''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 			lowerCamelCase					(						__UpperCAmelCase     ,							__UpperCAmelCase     ,							unittest.TestCase  ):
					_SCREAMING_SNAKE_CASE							   =    (
					    (
					        TFMobileBertModel,
					        TFMobileBertForMaskedLM,
					        TFMobileBertForNextSentencePrediction,
					        TFMobileBertForPreTraining,
					        TFMobileBertForQuestionAnswering,
					        TFMobileBertForSequenceClassification,
					        TFMobileBertForTokenClassification,
					        TFMobileBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else ()
					)
					_SCREAMING_SNAKE_CASE							   =    (
					    {
					        "feature-extraction": TFMobileBertModel,
					        "fill-mask": TFMobileBertForMaskedLM,
					        "question-answering": TFMobileBertForQuestionAnswering,
					        "text-classification": TFMobileBertForSequenceClassification,
					        "token-classification": TFMobileBertForTokenClassification,
					        "zero-shot": TFMobileBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Optional[int]=False       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		super()._prepare_for_class(__snake_case       ,     __snake_case       ,     return_labels=__snake_case       )

											if return_labels:
																	if model_class in get_values(__snake_case       ):
																							_snake_case:   List[str]  					=		tf.zeros(self.model_tester.batch_size       ,     dtype=tf.intaa       )

											return inputs_dict







					class 			lowerCamelCase					(						__UpperCAmelCase  ):


										def __init__(					self	:  List[str]       ,     __snake_case	:  int       ,     __snake_case	:  Any=13       ,     __snake_case	:  Dict=7       ,     __snake_case	:  Tuple=True       ,     __snake_case	:  Dict=True       ,     __snake_case	:  List[Any]=True       ,     __snake_case	:  Tuple=True       ,     __snake_case	:  List[str]=99       ,     __snake_case	:  List[Any]=32       ,     __snake_case	:  Optional[Any]=32       ,     __snake_case	:  int=2       ,     __snake_case	:  Optional[int]=4       ,     __snake_case	:  Union[str, Any]=37       ,     __snake_case	:  List[str]="gelu"       ,     __snake_case	:  Tuple=0.1       ,     __snake_case	:  Optional[int]=0.1       ,     __snake_case	:  Optional[int]=5_12       ,     __snake_case	:  Dict=16       ,     __snake_case	:  List[Any]=2       ,     __snake_case	:  List[str]=0.02       ,     __snake_case	:  List[Any]=3       ,     __snake_case	:  Any=4       ,     __snake_case	:  Tuple=None       ,     ):





																'''simple docstring'''





																_snake_case:   List[str]  					=		parent
																_snake_case:   Any  					=		batch_size
																_snake_case:   Union[str, Any]  					=		seq_length
																_snake_case:   List[str]  					=		is_training
																_snake_case:   Optional[int]  					=		use_input_mask
																_snake_case:   Tuple  					=		use_token_type_ids
																_snake_case:   Optional[int]  					=		use_labels
																_snake_case:   str  					=		vocab_size
																_snake_case:   str  					=		hidden_size
																_snake_case:   Optional[Any]  					=		num_hidden_layers
																_snake_case:   List[str]  					=		num_attention_heads
																_snake_case:   str  					=		intermediate_size
																_snake_case:   Optional[int]  					=		hidden_act
																_snake_case:   Any  					=		hidden_dropout_prob
																_snake_case:   Optional[int]  					=		attention_probs_dropout_prob
																_snake_case:   Any  					=		max_position_embeddings
																_snake_case:   int  					=		type_vocab_size
																_snake_case:   Tuple  					=		type_sequence_label_size
																_snake_case:   Optional[Any]  					=		initializer_range
																_snake_case:   Tuple  					=		num_labels
																_snake_case:   Optional[Any]  					=		num_choices
																_snake_case:   Union[str, Any]  					=		scope
																_snake_case:   Any  					=		embedding_size


										def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





																'''simple docstring'''





																_snake_case:   int  					=		ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size       )

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

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

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

																_snake_case:   str  					=		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    SCREAMING_SNAKE_CASE_		(					self	:  int       ,     __snake_case	:  int       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  int       ,     __snake_case	:  List[str]       ,     __snake_case	:  List[Any]       ,     __snake_case	:  List[str]       ):





																'''simple docstring'''





																_snake_case:   int  					=		TFMobileBertModel(config=__snake_case       )
																_snake_case:   str  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   List[str]  					=		model(__snake_case       )

																_snake_case:   List[str]  					=		[input_ids, input_mask]
																_snake_case:   Dict  					=		model(__snake_case       )

																_snake_case:   List[str]  					=		model(__snake_case       )

																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    SCREAMING_SNAKE_CASE_		(					self	:  str       ,     __snake_case	:  int       ,     __snake_case	:  str       ,     __snake_case	:  List[str]       ,     __snake_case	:  Dict       ,     __snake_case	:  str       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[str]       ):





																'''simple docstring'''





																_snake_case:   str  					=		TFMobileBertForMaskedLM(config=__snake_case       )
																_snake_case:   Optional[Any]  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   Optional[int]  					=		model(__snake_case       )
																self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size)       )


										def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     __snake_case	:  int       ,     __snake_case	:  List[str]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  int       ,     __snake_case	:  str       ):





																'''simple docstring'''





																_snake_case:   Union[str, Any]  					=		TFMobileBertForNextSentencePrediction(config=__snake_case       )
																_snake_case:   List[str]  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   List[str]  					=		model(__snake_case       )
																self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, 2)       )


										def    SCREAMING_SNAKE_CASE_		(					self	:  int       ,     __snake_case	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  Dict       ,     __snake_case	:  List[str]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  List[Any]       ):





																'''simple docstring'''





																_snake_case:   str  					=		TFMobileBertForPreTraining(config=__snake_case       )
																_snake_case:   str  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   List[str]  					=		model(__snake_case       )
																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    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ,     __snake_case	:  int       ,     __snake_case	:  Any       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Optional[int]       ):





																'''simple docstring'''





																_snake_case:   int  					=		self.num_labels
																_snake_case:   Tuple  					=		TFMobileBertForSequenceClassification(config=__snake_case       )
																_snake_case:   Optional[Any]  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   List[Any]  					=		model(__snake_case       )
																self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)       )


										def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Any       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  List[str]       ):





																'''simple docstring'''





																_snake_case:   Tuple  					=		self.num_choices
																_snake_case:   Optional[int]  					=		TFMobileBertForMultipleChoice(config=__snake_case       )
																_snake_case:   str  					=		tf.tile(tf.expand_dims(__snake_case       ,     1       )       ,     (1, self.num_choices, 1)       )
																_snake_case:   Union[str, Any]  					=		tf.tile(tf.expand_dims(__snake_case       ,     1       )       ,     (1, self.num_choices, 1)       )
																_snake_case:   Optional[int]  					=		tf.tile(tf.expand_dims(__snake_case       ,     1       )       ,     (1, self.num_choices, 1)       )
																_snake_case:   Optional[Any]  					=		{
																    'input_ids': multiple_choice_inputs_ids,
																    'attention_mask': multiple_choice_input_mask,
																    'token_type_ids': multiple_choice_token_type_ids,
																}
																_snake_case:   Optional[Any]  					=		model(__snake_case       )
																self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_choices)       )


										def    SCREAMING_SNAKE_CASE_		(					self	:  int       ,     __snake_case	:  str       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Any       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Optional[Any]       ):





																'''simple docstring'''





																_snake_case:   Tuple  					=		self.num_labels
																_snake_case:   Dict  					=		TFMobileBertForTokenClassification(config=__snake_case       )
																_snake_case:   str  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   Tuple  					=		model(__snake_case       )
																self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels)       )


										def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ,     __snake_case	:  Any       ,     __snake_case	:  Tuple       ,     __snake_case	:  Dict       ,     __snake_case	:  int       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ,     __snake_case	:  Any       ):





																'''simple docstring'''





																_snake_case:   int  					=		TFMobileBertForQuestionAnswering(config=__snake_case       )
																_snake_case:   Any  					=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
																_snake_case:   Union[str, Any]  					=		model(__snake_case       )
																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    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





																'''simple docstring'''





																_snake_case:   str  					=		self.prepare_config_and_inputs()
																(
																    (
																    _snake_case
																)					,						(
																    _snake_case
																)					,						(
																    _snake_case
																)					,						(
																    _snake_case
																)					,						(
																    _snake_case
																)					,						(
																    _snake_case
																)					,						(
																    _snake_case
																)					,						
																):   Any  					=		config_and_inputs
																_snake_case:   str  					=		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
																return config, inputs_dict





					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   int  					=		TFMobileBertModelTest.TFMobileBertModelTester(self       )
											_snake_case:   Dict  					=		ConfigTester(self       ,     config_class=__snake_case       ,     hidden_size=37       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											self.config_tester.run_common_tests()


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_model(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_masked_lm(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   List[Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_pretraining(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_question_answering(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mobilebert_for_token_classification(*__snake_case       )




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											for model_name in ["google/mobilebert-uncased"]:
																	_snake_case:   Optional[Any]  					=		TFMobileBertModel.from_pretrained(__snake_case       )
																	self.assertIsNotNone(__snake_case       )







@require_tf
class 			lowerCamelCase					(						unittest.TestCase  ):


					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		TFMobileBertForPreTraining.from_pretrained('google/mobilebert-uncased'       )
											_snake_case:   Any  					=		tf.constant([[0, 1, 2, 3, 4, 5]]       )
											_snake_case:   Optional[Any]  					=		model(__snake_case       )[0]

											_snake_case:   str  					=		[1, 6, 3_05_22]
											self.assertEqual(output.shape       ,     __snake_case       )

											_snake_case:   int  					=		tf.constant(
											    [
											        [
											            [-4.5_919_547, -9.248_295, -9.645_256],
											            [-6.7_306_175, -6.440_284, -6.6_052_837],
											            [-7.2_743_506, -6.7_847_915, -6.024_673],
											        ]
											    ]       )
											tf.debugging.assert_near(output[:, :3, :3]       ,     __snake_case       ,     atol=1e-4       )





