




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




			def        lowerCAmelCase__    ( self    ,							a__							)    ->    int:

										'''simple docstring'''




										for model_result in results.values():
																	for batch_size, sequence_length in zip(model_result["bs"]    ,							model_result["ss"]							):
																								snake_case_      =				model_result["result"][batch_size][sequence_length]
																								self.assertIsNotNone(a__							)




			def        lowerCAmelCase__    ( self							)    ->    Any:

										'''simple docstring'''




										snake_case_      =				"sshleifer/tiny-gpt2"
										snake_case_      =				PyTorchBenchmarkArguments(
										    models=[MODEL_ID]    ,							training=a__    ,							inference=a__    ,							sequence_lengths=[8]    ,							batch_sizes=[1]    ,							multi_process=a__    ,							)
										snake_case_      =				PyTorchBenchmark(a__							)
										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        lowerCAmelCase__    ( self							)    ->    Any:

										'''simple docstring'''




										snake_case_      =				"sgugger/tiny-distilbert-classification"
										snake_case_      =				PyTorchBenchmarkArguments(
										    models=[MODEL_ID]    ,							training=a__    ,							inference=a__    ,							sequence_lengths=[8]    ,							batch_sizes=[1]    ,							multi_process=a__    ,							only_pretrain_model=a__    ,							)
										snake_case_      =				PyTorchBenchmark(a__							)
										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        lowerCAmelCase__    ( self							)    ->    Dict:

										'''simple docstring'''




										snake_case_      =				"sshleifer/tiny-gpt2"
										snake_case_      =				PyTorchBenchmarkArguments(
										    models=[MODEL_ID]    ,							training=a__    ,							inference=a__    ,							torchscript=a__    ,							sequence_lengths=[8]    ,							batch_sizes=[1]    ,							multi_process=a__    ,							)
										snake_case_      =				PyTorchBenchmark(a__							)
										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(torch_device == "cpu"    ,							"Cant do half precision"							)
			def        lowerCAmelCase__    ( self							)    ->    int:

										'''simple docstring'''




										snake_case_      =				"sshleifer/tiny-gpt2"
										snake_case_      =				PyTorchBenchmarkArguments(
										    models=[MODEL_ID]    ,							training=a__    ,							inference=a__    ,							fpaa=a__    ,							sequence_lengths=[8]    ,							batch_sizes=[1]    ,							multi_process=a__    ,							)
										snake_case_      =				PyTorchBenchmark(a__							)
										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        lowerCAmelCase__    ( self							)    ->    Tuple:

										'''simple docstring'''




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

										'''simple docstring'''




										snake_case_      =				"sshleifer/tiny-gpt2"
										snake_case_      =				PyTorchBenchmarkArguments(
										    models=[MODEL_ID]    ,							training=a__    ,							inference=a__    ,							sequence_lengths=[8]    ,							batch_sizes=[1]    ,							multi_process=a__    ,							)
										snake_case_      =				PyTorchBenchmark(a__							)
										snake_case_      =				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							)    ->    Any:

										'''simple docstring'''




										snake_case_      =				"sshleifer/tiny-gpt2"
										snake_case_      =				PyTorchBenchmarkArguments(
										    models=[MODEL_ID]    ,							training=a__    ,							inference=a__    ,							sequence_lengths=[8]    ,							batch_sizes=[1]    ,							fpaa=a__    ,							multi_process=a__    ,							)
										snake_case_      =				PyTorchBenchmark(a__							)
										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        lowerCAmelCase__    ( self							)    ->    Dict:

										'''simple docstring'''




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

										'''simple docstring'''




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

										'''simple docstring'''




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

										'''simple docstring'''




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

										'''simple docstring'''




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




			def        lowerCAmelCase__    ( self							)    ->    Tuple:

										'''simple docstring'''




										snake_case_      =				"sshleifer/tiny-gpt2"

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

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










'''simple docstring'''





from ..utils import DummyObject, requires_backends




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Dict							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    List[Any]:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    str:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Dict							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    Dict:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Optional[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[str]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Optional[Any]							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    str:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




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

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[str]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Optional[Any]							=   ["flax"]




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

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[str]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Dict:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				List[str]							=   ["flax"]




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

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Optional[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




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

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				int							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    List[str]:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Any:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Optional[Any]							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    Any:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    int:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Dict							=   ["flax"]




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

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




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

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    List[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				List[str]							=   ["flax"]




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

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Dict:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Union[str, Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				int							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    Dict:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Union[str, Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    int:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Any							=   ["flax"]




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

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Tuple:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    str:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				str							=   ["flax"]




			def __init__( self    ,							*a__    ,							**a__							)    ->    List[str]:

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Union[str, Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Union[str, Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




class 			_snake_case		(     metaclass=lowercase_							):
			lowerCAmelCase_					:				Tuple							=   ["flax"]




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

										'''simple docstring'''




										requires_backends(self    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    int:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




			@classmethod
			def        lowerCAmelCase__    ( cls    ,							*a__    ,							**a__							)    ->    Optional[Any]:

										'''simple docstring'''




										requires_backends(cls    ,							["flax"]							)




