





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





     def 							lowercase__      ( self		:					int	,      lowercase		:					List[Any]						):





        """simple docstring"""




        for model_result in results.values():
           for batch_size, sequence_length in zip(model_result["bs"]	,      model_result["ss"]						):
              lowercase_			:Any    			= model_result["result"][batch_size][sequence_length]
              self.assertIsNotNone(lowercase						)





     def 							lowercase__      ( self		:					int						):





        """simple docstring"""




        lowercase_			:List[Any]    			= "sshleifer/tiny-gpt2"
        lowercase_			:List[Any]    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      eager_mode=lowercase	,      multi_process=lowercase	,      )
        lowercase_			:Tuple    			= TensorFlowBenchmark(lowercase						)
        lowercase_			:int    			= 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[str]						):





        """simple docstring"""




        lowercase_			:str    			= "sgugger/tiny-distilbert-classification"
        lowercase_			:List[str]    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      multi_process=lowercase	,      only_pretrain_model=lowercase	,      )
        lowercase_			:int    			= TensorFlowBenchmark(lowercase						)
        lowercase_			:str    			= 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]						):





        """simple docstring"""




        lowercase_			:Dict    			= "sshleifer/tiny-gpt2"
        lowercase_			:str    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      multi_process=lowercase	,      )
        lowercase_			:Tuple    			= TensorFlowBenchmark(lowercase						)
        lowercase_			:Dict    			= 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]						):





        """simple docstring"""




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





        """simple docstring"""




        lowercase_			:Any    			= "sshleifer/tiny-gpt2"
        lowercase_			:Tuple    			= AutoConfig.from_pretrained(lowercase						)
        lowercase_			:Any    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      multi_process=lowercase	,      )
        lowercase_			:Tuple    			= TensorFlowBenchmark(lowercase	,      [config]						)
        lowercase_			:Optional[Any]    			= 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]						):





        """simple docstring"""




        lowercase_			:Union[str, Any]    			= "sshleifer/tiny-gpt2"
        lowercase_			:List[str]    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      multi_process=lowercase	,      )
        lowercase_			:Union[str, Any]    			= TensorFlowBenchmark(lowercase						)
        lowercase_			:Optional[int]    			= 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		:					List[Any]						):





        """simple docstring"""




        lowercase_			:Tuple    			= "sshleifer/tiny-gpt2"
        lowercase_			:Dict    			= AutoConfig.from_pretrained(lowercase						)
        lowercase_			:Any    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      multi_process=lowercase	,      )
        lowercase_			:int    			= TensorFlowBenchmark(lowercase	,      [config]						)
        lowercase_			: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 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        lowercase_			:int    			= "patrickvonplaten/t5-tiny-random"
        lowercase_			:List[Any]    			= AutoConfig.from_pretrained(lowercase						)
        lowercase_			:int    			= TensorFlowBenchmarkArguments(
            models=[MODEL_ID]	,      training=lowercase	,      inference=lowercase	,      sequence_lengths=[8]	,      batch_sizes=[1]	,      multi_process=lowercase	,      )
        lowercase_			:Tuple    			= TensorFlowBenchmark(lowercase	,      configs=[config]						)
        lowercase_			:Tuple    			= 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		:					Union[str, Any]						):





        """simple docstring"""




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





        """simple docstring"""




        lowercase_			:str    			= "sshleifer/tiny-gpt2"
        with tempfile.TemporaryDirectory() as tmp_dir:
           lowercase_			:Any    			= 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	,      )
           lowercase_			:str    			= 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 							lowercase__      ( self		:					Dict						):





        """simple docstring"""




        lowercase_			:List[Any]    			= "sshleifer/tiny-gpt2"

        def _check_summary_is_not_empty(lowercase		:					str						):
           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:
           lowercase_			:Optional[int]    			= 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	,      )
           lowercase_			:int    			= TensorFlowBenchmark(lowercase						)
           lowercase_			:Optional[int]    			= benchmark.run()
           _check_summary_is_not_empty(result.inference_summary						)
           self.assertTrue(Path(os.path.join(lowercase	,      "log.txt"						)						).exists()						)









'''simple docstring'''


import pytest

from datasets import inspect_metric, list_metrics, load_metric
@pytest.fixture
def 							UpperCAmelCase_  (						__lowerCamelCase					:					List[str] ):
   monkeypatch.setattr("datasets.utils.deprecation_utils._emitted_deprecation_warnings"	,set() )
@pytest.fixture
def 							UpperCAmelCase_  (						__lowerCamelCase					:					Any ):
   class       a_   :





        def __init__( self		:					int	,      lowercase		:					int						):





           """simple docstring"""




           lowercase_			:Optional[Any]    			= metric_id







   class       a_   :
        __A      =			[MetricMock(_lowerCAmelCase							) for metric_id in ["accuracy", "mse", "precision", "codeparrot/apps_metric"]]





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





           """simple docstring"""




           return self._metrics







   monkeypatch.setattr("datasets.inspect.huggingface_hub"	,HfhMock() )


@pytest.mark.parametrize(
    "func, args"	,[(load_metric, ("metrics/mse",)), (list_metrics, ()), (inspect_metric, ("metrics/mse", "tmp_path"))] )
def 							UpperCAmelCase_  (						__lowerCamelCase					:					Union[str, Any]	,__lowerCamelCase					:					int	,__lowerCamelCase					:					Optional[int]	,__lowerCamelCase					:					Union[str, Any]	,__lowerCamelCase					:					Tuple ):
   if "tmp_path" in args:
      lowercase_			:Union[str, Any]    			= tuple(arg if arg != "tmp_path" else tmp_path for arg in args )
   with pytest.warns(__lowerCamelCase	,match="https://huggingface.co/docs/evaluate" ):
      func(*__lowerCamelCase )


