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




  '''simple docstring'''







  def        UpperCamelCase__					(		self				,   lowercase_  ):

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







  def        UpperCamelCase__					(		self  ):

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

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

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

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

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

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

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

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

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

     """simple docstring"""
     UpperCAmelCase_					:					int			     =    "sshleifer/tiny-gpt2"
     with tempfile.TemporaryDirectory() as tmp_dir:
        UpperCAmelCase_					:					List[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_				,   )
        UpperCAmelCase_					:					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  ):

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




"""simple docstring"""





def 	__a     (		__lowerCamelCase,		__lowerCamelCase,		__lowerCamelCase  ):
   return round(float(moles / volume  ) * nfactor  )







def 	__a     (		__lowerCamelCase,		__lowerCamelCase,		__lowerCamelCase  ):
   return round(float((moles * 0.0821 * temperature) / (volume)  )  )







def 	__a     (		__lowerCamelCase,		__lowerCamelCase,		__lowerCamelCase  ):
   return round(float((moles * 0.0821 * temperature) / (pressure)  )  )







def 	__a     (		__lowerCamelCase,		__lowerCamelCase,		__lowerCamelCase  ):
   return round(float((pressure * volume) / (0.0821 * moles)  )  )


if __name__ == "__main__":
    import doctest

    doctest.testmod()


