



"""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		):





		"""simple docstring"""






		def    UpperCAmelCase__							(					self							,    _lowercase   ) ->						Any:







								'''simple docstring'''

								for model_result in results.values():
														for batch_size, sequence_length in zip(model_result["""bs"""]							,    model_result["""ss"""]   ):
																				snake_case_   : List[str]						=			model_result["""result"""][batch_size][sequence_length]
																				self.assertIsNotNone(_lowercase   )





		def    UpperCAmelCase__							(					self   ) ->						List[str]:







								'''simple docstring'''

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





		def    UpperCAmelCase__							(					self   ) ->						Any:







								'''simple docstring'''

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





		def    UpperCAmelCase__							(					self   ) ->						List[Any]:







								'''simple docstring'''

								snake_case_   : Optional[Any]						=			"""sshleifer/tiny-gpt2"""
								snake_case_   : Tuple						=			TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]							,    training=_lowercase							,    inference=_lowercase							,    sequence_lengths=[8]							,    batch_sizes=[1]							,    multi_process=_lowercase							,    )
								snake_case_   : int						=			TensorFlowBenchmark(_lowercase   )
								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    UpperCAmelCase__							(					self   ) ->						Any:







								'''simple docstring'''

								snake_case_   : Union[str, Any]						=			"""sshleifer/tiny-gpt2"""
								snake_case_   : str						=			AutoConfig.from_pretrained(_lowercase   )
								snake_case_   : List[Any]						=			TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]							,    training=_lowercase							,    inference=_lowercase							,    sequence_lengths=[8]							,    batch_sizes=[1]							,    eager_mode=_lowercase							,    multi_process=_lowercase							,    )
								snake_case_   : List[Any]						=			TensorFlowBenchmark(_lowercase							,    [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    UpperCAmelCase__							(					self   ) ->						str:







								'''simple docstring'''

								snake_case_   : Optional[Any]						=			"""sshleifer/tiny-gpt2"""
								snake_case_   : Optional[int]						=			AutoConfig.from_pretrained(_lowercase   )
								snake_case_   : Optional[int]						=			TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]							,    training=_lowercase							,    inference=_lowercase							,    sequence_lengths=[8]							,    batch_sizes=[1]							,    multi_process=_lowercase							,    )
								snake_case_   : List[str]						=			TensorFlowBenchmark(_lowercase							,    [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    UpperCAmelCase__							(					self   ) ->						Tuple:







								'''simple docstring'''

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





		def    UpperCAmelCase__							(					self   ) ->						str:







								'''simple docstring'''

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





		def    UpperCAmelCase__							(					self   ) ->						Optional[int]:







								'''simple docstring'''

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







								'''simple docstring'''

								snake_case_   : Dict						=			"""sshleifer/tiny-gpt2"""
								snake_case_   : List[str]						=			TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]							,    training=_lowercase							,    inference=_lowercase							,    sequence_lengths=[8]							,    batch_sizes=[1]							,    use_xla=_lowercase							,    multi_process=_lowercase							,    )
								snake_case_   : int						=			TensorFlowBenchmark(_lowercase   )
								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    UpperCAmelCase__							(					self   ) ->						Dict:







								'''simple docstring'''

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





		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								snake_case_   : Dict						=			"""sshleifer/tiny-gpt2"""

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

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






"""simple docstring"""





from .data_collator import (
    DataCollatorForLanguageModeling,
    DataCollatorForPermutationLanguageModeling,
    DataCollatorForSeqaSeq,
    DataCollatorForSOP,
    DataCollatorForTokenClassification,
    DataCollatorForWholeWordMask,
    DataCollatorWithPadding,
    DefaultDataCollator,
    default_data_collator,
)
from .metrics import glue_compute_metrics, xnli_compute_metrics
from .processors import (
    DataProcessor,
    InputExample,
    InputFeatures,
    SingleSentenceClassificationProcessor,
    SquadExample,
    SquadFeatures,
    SquadVaProcessor,
    SquadVaProcessor,
    glue_convert_examples_to_features,
    glue_output_modes,
    glue_processors,
    glue_tasks_num_labels,
    squad_convert_examples_to_features,
    xnli_output_modes,
    xnli_processors,
    xnli_tasks_num_labels,
)

