


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




				def   a__(	self    :				Tuple   ,					lowerCAmelCase    :				str   )->  Optional[int]:

										"""simple docstring"""




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




				def   a__(	self    :				List[Any]   )->  Union[str, Any]:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_inference_result   )
										self.check_results_dict_not_empty(results.memory_inference_result   )




				def   a__(	self    :				int   )->  List[str]:

										"""simple docstring"""




										UpperCAmelCase         =			'''sgugger/tiny-distilbert-classification'''
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					only_pretrain_model=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_inference_result   )
										self.check_results_dict_not_empty(results.memory_inference_result   )




				def   a__(	self    :				Union[str, Any]   )->  List[Any]:

										"""simple docstring"""




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

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					fpaa=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_inference_result   )
										self.check_results_dict_not_empty(results.memory_inference_result   )




				def   a__(	self    :				Optional[Any]   )->  int:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										UpperCAmelCase         =			AutoConfig.from_pretrained(lowerCAmelCase   )
										# set architectures equal to `None`
										UpperCAmelCase         =			None
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   ,					configs=[config]   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_inference_result   )
										self.check_results_dict_not_empty(results.memory_inference_result   )




				def   a__(	self    :				Optional[Any]   )->  Optional[Any]:

										"""simple docstring"""




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

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					fpaa=lowerCAmelCase   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_train_result   )
										self.check_results_dict_not_empty(results.memory_train_result   )




				def   a__(	self    :				Dict   )->  str:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										UpperCAmelCase         =			AutoConfig.from_pretrained(lowerCAmelCase   )
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   ,					configs=[config]   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_inference_result   )
										self.check_results_dict_not_empty(results.memory_inference_result   )




				def   a__(	self    :				Optional[Any]   )->  Union[str, Any]:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tinier_bart'''
										UpperCAmelCase         =			AutoConfig.from_pretrained(lowerCAmelCase   )
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   ,					configs=[config]   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_inference_result   )
										self.check_results_dict_not_empty(results.memory_inference_result   )




				def   a__(	self    :				Union[str, Any]   )->  List[str]:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										UpperCAmelCase         =			AutoConfig.from_pretrained(lowerCAmelCase   )
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   ,					configs=[config]   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_train_result   )
										self.check_results_dict_not_empty(results.memory_train_result   )




				def   a__(	self    :				int   )->  Any:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tinier_bart'''
										UpperCAmelCase         =			AutoConfig.from_pretrained(lowerCAmelCase   )
										UpperCAmelCase         =			PyTorchBenchmarkArguments(
										    models=[MODEL_ID]   ,					training=lowerCAmelCase   ,					inference=lowerCAmelCase   ,					sequence_lengths=[8]   ,					batch_sizes=[1]   ,					multi_process=lowerCAmelCase   ,					)
										UpperCAmelCase         =			PyTorchBenchmark(lowerCAmelCase   ,					configs=[config]   )
										UpperCAmelCase         =			benchmark.run()
										self.check_results_dict_not_empty(results.time_train_result   )
										self.check_results_dict_not_empty(results.memory_train_result   )




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

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''
										with tempfile.TemporaryDirectory() as tmp_dir:
																UpperCAmelCase         =			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         =			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   a__(	self    :				Dict   )->  Tuple:

										"""simple docstring"""




										UpperCAmelCase         =			'''sshleifer/tiny-gpt2'''

										def _check_summary_is_not_empty(lowerCAmelCase    :				Optional[Any]   ):
																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         =			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         =			PyTorchBenchmark(lowerCAmelCase   )
																UpperCAmelCase         =			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'''



from ..utils import DummyObject, requires_backends






class  UpperCamelCase__(     metaclass=lowerCAmelCase ):
				__magic_name__       :   List[str]							= ["note_seq"]




				def __init__(	self    :				Any   ,					*lowerCAmelCase    :				List[str]   ,					**lowerCAmelCase    :				int   )->  Optional[int]:

										"""simple docstring"""




										requires_backends(self   ,					['''note_seq''']   )




				@classmethod
				def   a__(	cls    :				Dict   ,					*lowerCAmelCase    :				int   ,					**lowerCAmelCase    :				Optional[int]   )->  Dict:

										"""simple docstring"""




										requires_backends(cls   ,					['''note_seq''']   )





				@classmethod
				def   a__(	cls    :				int   ,					*lowerCAmelCase    :				Tuple   ,					**lowerCAmelCase    :				Optional[Any]   )->  Union[str, Any]:

										"""simple docstring"""




										requires_backends(cls   ,					['''note_seq''']   )





