
from typing import List

from .keymap import KEYMAP, get_character







def     A__   (  lowerCamelCase  )					->		str:

				def decorator(lowerCamelCase  ):
								UpperCamelCase_:							Optional[int]		=  getattr(lowerCamelCase       ,      """handle_key"""       ,      []  )
								handle += [key]
								setattr(lowerCamelCase       ,      """handle_key"""       ,      lowerCamelCase  )
								return func

				return decorator







def     A__   (  *lowerCamelCase  )					->		Tuple:

				def decorator(lowerCamelCase  ):
								UpperCamelCase_:							Union[str, Any]		=  getattr(lowerCamelCase       ,      """handle_key"""       ,      []  )
								handle += keys
								setattr(lowerCamelCase       ,      """handle_key"""       ,      lowerCamelCase  )
								return func

				return decorator

class     _UpperCamelCase			(   _A					):






			'''simple docstring'''

			def __new__(    cls	:    List[str]  ,		snake_case_	:    Optional[int]  ,		snake_case_	:    Any  ,		snake_case_	:    List[str] ):
							UpperCamelCase_:							Dict		=  super().__new__(cls  ,		snake_case_  ,		snake_case_  ,		snake_case_ )
							if not hasattr(snake_case_  ,		"""key_handler""" ):
											setattr(snake_case_  ,		"""key_handler"""  ,		{} )
							setattr(snake_case_  ,		"""handle_input"""  ,		KeyHandler.handle_input )

							for value in attrs.values():
											UpperCamelCase_:							Union[str, Any]		=  getattr(snake_case_  ,		"""handle_key"""  ,		[] )
											for key in handled_keys:
															UpperCamelCase_:							Optional[Any]		=  value
							return new_cls




			@staticmethod
			def  lowerCAmelCase__		(    cls	:    Optional[Any] ):
							UpperCamelCase_:							str		=  get_character()
							if char != KEYMAP["undefined"]:
											UpperCamelCase_:							Tuple		=  ord(snake_case_ )
							UpperCamelCase_:							Dict		=  cls.key_handler.get(snake_case_ )
							if handler:
											UpperCamelCase_:							Optional[Any]		=  char
											return handler(cls )
							else:
											return None







def     A__   (  cls  )					->		List[str]:
				return KeyHandler(cls.__name__       ,      cls.__bases__       ,      cls.__dict__.copy()  )








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     A__   (  lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase  )					->		Union[str, Any]:
				# Construct model
				if gpta_config_file == "":
								UpperCamelCase_:							Union[str, Any]		=  GPTaConfig()
				else:
								UpperCamelCase_:							Optional[Any]		=  GPTaConfig.from_json_file(lowerCamelCase  )
				UpperCamelCase_:							List[Any]		=  GPTaModel(lowerCamelCase  )

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

				# Save pytorch-model
				UpperCamelCase_:							int		=  pytorch_dump_folder_path + """/""" + WEIGHTS_NAME
				UpperCamelCase_:							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__":
							lowerCamelCase_  :	int 				=					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."""
							    ),
							)
							lowerCamelCase_  :	List[str] 				=					parser.parse_args()
							convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)






