


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





							"""simple docstring"""







							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										for model_result in results.values():
													for batch_size, sequence_length in zip(model_result['bs']			,						model_result['ss']       ):
																SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					model_result['result'][batch_size][sequence_length]
																self.assertIsNotNone(lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




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





										"""simple docstring"""




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





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Tuple					=					'sshleifer/tiny-gpt2'
										SCREAMING_SNAKE_CASE_		:     Dict					=					PyTorchBenchmarkArguments(
										    models=[MODEL_ID]			,						training=lowerCAmelCase__			,						inference=lowerCAmelCase__			,						torchscript=lowerCAmelCase__			,						sequence_lengths=[8]			,						batch_sizes=[1]			,						multi_process=lowerCAmelCase__			,						)
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					PyTorchBenchmark(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					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 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




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





										"""simple docstring"""




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





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					'sshleifer/tiny-gpt2'
										SCREAMING_SNAKE_CASE_		:     int					=					PyTorchBenchmarkArguments(
										    models=[MODEL_ID]			,						training=lowerCAmelCase__			,						inference=lowerCAmelCase__			,						sequence_lengths=[8]			,						batch_sizes=[1]			,						multi_process=lowerCAmelCase__			,						)
										SCREAMING_SNAKE_CASE_		:     Dict					=					PyTorchBenchmark(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					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 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




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





										"""simple docstring"""




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





										"""simple docstring"""




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





										"""simple docstring"""




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





										"""simple docstring"""




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





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[str]					=					'sshleifer/tiny-gpt2'
										with tempfile.TemporaryDirectory() as tmp_dir:
													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					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__			,						)
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					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 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					'sshleifer/tiny-gpt2'

										def _check_summary_is_not_empty(lowerCAmelCase__       ):
													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:
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					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__			,						)
													SCREAMING_SNAKE_CASE_		:     int					=					PyTorchBenchmark(lowerCAmelCase__       )
													SCREAMING_SNAKE_CASE_		:     str					=					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()       )









def 						a__			(				A__ = 5_0_0_0_0_0_0_0				):
			SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					set()
			SCREAMING_SNAKE_CASE_		:     Optional[int]					=					int((limit - 2_4) ** (1 / 2)				)

			SCREAMING_SNAKE_CASE_		:     Dict					=					set(range(3,      prime_square_limit + 1,      2				)				)
			primes.add(2				)
			for p in range(3,      prime_square_limit + 1,      2				):
						if p not in primes:
									continue
						primes.difference_update(set(range(p * p,      prime_square_limit + 1,      A__				)				)				)

			for primea in primes:
						SCREAMING_SNAKE_CASE_		:     int					=					primea * primea
						for primea in primes:
									SCREAMING_SNAKE_CASE_		:     Dict					=					primea * primea * primea
									if square + cube >= limit - 1_6:
												break
									for primea in primes:
												SCREAMING_SNAKE_CASE_		:     Optional[int]					=					primea * primea * primea * primea
												SCREAMING_SNAKE_CASE_		:     str					=					square + cube + tetr
												if total >= limit:
															break
												ret.add(A__				)

			return len(A__				)


if __name__ == "__main__":
				print(F"""{solution() = }""")





