





import argparse

import torch

from transformers import GPTaConfig, GPTaModel, load_tf_weights_in_gpta
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()





def  __magic_name__  (				lowercase				,       lowercase				,       lowercase				)				-> Any:

							"""simple docstring"""



							if gpta_config_file == "":
														lowercase_	:   Any  				=     GPTaConfig()
							else:
														lowercase_	:   Optional[Any]  				=     GPTaConfig.from_json_file(_lowerCamelCase				)
							lowercase_	:   Tuple  				=     GPTaModel(_lowerCamelCase				)

							# Load weights from numpy
							load_tf_weights_in_gpta(_lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				)

							# Save pytorch-model
							lowercase_	:   List[str]  				=     pytorch_dump_folder_path + """/""" + WEIGHTS_NAME
							lowercase_	:   Optional[Any]  				=     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__":
							UpperCAmelCase_							=				argparse.ArgumentParser()
							# Required parameters
							parser.add_argument(
							    """--gpt2_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
							)
							parser.add_argument(
							    """--pytorch_dump_folder_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
							)
							parser.add_argument(
							    """--gpt2_config_file""",
							    default="""""",
							    type=str,
							    help=(
							        """An optional config json file corresponding to the pre-trained OpenAI model. \n"""
							        """This specifies the model architecture."""
							    ),
							)
							UpperCAmelCase_							=				parser.parse_args()
							convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)





'''simple docstring'''



def       _UpperCamelCase			(_lowerCamelCase				:  int						)-> int:




     '''simple docstring'''





     __snake_case            =	abs(_lowerCamelCase						)
     __snake_case            =	0
     while n > 0:
          res += n % 10
          n //= 10
     return res







def       _UpperCamelCase			(_lowerCamelCase				:  int						)-> int:




     '''simple docstring'''





     __snake_case            =	abs(_lowerCamelCase						)
     return n if n < 10 else n % 10 + sum_of_digits(n // 10						)







def       _UpperCamelCase			(_lowerCamelCase				:  int						)-> int:




     '''simple docstring'''





     return sum(int(_lowerCamelCase						) for c in str(abs(_lowerCamelCase						)						)						)







def       _UpperCamelCase			()-> None:




     '''simple docstring'''





     from collections.abc import Callable
     from timeit import timeit

     def benchmark_a_function(_lowerCamelCase				:  Callable ,						_lowerCamelCase				:  int						) -> None:
          __snake_case            =	f'''{func.__name__}({value})'''
          __snake_case            =	timeit(f'''__main__.{call}''' ,						setup='''import __main__'''						)
          print(f'''{call:56} = {func(_lowerCamelCase						)} -- {timing:.4f} seconds'''						)

     for value in (26_21_44, 11_25_89_99_06_84_26_24, 1_26_76_50_60_02_28_22_94_01_49_67_03_20_53_76):
          for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
               benchmark_a_function(_lowerCamelCase ,						_lowerCamelCase						)
          print()


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     benchmark()






