





import argparse

import torch

from transformers import ImageGPTConfig, ImageGPTForCausalLM, load_tf_weights_in_imagegpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()



def _a       (			lowerCamelCase:     Optional[int]      ,       lowerCamelCase:     Any      ,       lowerCamelCase:     Any				)			->		List[Any]:







      '''simple docstring'''






      __A      =       {'''small''': (5_12, 8, 24), '''medium''': (10_24, 8, 36), '''large''': (15_36, 16, 48)}
      __A     ,		__A     ,		__A      =       MODELS[model_size]  # set model hyperparameters
      __A      =       ImageGPTConfig(n_embd=lowerCamelCase      ,       n_layer=lowerCamelCase      ,       n_head=lowerCamelCase				)
      __A      =       ImageGPTForCausalLM(lowerCamelCase				)

      # Load weights from numpy
      load_tf_weights_in_imagegpt(lowerCamelCase      ,       lowerCamelCase      ,       lowerCamelCase				)

      # Save pytorch-model
      __A      =       pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
      __A      =       pytorch_dump_folder_path + '''/''' + CONFIG_NAME
      print(F"""Save PyTorch model to {pytorch_weights_dump_path}"""				)
      torch.save(model.state_dict()      ,       lowerCamelCase				)
      print(F"""Save configuration file to {pytorch_config_dump_path}"""				)
      with open(lowerCamelCase      ,       '''w'''      ,       encoding='''utf-8'''				) as f:
            f.write(config.to_json_string()				)


if __name__ == "__main__":
       snake_case__									=  argparse.ArgumentParser()
       # Required parameters
       parser.add_argument(
           '--imagegpt_checkpoint_path',
           default=None,
           type=str,
           required=True,
           help='Path to the TensorFlow checkpoint path.',
       )
       parser.add_argument(
           '--model_size',
           default=None,
           type=str,
           required=True,
           help='Size of the model (can be either \'small\', \'medium\' or \'large\').',
       )
       parser.add_argument(
           '--pytorch_dump_folder_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
       )
       snake_case__									=  parser.parse_args()
       convert_imagegpt_checkpoint_to_pytorch(
           args.imagegpt_checkpoint_path, args.model_size, args.pytorch_dump_folder_path
       )












import unittest
from timeit import timeit



def _a       (			lowerCamelCase:     int      ,       lowerCamelCase:     int				)			->		int:







      '''simple docstring'''






      __A      =       first_num if first_num >= second_num else second_num
      __A      =       max_num
      while (common_mult % first_num > 0) or (common_mult % second_num > 0):
            common_mult += max_num
      return common_mult



def _a       (			lowerCamelCase:     int      ,       lowerCamelCase:     int				)			->		int:







      '''simple docstring'''






      return b if a == 0 else greatest_common_divisor(b % a      ,       lowerCamelCase				)



def _a       (			lowerCamelCase:     int      ,       lowerCamelCase:     int				)			->		int:







      '''simple docstring'''






      return first_num // greatest_common_divisor(lowerCamelCase      ,       lowerCamelCase				) * second_num



def _a       (			)			->		Tuple:







      '''simple docstring'''






      __A      =       (
          '''from __main__ import least_common_multiple_slow, least_common_multiple_fast'''
      )
      print(
          '''least_common_multiple_slow():'''      ,       timeit('''least_common_multiple_slow(1000, 999)'''      ,       setup=lowerCamelCase				)      ,       )
      print(
          '''least_common_multiple_fast():'''      ,       timeit('''least_common_multiple_fast(1000, 999)'''      ,       setup=lowerCamelCase				)      ,       )





class A_      (    unittest.TestCase     ):
   lowerCAmelCase__       =				(
       (10, 20),
       (13, 15),
       (4, 31),
       (10, 42),
       (43, 34),
       (5, 12),
       (12, 25),
       (10, 25),
       (6, 9),
   )
   lowerCAmelCase__       =				(20, 195, 124, 210, 1462, 60, 300, 50, 18)




   def _lowerCAmelCase   (self			:List[str]				)->      Union[str, Any]:
         for i, (first_num, second_num) in enumerate(self.test_inputs				):
               __A      =       least_common_multiple_slow(_UpperCamelCase					,     _UpperCamelCase				)
               __A      =       least_common_multiple_fast(_UpperCamelCase					,     _UpperCamelCase				)
               with self.subTest(i=_UpperCamelCase				):
                     self.assertEqual(_UpperCamelCase					,     self.expected_results[i]				)
                     self.assertEqual(_UpperCamelCase					,     self.expected_results[i]				)


if __name__ == "__main__":
       benchmark()
       unittest.main()





