



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



       def 		_lowerCamelCase      (		self							:					List[Any]					,		__SCREAMING_SNAKE_CASE							:					Tuple):


           '''simple docstring'''

           for model_result in results.values():
               for batch_size, sequence_length in zip(model_result['''bs''']					,		model_result['''ss''']):
                   __a							=    model_result['''result'''][batch_size][sequence_length]
                   self.assertIsNotNone(__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					int):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
           __a							=    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							:					Tuple):


           '''simple docstring'''

           __a							=    '''sgugger/tiny-distilbert-classification'''
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		only_pretrain_model=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
           __a							=    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[Any]):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		torchscript=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
           __a							=    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							:					List[str]):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		fpaa=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
           __a							=    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							:					int):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE)
           # set architectures equal to `None`
           __a							=    None
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE					,		configs=[config])
           __a							=    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]):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
           __a							=    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							:					List[str]):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		fpaa=__SCREAMING_SNAKE_CASE					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
           __a							=    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							:					List[Any]):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE)
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE					,		configs=[config])
           __a							=    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]):


           '''simple docstring'''

           __a							=    '''sshleifer/tinier_bart'''
           __a							=    AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE)
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE					,		configs=[config])
           __a							=    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							:					int):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''
           __a							=    AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE)
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE					,		configs=[config])
           __a							=    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[Any]):


           '''simple docstring'''

           __a							=    '''sshleifer/tinier_bart'''
           __a							=    AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE)
           __a							=    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
           __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE					,		configs=[config])
           __a							=    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							:					Any):


           '''simple docstring'''

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





       def 		_lowerCamelCase      (		self							:					Dict):


           '''simple docstring'''

           __a							=    '''sshleifer/tiny-gpt2'''

           def _check_summary_is_not_empty(__SCREAMING_SNAKE_CASE							:					Tuple):
               self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,		'''sequential'''))
               self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,		'''cumulative'''))
               self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,		'''current'''))
               self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,		'''total'''))

           with tempfile.TemporaryDirectory() as tmp_dir:
               __a							=    PyTorchBenchmarkArguments(
                   models=[MODEL_ID]					,		training=__SCREAMING_SNAKE_CASE					,		inference=__SCREAMING_SNAKE_CASE					,		sequence_lengths=[8]					,		batch_sizes=[1]					,		log_filename=os.path.join(__SCREAMING_SNAKE_CASE					,		'''log.txt''')					,		log_print=__SCREAMING_SNAKE_CASE					,		trace_memory_line_by_line=__SCREAMING_SNAKE_CASE					,		multi_process=__SCREAMING_SNAKE_CASE					,		)
               __a							=    PyTorchBenchmark(__SCREAMING_SNAKE_CASE)
               __a							=    benchmark.run()
               _check_summary_is_not_empty(result.inference_summary)
               _check_summary_is_not_empty(result.train_summary)
               self.assertTrue(Path(os.path.join(__SCREAMING_SNAKE_CASE					,		'''log.txt''')).exists())










def 					__snake_case     (      _UpperCAmelCase       ,			_UpperCAmelCase    ):
    return base * power(_UpperCAmelCase       ,			(exponent - 1)    ) if exponent else 1


if __name__ == "__main__":
 print('''Raise base to the power of exponent using recursion...''')
 __snake_case						:List[Any]						=					int(input('''Enter the base: ''').strip())
 __snake_case						:Dict						=					int(input('''Enter the exponent: ''').strip())
 __snake_case						:int						=					power(base, abs(exponent))
 if exponent < 0:  # power() does not properly deal w/ negative exponents
  __snake_case						:Optional[Any]						=					1 / result
 print(f'{base} to the power of {exponent} is {result}')





