




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     ):

    '''simple docstring'''






    def        SCREAMING_SNAKE_CASE							(			self      :	str					, UpperCAmelCase__      :	str)						->Optional[Any]:





           '''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(UpperCAmelCase__)


    def        SCREAMING_SNAKE_CASE							(			self      :	Tuple)						->Tuple:





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	Tuple)						->List[Any]:





           '''simple docstring'''

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


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





           '''simple docstring'''

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





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	Any)						->int:





           '''simple docstring'''

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





           '''simple docstring'''

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





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	str)						->Tuple:





           '''simple docstring'''

           A__       =    '''sshleifer/tiny-gpt2'''
           A__       =    AutoConfig.from_pretrained(UpperCAmelCase__)
           A__       =    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					, training=UpperCAmelCase__					, inference=UpperCAmelCase__					, sequence_lengths=[8]					, batch_sizes=[1]					, multi_process=UpperCAmelCase__					, )
           A__       =    PyTorchBenchmark(UpperCAmelCase__					, 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        SCREAMING_SNAKE_CASE							(			self      :	Union[str, Any])						->Optional[Any]:





           '''simple docstring'''

           A__       =    '''sshleifer/tinier_bart'''
           A__       =    AutoConfig.from_pretrained(UpperCAmelCase__)
           A__       =    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					, training=UpperCAmelCase__					, inference=UpperCAmelCase__					, sequence_lengths=[8]					, batch_sizes=[1]					, multi_process=UpperCAmelCase__					, )
           A__       =    PyTorchBenchmark(UpperCAmelCase__					, 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        SCREAMING_SNAKE_CASE							(			self      :	str)						->Any:





           '''simple docstring'''

           A__       =    '''sshleifer/tiny-gpt2'''
           A__       =    AutoConfig.from_pretrained(UpperCAmelCase__)
           A__       =    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					, training=UpperCAmelCase__					, inference=UpperCAmelCase__					, sequence_lengths=[8]					, batch_sizes=[1]					, multi_process=UpperCAmelCase__					, )
           A__       =    PyTorchBenchmark(UpperCAmelCase__					, 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        SCREAMING_SNAKE_CASE							(			self      :	int)						->Tuple:





           '''simple docstring'''

           A__       =    '''sshleifer/tinier_bart'''
           A__       =    AutoConfig.from_pretrained(UpperCAmelCase__)
           A__       =    PyTorchBenchmarkArguments(
               models=[MODEL_ID]					, training=UpperCAmelCase__					, inference=UpperCAmelCase__					, sequence_lengths=[8]					, batch_sizes=[1]					, multi_process=UpperCAmelCase__					, )
           A__       =    PyTorchBenchmark(UpperCAmelCase__					, 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        SCREAMING_SNAKE_CASE							(			self      :	Union[str, Any])						->Optional[Any]:





           '''simple docstring'''

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





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





           '''simple docstring'''

           A__       =    '''sshleifer/tiny-gpt2'''

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

           with tempfile.TemporaryDirectory() as tmp_dir:
                  A__       =    PyTorchBenchmarkArguments(
                      models=[MODEL_ID]					, training=UpperCAmelCase__					, inference=UpperCAmelCase__					, sequence_lengths=[8]					, batch_sizes=[1]					, log_filename=os.path.join(UpperCAmelCase__					, '''log.txt''')					, log_print=UpperCAmelCase__					, trace_memory_line_by_line=UpperCAmelCase__					, multi_process=UpperCAmelCase__					, )
                  A__       =    PyTorchBenchmark(UpperCAmelCase__)
                  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(UpperCAmelCase__					, '''log.txt''')).exists())









from __future__ import annotations

import typing
from collections import Counter







def 			A__							(    SCREAMING_SNAKE_CASE__)   ->    typing.Counter[int]:
  __snake_case:						typing.Counter[int]   =						Counter()
  for base in range(1					,					max_perimeter + 1):
    for perpendicular in range(SCREAMING_SNAKE_CASE__					,					max_perimeter + 1):
      __snake_case:						Dict   =						(base * base + perpendicular * perpendicular) ** 0.5
      if hypotenuse == int(SCREAMING_SNAKE_CASE__):
        __snake_case:						Any   =						int(base + perpendicular + hypotenuse)
        if perimeter > max_perimeter:
          continue
        triplets[perimeter] += 1
  return triplets







def 			A__							(    SCREAMING_SNAKE_CASE__ = 1000)   ->    int:
  __snake_case:						List[str]   =						pythagorean_triple(SCREAMING_SNAKE_CASE__)
  return triplets.most_common(1)[0][0]


if __name__ == "__main__":
      print(f'Perimeter {solution()} has maximum solutions')






