'''simple docstring'''






def  _SCREAMING_SNAKE_CASE		(      __snake_case							:			int				):
     if upper_limit < 0:
          raise ValueError('Limit for the Catalan sequence must be ≥ 0'				)

     _A    		=  [0] * (upper_limit + 1)

     # Base case: C(0) = C(1) = 1
     _A    		=  1
     if upper_limit > 0:
          _A    		=  1

     # Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
     for i in range(2   ,		upper_limit + 1				):
          for j in range(__snake_case				):
               catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

     return catalan_list


if __name__ == "__main__":
   print('''\n********* Catalan Numbers Using Dynamic Programming ************\n''')
   print('''\n*** Enter -1 at any time to quit ***''')
   print('''\nEnter the upper limit (≥ 0) for the Catalan number sequence: ''', end='''''')
   try:
      while True:
         _UpperCAmelCase    :     int         =       int(input().strip())
         if N < 0:
            print('''\n********* Goodbye!! ************''')
            break
         else:
            print(F'''The Catalan numbers from 0 through {N} are:''')
            print(catalan_numbers(N))
            print('''Try another upper limit for the sequence: ''', end='''''')
   except (NameError, ValueError):
      print('''\n********* Invalid input, goodbye! ************\n''')

   import doctest

   doctest.testmod()




'''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 						UpperCAmelCase_	(	self    ,     _lowerCamelCase ):
     for model_result in results.values():
        for batch_size, sequence_length in zip(model_result['''bs''']    ,     model_result['''ss'''] ):
           lowerCAmelCase_			=      model_result['''result'''][batch_size][sequence_length]
           self.assertIsNotNone(_lowerCamelCase )





  def 						UpperCAmelCase_	(	self ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sgugger/tiny-distilbert-classification'''
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     only_pretrain_model=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     torchscript=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     fpaa=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      AutoConfig.from_pretrained(_lowerCamelCase )
     # set architectures equal to `None`
     lowerCAmelCase_			=      None
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase    ,     configs=[config] )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     fpaa=_lowerCamelCase    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      AutoConfig.from_pretrained(_lowerCamelCase )
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase    ,     configs=[config] )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tinier_bart'''
     lowerCAmelCase_			=      AutoConfig.from_pretrained(_lowerCamelCase )
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase    ,     configs=[config] )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     lowerCAmelCase_			=      AutoConfig.from_pretrained(_lowerCamelCase )
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase    ,     configs=[config] )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tinier_bart'''
     lowerCAmelCase_			=      AutoConfig.from_pretrained(_lowerCamelCase )
     lowerCAmelCase_			=      PyTorchBenchmarkArguments(
         models=[MODEL_ID]    ,     training=_lowerCamelCase    ,     inference=_lowerCamelCase    ,     sequence_lengths=[8]    ,     batch_sizes=[1]    ,     multi_process=_lowerCamelCase    ,     )
     lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase    ,     configs=[config] )
     lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''sshleifer/tiny-gpt2'''
     with tempfile.TemporaryDirectory() as tmp_dir:
        lowerCAmelCase_			=      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    ,     )
        lowerCAmelCase_			=      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 ):
     lowerCAmelCase_			=      '''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:
        lowerCAmelCase_			=      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    ,     )
        lowerCAmelCase_			=      PyTorchBenchmark(_lowerCamelCase )
        lowerCAmelCase_			=      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() )





