
from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, 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 import (
						    TFConvBertForMaskedLM,
						    TFConvBertForMultipleChoice,
						    TFConvBertForQuestionAnswering,
						    TFConvBertForSequenceClassification,
						    TFConvBertForTokenClassification,
						    TFConvBertModel,
						)
class  lowercase__:



	"""simple docstring"""




	def __init__(       self  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=1_3       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=7       ,							SCREAMING_SNAKE_CASE_  :			int=True       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=True       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=True       ,							SCREAMING_SNAKE_CASE_  :			Dict=True       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=9_9       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=3_2       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=2       ,							SCREAMING_SNAKE_CASE_  :			Tuple=4       ,							SCREAMING_SNAKE_CASE_  :			Any=3_7       ,							SCREAMING_SNAKE_CASE_  :			str="gelu"       ,							SCREAMING_SNAKE_CASE_  :			Dict=0.1       ,							SCREAMING_SNAKE_CASE_  :			int=0.1       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=5_1_2       ,							SCREAMING_SNAKE_CASE_  :			str=1_6       ,							SCREAMING_SNAKE_CASE_  :			str=2       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=0.02       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=3       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=4       ,							SCREAMING_SNAKE_CASE_  :			Dict=None       ,							)       ->     List[Any]:
					lowercase_       =					parent
					lowercase_       =					1_3
					lowercase_       =					7
					lowercase_       =					True
					lowercase_       =					True
					lowercase_       =					True
					lowercase_       =					True
					lowercase_       =					9_9
					lowercase_       =					3_8_4
					lowercase_       =					2
					lowercase_       =					4
					lowercase_       =					3_7
					lowercase_       =					'''gelu'''
					lowercase_       =					0.1
					lowercase_       =					0.1
					lowercase_       =					5_1_2
					lowercase_       =					1_6
					lowercase_       =					2
					lowercase_       =					0.02
					lowercase_       =					3
					lowercase_       =					4
					lowercase_       =					1_2_8
					lowercase_       =					2
					lowercase_       =					9
					lowercase_       =					1
					lowercase_       =					None
	def 						_lowercase  (       self  :			List[Any]       )       ->     Union[str, Any]:
					lowercase_       =					ids_tensor([self.batch_size, self.seq_length]       ,							self.vocab_size       )

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

					lowercase_       =					None
					if self.use_token_type_ids:
									lowercase_       =					ids_tensor([self.batch_size, self.seq_length]       ,							self.type_vocab_size       )

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

					lowercase_       =					ConvBertConfig(
					    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       ,							return_dict=UpperCamelCase__       ,							)

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
	def 						_lowercase  (       self  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			str       )       ->     Optional[Any]:
					lowercase_       =					TFConvBertModel(config=UpperCamelCase__       )
					lowercase_       =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

					lowercase_       =					[input_ids, input_mask]
					lowercase_       =					model(UpperCamelCase__       )

					lowercase_       =					model(UpperCamelCase__       )

					self.parent.assertEqual(result.last_hidden_state.shape       ,							(self.batch_size, self.seq_length, self.hidden_size)       )
	def 						_lowercase  (       self  :			int       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       )       ->     Dict:
					lowercase_       =					TFConvBertForMaskedLM(config=UpperCamelCase__       )
					lowercase_       =					{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowercase_       =					model(UpperCamelCase__       )
					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)       )
	def 						_lowercase  (       self  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			List[str]       )       ->     Union[str, Any]:
					lowercase_       =					self.num_labels
					lowercase_       =					TFConvBertForSequenceClassification(config=UpperCamelCase__       )
					lowercase_       =					{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowercase_       =					model(UpperCamelCase__       )
					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_labels)       )
	def 						_lowercase  (       self  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			int       )       ->     str:
					lowercase_       =					self.num_choices
					lowercase_       =					TFConvBertForMultipleChoice(config=UpperCamelCase__       )
					lowercase_       =					tf.tile(tf.expand_dims(UpperCamelCase__       ,							1       )       ,							(1, self.num_choices, 1)       )
					lowercase_       =					tf.tile(tf.expand_dims(UpperCamelCase__       ,							1       )       ,							(1, self.num_choices, 1)       )
					lowercase_       =					tf.tile(tf.expand_dims(UpperCamelCase__       ,							1       )       ,							(1, self.num_choices, 1)       )
					lowercase_       =					{
					    '''input_ids''': multiple_choice_inputs_ids,
					    '''attention_mask''': multiple_choice_input_mask,
					    '''token_type_ids''': multiple_choice_token_type_ids,
					}
					lowercase_       =					model(UpperCamelCase__       )
					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_choices)       )
	def 						_lowercase  (       self  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			str       )       ->     Optional[int]:
					lowercase_       =					self.num_labels
					lowercase_       =					TFConvBertForTokenClassification(config=UpperCamelCase__       )
					lowercase_       =					{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowercase_       =					model(UpperCamelCase__       )
					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.num_labels)       )
	def 						_lowercase  (       self  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       )       ->     Optional[Any]:
					lowercase_       =					TFConvBertForQuestionAnswering(config=UpperCamelCase__       )
					lowercase_       =					{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowercase_       =					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 						_lowercase  (       self  :			List[str]       )       ->     Optional[int]:
					lowercase_       =					self.prepare_config_and_inputs()
					(
					    (
					    lowercase_    
					)  ,	(
					    lowercase_    
					)  ,	(
					    lowercase_    
					)  ,	(
					    lowercase_    
					)  ,	(
					    lowercase_    
					)  ,	(
					    lowercase_    
					)  ,	(
					    lowercase_    
					)  ,	    
					)       =					config_and_inputs
					lowercase_       =					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
					return config, inputs_dict

@require_tf
class  lowercase__(				_A ,						_A ,						unittest.TestCase							):



	"""simple docstring"""




	a			:Any         =	(
	    (
	        TFConvBertModel,
	        TFConvBertForMaskedLM,
	        TFConvBertForQuestionAnswering,
	        TFConvBertForSequenceClassification,
	        TFConvBertForTokenClassification,
	        TFConvBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	a			:Dict         =	(
	    {
	        'feature-extraction': TFConvBertModel,
	        'fill-mask': TFConvBertForMaskedLM,
	        'question-answering': TFConvBertForQuestionAnswering,
	        'text-classification': TFConvBertForSequenceClassification,
	        'token-classification': TFConvBertForTokenClassification,
	        'zero-shot': TFConvBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	a			:Optional[int]         =	False
	a			:Union[str, Any]         =	False
	a			:str         =	False
	def 						_lowercase  (       self  :			List[str]       )       ->     Any:
					lowercase_       =					TFConvBertModelTester(self       )
					lowercase_       =					ConfigTester(self       ,							config_class=UpperCamelCase__       ,							hidden_size=3_7       )
	def 						_lowercase  (       self  :			str       )       ->     int:
					self.config_tester.run_common_tests()
	def 						_lowercase  (       self  :			int       )       ->     str:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*UpperCamelCase__       )
	def 						_lowercase  (       self  :			Dict       )       ->     List[str]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     List[Any]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__       )
	def 						_lowercase  (       self  :			int       )       ->     Optional[int]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__       )
	def 						_lowercase  (       self  :			Any       )       ->     Optional[Any]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__       )
	def 						_lowercase  (       self  :			Optional[Any]       )       ->     int:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__       )
	@slow
	def 						_lowercase  (       self  :			Tuple       )       ->     Optional[int]:
					lowercase_  ,	lowercase_       =					self.model_tester.prepare_config_and_inputs_for_common()
					lowercase_       =					True
					lowercase_       =					True

					if hasattr(UpperCamelCase__       ,							'''use_cache'''       ):
									lowercase_       =					True

					lowercase_       =					getattr(self.model_tester       ,							'''encoder_seq_length'''       ,							self.model_tester.seq_length       )
					lowercase_       =					getattr(self.model_tester       ,							'''key_length'''       ,							UpperCamelCase__       )

					for model_class in self.all_model_classes:
									lowercase_       =					self._prepare_for_class(UpperCamelCase__       ,							UpperCamelCase__       )
									lowercase_       =					model_class(UpperCamelCase__       )
									lowercase_       =					len(model(UpperCamelCase__       )       )

									with tempfile.TemporaryDirectory() as tmpdirname:
													model.save_pretrained(UpperCamelCase__       ,							saved_model=UpperCamelCase__       )
													lowercase_       =					os.path.join(UpperCamelCase__       ,							'''saved_model'''       ,							'''1'''       )
													lowercase_       =					tf.keras.models.load_model(UpperCamelCase__       )
													lowercase_       =					model(UpperCamelCase__       )

													if self.is_encoder_decoder:
																	lowercase_       =					outputs['''encoder_hidden_states''']
																	lowercase_       =					outputs['''encoder_attentions''']
													else:
																	lowercase_       =					outputs['''hidden_states''']
																	lowercase_       =					outputs['''attentions''']

													self.assertEqual(len(UpperCamelCase__       )       ,							UpperCamelCase__       )

													lowercase_       =					getattr(
													    self.model_tester       ,							'''expected_num_hidden_layers'''       ,							self.model_tester.num_hidden_layers + 1       )

													self.assertEqual(len(UpperCamelCase__       )       ,							UpperCamelCase__       )
													self.assertListEqual(
													    list(output_hidden_states[0].shape[-2:]       )       ,							[self.model_tester.seq_length, self.model_tester.hidden_size]       ,							)

													self.assertEqual(len(UpperCamelCase__       )       ,							self.model_tester.num_hidden_layers       )
													self.assertListEqual(
													    list(output_attentions[0].shape[-3:]       )       ,							[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,							)
	@slow
	def 						_lowercase  (       self  :			Dict       )       ->     Tuple:
					lowercase_       =					TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''       )
					self.assertIsNotNone(UpperCamelCase__       )




	def 						_lowercase  (       self  :			Optional[int]       )       ->     List[Any]:
					lowercase_  ,	lowercase_       =					self.model_tester.prepare_config_and_inputs_for_common()
					lowercase_       =					True
					lowercase_       =					getattr(self.model_tester       ,							'''decoder_seq_length'''       ,							self.model_tester.seq_length       )
					lowercase_       =					getattr(self.model_tester       ,							'''encoder_seq_length'''       ,							self.model_tester.seq_length       )
					lowercase_       =					getattr(self.model_tester       ,							'''key_length'''       ,							UpperCamelCase__       )
					lowercase_       =					getattr(self.model_tester       ,							'''key_length'''       ,							UpperCamelCase__       )

					def check_decoder_attentions_output(SCREAMING_SNAKE_CASE_  :			List[str]       ):
									lowercase_       =					len(UpperCamelCase__       )
									self.assertEqual(out_len % 2       ,							0       )
									lowercase_       =					outputs.decoder_attentions
									self.assertEqual(len(UpperCamelCase__       )       ,							self.model_tester.num_hidden_layers       )
									self.assertListEqual(
									    list(decoder_attentions[0].shape[-3:]       )       ,							[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]       ,							)

					def check_encoder_attentions_output(SCREAMING_SNAKE_CASE_  :			Optional[Any]       ):
									lowercase_       =					[
									    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
									]
									self.assertEqual(len(UpperCamelCase__       )       ,							self.model_tester.num_hidden_layers       )
									self.assertListEqual(
									    list(attentions[0].shape[-3:]       )       ,							[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,							)

					for model_class in self.all_model_classes:
									lowercase_       =					True
									lowercase_       =					False
									lowercase_       =					model_class(UpperCamelCase__       )
									lowercase_       =					model(self._prepare_for_class(UpperCamelCase__       ,							UpperCamelCase__       )       )
									lowercase_       =					len(UpperCamelCase__       )
									self.assertEqual(config.output_hidden_states       ,							UpperCamelCase__       )
									check_encoder_attentions_output(UpperCamelCase__       )

									if self.is_encoder_decoder:
													lowercase_       =					model_class(UpperCamelCase__       )
													lowercase_       =					model(self._prepare_for_class(UpperCamelCase__       ,							UpperCamelCase__       )       )
													self.assertEqual(config.output_hidden_states       ,							UpperCamelCase__       )
													check_decoder_attentions_output(UpperCamelCase__       )

									# Check that output attentions can also be changed via the config
									del inputs_dict["output_attentions"]
									lowercase_       =					True
									lowercase_       =					model_class(UpperCamelCase__       )
									lowercase_       =					model(self._prepare_for_class(UpperCamelCase__       ,							UpperCamelCase__       )       )
									self.assertEqual(config.output_hidden_states       ,							UpperCamelCase__       )
									check_encoder_attentions_output(UpperCamelCase__       )

									# Check attention is always last and order is fine
									lowercase_       =					True
									lowercase_       =					True
									lowercase_       =					model_class(UpperCamelCase__       )
									lowercase_       =					model(self._prepare_for_class(UpperCamelCase__       ,							UpperCamelCase__       )       )

									self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)       ,							len(UpperCamelCase__       )       )
									self.assertEqual(model.config.output_hidden_states       ,							UpperCamelCase__       )
									check_encoder_attentions_output(UpperCamelCase__       )

@require_tf
class  lowercase__(				unittest.TestCase							):



	"""simple docstring"""




	@slow
	def 						_lowercase  (       self  :			int       )       ->     List[str]:
					lowercase_       =					TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''       )
					lowercase_       =					tf.constant([[0, 1, 2, 3, 4, 5]]       )
					lowercase_       =					model(UpperCamelCase__       )[0]

					lowercase_       =					[1, 6, 7_6_8]
					self.assertEqual(output.shape       ,							UpperCamelCase__       )

					lowercase_       =					tf.constant(
					    [
					        [
					            [-0.03_47_54_93, -0.4_68_60_34, -0.30_63_88_32],
					            [0.22_63_72_48, -0.26_98_86_46, -0.7_42_34_24],
					            [0.10_32_48_68, -0.45_01_35_08, -0.58_28_07_84],
					        ]
					    ]       )
					tf.debugging.assert_near(output[:, :3, :3]       ,							UpperCamelCase__       ,							atol=1e-4       )






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        UpperCAmelCase_			( unittest.TestCase     ):


  '''simple docstring'''







  def 							_lowercase							( self			: List[str]			,							UpperCamelCase__			: int    )			->	str:







    """simple docstring"""






    for model_result in results.values():
      for batch_size, sequence_length in zip(model_result["""bs"""]			,							model_result["""ss"""]    ):
        __magic_name__				     =       model_result["""result"""][batch_size][sequence_length]
        self.assertIsNotNone(UpperCamelCase__    )
  def 							_lowercase							( self			: Union[str, Any]    )			->	Optional[int]:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							eager_mode=UpperCamelCase__			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_inference_result    )
    self.check_results_dict_not_empty(results.memory_inference_result    )
  def 							_lowercase							( self			: Optional[Any]    )			->	List[Any]:







    """simple docstring"""






    __magic_name__				     =       """sgugger/tiny-distilbert-classification"""
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							multi_process=UpperCamelCase__			,							only_pretrain_model=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_inference_result    )
    self.check_results_dict_not_empty(results.memory_inference_result    )
  def 							_lowercase							( self			: Any    )			->	List[Any]:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_inference_result    )
    self.check_results_dict_not_empty(results.memory_inference_result    )
  def 							_lowercase							( self			: Tuple    )			->	List[Any]:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       AutoConfig.from_pretrained(UpperCamelCase__    )
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							eager_mode=UpperCamelCase__			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__			,							[config]    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_inference_result    )
    self.check_results_dict_not_empty(results.memory_inference_result    )
  def 							_lowercase							( self			: Any    )			->	Union[str, Any]:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       AutoConfig.from_pretrained(UpperCamelCase__    )
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__			,							[config]    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_inference_result    )
    self.check_results_dict_not_empty(results.memory_inference_result    )
  def 							_lowercase							( self			: List[Any]    )			->	Dict:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_train_result    )
    self.check_results_dict_not_empty(results.memory_train_result    )
  def 							_lowercase							( self			: Optional[Any]    )			->	List[str]:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       AutoConfig.from_pretrained(UpperCamelCase__    )
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__			,							[config]    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_train_result    )
    self.check_results_dict_not_empty(results.memory_train_result    )
  def 							_lowercase							( self			: Union[str, Any]    )			->	Any:







    """simple docstring"""






    __magic_name__				     =       """patrickvonplaten/t5-tiny-random"""
    __magic_name__				     =       AutoConfig.from_pretrained(UpperCamelCase__    )
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__			,							configs=[config]    )
    __magic_name__				     =       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 							_lowercase							( self			: Tuple    )			->	int:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""
    __magic_name__				     =       TensorFlowBenchmarkArguments(
        models=[MODEL_ID]			,							training=UpperCamelCase__			,							inference=UpperCamelCase__			,							sequence_lengths=[8]			,							batch_sizes=[1]			,							use_xla=UpperCamelCase__			,							multi_process=UpperCamelCase__			,							)
    __magic_name__				     =       TensorFlowBenchmark(UpperCamelCase__    )
    __magic_name__				     =       benchmark.run()
    self.check_results_dict_not_empty(results.time_inference_result    )
    self.check_results_dict_not_empty(results.memory_inference_result    )
  def 							_lowercase							( self			: Union[str, Any]    )			->	Dict:







    """simple docstring"""






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





  def 							_lowercase							( self			: int    )			->	Optional[Any]:







    """simple docstring"""






    __magic_name__				     =       """sshleifer/tiny-gpt2"""

    def _check_summary_is_not_empty(UpperCamelCase__			: Dict    ):
      self.assertTrue(hasattr(UpperCamelCase__			,							"""sequential"""    )    )
      self.assertTrue(hasattr(UpperCamelCase__			,							"""cumulative"""    )    )
      self.assertTrue(hasattr(UpperCamelCase__			,							"""current"""    )    )
      self.assertTrue(hasattr(UpperCamelCase__			,							"""total"""    )    )

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

