


'''simple docstring'''


import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
						from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments






@require_torch
class 	lowerCAmelCase__			(			unittest.TestCase	):




			def 							lowerCAmelCase__    (		self  :     int	,  lowerCamelCase__  :     Tuple )   ->Dict:



					'''simple docstring'''







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




			def 							lowerCAmelCase__    (		self  :     Dict )   ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Optional[Any]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       Union[str, Any]								=      PyTorchBenchmark(lowerCamelCase__ )
					_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 							lowerCAmelCase__    (		self  :     Dict )   ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       List[str]								=      "sgugger/tiny-distilbert-classification"
					_UpperCAmelCase		:       Dict								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  only_pretrain_model=lowerCamelCase__	,  )
					_UpperCAmelCase		:       str								=      PyTorchBenchmark(lowerCamelCase__ )
					_UpperCAmelCase		:       Dict								=      benchmark.run()
					self.check_results_dict_not_empty(results.time_inference_result )
					self.check_results_dict_not_empty(results.memory_inference_result )




			def 							lowerCAmelCase__    (		self  :     Optional[Any] )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       Dict								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Optional[Any]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  torchscript=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       Optional[Any]								=      PyTorchBenchmark(lowerCamelCase__ )
					_UpperCAmelCase		:       str								=      benchmark.run()
					self.check_results_dict_not_empty(results.time_inference_result )
					self.check_results_dict_not_empty(results.memory_inference_result )




			@unittest.skipIf(torch_device == "cpu"	,  "Cant do half precision" )
			def 							lowerCAmelCase__    (		self  :     Tuple )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       str								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Dict								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  fpaa=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       Optional[int]								=      PyTorchBenchmark(lowerCamelCase__ )
					_UpperCAmelCase		:       Any								=      benchmark.run()
					self.check_results_dict_not_empty(results.time_inference_result )
					self.check_results_dict_not_empty(results.memory_inference_result )




			def 							lowerCAmelCase__    (		self  :     List[str] )   ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       str								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Union[str, Any]								=      AutoConfig.from_pretrained(lowerCamelCase__ )
					# set architectures equal to `None`
					_UpperCAmelCase		:       List[Any]								=      None
					_UpperCAmelCase		:       Union[str, Any]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       str								=      PyTorchBenchmark(lowerCamelCase__	,  configs=[config] )
					_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 							lowerCAmelCase__    (		self  :     str )   ->Tuple:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       str								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       List[str]								=      PyTorchBenchmark(lowerCamelCase__ )
					_UpperCAmelCase		:       List[Any]								=      benchmark.run()
					self.check_results_dict_not_empty(results.time_train_result )
					self.check_results_dict_not_empty(results.memory_train_result )




			@unittest.skipIf(torch_device == "cpu"	,  "Can't do half precision" )
			def 							lowerCAmelCase__    (		self  :     str )   ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[int]								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Union[str, Any]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  fpaa=lowerCamelCase__	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       str								=      PyTorchBenchmark(lowerCamelCase__ )
					_UpperCAmelCase		:       Any								=      benchmark.run()
					self.check_results_dict_not_empty(results.time_train_result )
					self.check_results_dict_not_empty(results.memory_train_result )




			def 							lowerCAmelCase__    (		self  :     str )   ->List[Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Any								=      AutoConfig.from_pretrained(lowerCamelCase__ )
					_UpperCAmelCase		:       List[Any]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       Tuple								=      PyTorchBenchmark(lowerCamelCase__	,  configs=[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 							lowerCAmelCase__    (		self  :     Optional[Any] )   ->Any:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      "sshleifer/tinier_bart"
					_UpperCAmelCase		:       List[str]								=      AutoConfig.from_pretrained(lowerCamelCase__ )
					_UpperCAmelCase		:       List[str]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       Optional[int]								=      PyTorchBenchmark(lowerCamelCase__	,  configs=[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 							lowerCAmelCase__    (		self  :     List[str] )   ->Tuple:



					'''simple docstring'''







					_UpperCAmelCase		:       Any								=      "sshleifer/tiny-gpt2"
					_UpperCAmelCase		:       Dict								=      AutoConfig.from_pretrained(lowerCamelCase__ )
					_UpperCAmelCase		:       Optional[Any]								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       Dict								=      PyTorchBenchmark(lowerCamelCase__	,  configs=[config] )
					_UpperCAmelCase		:       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 							lowerCAmelCase__    (		self  :     Optional[int] )   ->Dict:



					'''simple docstring'''







					_UpperCAmelCase		:       List[str]								=      "sshleifer/tinier_bart"
					_UpperCAmelCase		:       List[str]								=      AutoConfig.from_pretrained(lowerCamelCase__ )
					_UpperCAmelCase		:       Any								=      PyTorchBenchmarkArguments(
					    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  multi_process=lowerCamelCase__	,  )
					_UpperCAmelCase		:       List[Any]								=      PyTorchBenchmark(lowerCamelCase__	,  configs=[config] )
					_UpperCAmelCase		:       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 							lowerCAmelCase__    (		self  :     Dict )   ->Dict:



					'''simple docstring'''







					_UpperCAmelCase		:       List[str]								=      "sshleifer/tiny-gpt2"
					with tempfile.TemporaryDirectory() as tmp_dir:
							_UpperCAmelCase		:       Optional[int]								=      PyTorchBenchmarkArguments(
							    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  save_to_csv=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  inference_time_csv_file=os.path.join(lowerCamelCase__	,  "inf_time.csv" )	,  train_memory_csv_file=os.path.join(lowerCamelCase__	,  "train_mem.csv" )	,  inference_memory_csv_file=os.path.join(lowerCamelCase__	,  "inf_mem.csv" )	,  train_time_csv_file=os.path.join(lowerCamelCase__	,  "train_time.csv" )	,  env_info_csv_file=os.path.join(lowerCamelCase__	,  "env.csv" )	,  multi_process=lowerCamelCase__	,  )
							_UpperCAmelCase		:       List[str]								=      PyTorchBenchmark(lowerCamelCase__ )
							benchmark.run()
							self.assertTrue(Path(os.path.join(lowerCamelCase__	,  "inf_time.csv" ) ).exists() )
							self.assertTrue(Path(os.path.join(lowerCamelCase__	,  "train_time.csv" ) ).exists() )
							self.assertTrue(Path(os.path.join(lowerCamelCase__	,  "inf_mem.csv" ) ).exists() )
							self.assertTrue(Path(os.path.join(lowerCamelCase__	,  "train_mem.csv" ) ).exists() )
							self.assertTrue(Path(os.path.join(lowerCamelCase__	,  "env.csv" ) ).exists() )






			def 							lowerCAmelCase__    (		self  :     str )   ->Tuple:



					'''simple docstring'''







					_UpperCAmelCase		:       Tuple								=      "sshleifer/tiny-gpt2"

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

					with tempfile.TemporaryDirectory() as tmp_dir:
							_UpperCAmelCase		:       Optional[Any]								=      PyTorchBenchmarkArguments(
							    models=[MODEL_ID]	,  training=lowerCamelCase__	,  inference=lowerCamelCase__	,  sequence_lengths=[8]	,  batch_sizes=[1]	,  log_filename=os.path.join(lowerCamelCase__	,  "log.txt" )	,  log_print=lowerCamelCase__	,  trace_memory_line_by_line=lowerCamelCase__	,  multi_process=lowerCamelCase__	,  )
							_UpperCAmelCase		:       Optional[int]								=      PyTorchBenchmark(lowerCamelCase__ )
							_UpperCAmelCase		:       Union[str, Any]								=      benchmark.run()
							_check_summary_is_not_empty(result.inference_summary )
							_check_summary_is_not_empty(result.train_summary )
							self.assertTrue(Path(os.path.join(lowerCamelCase__	,  "log.txt" ) ).exists() )







'''simple docstring'''


def  __lowerCAmelCase ():
		_UpperCAmelCase		:       str								=      0
		for i in range(1      , 1_001   ):
				total += i**i
		return str(__lowerCAmelCase   )[-10:]


if __name__ == "__main__":
						print(solution())



