


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

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				Optional[Any]			,			UpperCAmelCase__			:				str   )       ->	str:
						for model_result in results.values():
											for batch_size, sequence_length in zip(model_result["bs"]			,			model_result["ss"]   ):
																__SCREAMING_SNAKE_CASE						   =				model_result["result"][batch_size][sequence_length]
																self.assertIsNotNone(UpperCAmelCase__   )




	def   UpperCAmelCase_      ( self			:				List[str]   )       ->	Tuple:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			eager_mode=UpperCAmelCase__			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				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   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"sgugger/tiny-distilbert-classification"
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			multi_process=UpperCAmelCase__			,			only_pretrain_model=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				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   )       ->	Union[str, Any]:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				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			:				int   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				AutoConfig.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			eager_mode=UpperCAmelCase__			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__			,			[config]   )
						__SCREAMING_SNAKE_CASE						   =				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]   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				AutoConfig.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__			,			[config]   )
						__SCREAMING_SNAKE_CASE						   =				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[str]   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				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			:				List[Any]   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				AutoConfig.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__			,			[config]   )
						__SCREAMING_SNAKE_CASE						   =				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			:				Dict   )       ->	Union[str, Any]:
						__SCREAMING_SNAKE_CASE						   =				"patrickvonplaten/t5-tiny-random"
						__SCREAMING_SNAKE_CASE						   =				AutoConfig.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__			,			configs=[config]   )
						__SCREAMING_SNAKE_CASE						   =				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   )       ->	Optional[int]:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmarkArguments(
						    models=[MODEL_ID]			,			training=UpperCAmelCase__			,			inference=UpperCAmelCase__			,			sequence_lengths=[8]			,			batch_sizes=[1]			,			use_xla=UpperCAmelCase__			,			multi_process=UpperCAmelCase__			,			)
						__SCREAMING_SNAKE_CASE						   =				TensorFlowBenchmark(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				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   )       ->	Tuple:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"
						with tempfile.TemporaryDirectory() as tmp_dir:
											__SCREAMING_SNAKE_CASE						   =				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__			,			)
											__SCREAMING_SNAKE_CASE						   =				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   UpperCAmelCase_      ( self			:				List[Any]   )       ->	Dict:
						__SCREAMING_SNAKE_CASE						   =				"sshleifer/tiny-gpt2"

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




UpperCAmelCase__   	=							8.31_44_62  # Unit - J mol-1 K-1
def 				UpperCAmelCase_					(							__snake_case     ,						__snake_case     ,						__snake_case						)     ->			float:







 """simple docstring"""


 if moles < 0 or kelvin < 0 or volume < 0:
  raise ValueError('''Invalid inputs. Enter positive value.'''						)
 return moles * kelvin * UNIVERSAL_GAS_CONSTANT / volume
def 				UpperCAmelCase_					(							__snake_case     ,						__snake_case     ,						__snake_case						)     ->			float:







 """simple docstring"""


 if moles < 0 or kelvin < 0 or pressure < 0:
  raise ValueError('''Invalid inputs. Enter positive value.'''						)
 return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure


if __name__ == "__main__":
  from doctest import testmod

  testmod()

