"""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   ,      lowercase)     ->      Any:





        '''simple docstring'''





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



      def   lowerCamelCase_       (						self)     ->      List[str]:





        '''simple docstring'''





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





        '''simple docstring'''





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





        '''simple docstring'''





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





        '''simple docstring'''





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





        '''simple docstring'''





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





        '''simple docstring'''





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





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





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





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





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





        '''simple docstring'''





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





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



      def   lowerCamelCase_       (						self)     ->      int:





        '''simple docstring'''





        a__:					Union[str, Any]      							=     'sshleifer/tiny-gpt2'

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

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



"""simple docstring"""
def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:
  return credit_card_number.startswith(('34', '35', '37', '4', '5', '6')       )







def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:
  a__:					Any      							=     credit_card_number
  a__:					Tuple      							=     0
  a__:					List[str]      							=     len(_SCREAMING_SNAKE_CASE       ) - 2
  for i in range(_SCREAMING_SNAKE_CASE		,					-1		,					-2       ):
    #  double the value of every second digit
    a__:					Tuple      							=     int(cc_number[i]       )
    digit *= 2
    # If doubling of a number results in a two digit number
    # i.e greater than 9(e.g., 6 × 2 = 12),
    # then add the digits of the product (e.g., 12: 1 + 2 = 3, 15: 1 + 5 = 6),
    # to get a single digit number.
    if digit > 9:
      digit %= 10
      digit += 1
    a__:					Optional[Any]      							=     cc_number[:i] + str(_SCREAMING_SNAKE_CASE       ) + cc_number[i + 1 :]
    total += digit

  # Sum up the remaining digits
  for i in range(len(_SCREAMING_SNAKE_CASE       ) - 1		,					-1		,					-2       ):
    total += int(cc_number[i]       )

  return total % 10 == 0







def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:
  a__:					Optional[int]      							=     F'{credit_card_number} is an invalid credit card number because'
  if not credit_card_number.isdigit():
    print(F'{error_message} it has nonnumerical characters.'       )
    return False

  if not 13 <= len(_SCREAMING_SNAKE_CASE       ) <= 16:
    print(F'{error_message} of its length.'       )
    return False

  if not validate_initial_digits(_SCREAMING_SNAKE_CASE       ):
    print(F'{error_message} of its first two digits.'       )
    return False

  if not luhn_validation(_SCREAMING_SNAKE_CASE       ):
    print(F'{error_message} it fails the Luhn check.'       )
    return False

  print(F'{credit_card_number} is a valid credit card number.'       )
  return True


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 validate_credit_card_number('4111111111111111')
 validate_credit_card_number('32323')


