




"""simple docstring"""
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 						UpperCAmelCase				(			A__:    Any							,				A__:    List[str]							,				A__:    str     )  ->     Tuple:






			if gpta_config_file == "":
						__lowerCamelCase					:	List[Any]	       =				GPTaConfig()
			else:
						__lowerCamelCase					:	str	       =				GPTaConfig.from_json_file(A__     )
			__lowerCamelCase					:	str	       =				GPTaModel(A__     )

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

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


if __name__ == "__main__":
					a_				:    str							=     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.'''
					    ),
					)
					a_				:    Optional[int]							=     parser.parse_args()
					convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)









"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_				:    Tuple										=     logging.get_logger(__name__)

a_				:    str										=     {'''openai-gpt''': '''https://huggingface.co/openai-gpt/resolve/main/config.json'''}

class __lowercase(      lowercase__				):




					'''simple docstring'''


					__a						:						Union[str, Any]     		= 'openai-gpt'
					__a						:						List[Any]     		= {
					    'max_position_embeddings': 'n_positions',
					    'hidden_size': 'n_embd',
					    'num_attention_heads': 'n_head',
					    'num_hidden_layers': 'n_layer',
					}
					def __init__(    self						,	__a=40478						,	__a=512						,	__a=768						,	__a=12						,	__a=12						,	__a="gelu"						,	__a=0.1						,	__a=0.1						,	__a=0.1						,	__a=1E-5						,	__a=0.02						,	__a="cls_index"						,	__a=True						,	__a=None						,	__a=True						,	__a=0.1						,	**__a						,	):
								__lowerCamelCase					:	List[str]	       =				vocab_size
								__lowerCamelCase					:	Union[str, Any]	       =				n_positions
								__lowerCamelCase					:	Optional[Any]	       =				n_embd
								__lowerCamelCase					:	int	       =				n_layer
								__lowerCamelCase					:	List[str]	       =				n_head
								__lowerCamelCase					:	Dict	       =				afn
								__lowerCamelCase					:	Optional[Any]	       =				resid_pdrop
								__lowerCamelCase					:	int	       =				embd_pdrop
								__lowerCamelCase					:	int	       =				attn_pdrop
								__lowerCamelCase					:	Dict	       =				layer_norm_epsilon
								__lowerCamelCase					:	List[str]	       =				initializer_range
								__lowerCamelCase					:	Any	       =				summary_type
								__lowerCamelCase					:	Tuple	       =				summary_use_proj
								__lowerCamelCase					:	List[Any]	       =				summary_activation
								__lowerCamelCase					:	str	       =				summary_first_dropout
								__lowerCamelCase					:	Tuple	       =				summary_proj_to_labels
								super().__init__(**__a     )



