

'''simple docstring'''



import argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()
def 						__lowerCamelCase	(       __snake_case					:		str,		__snake_case					:		int,		__snake_case					:		List[str]	)	->							int:






						"""simple docstring"""





						if openai_config_file == "":
												A__					:       int     =OpenAIGPTConfig()
						else:
												A__					:       Dict     =OpenAIGPTConfig.from_json_file(__snake_case	)
						A__					:       Optional[int]     =OpenAIGPTModel(__snake_case	)

						# Load weights from numpy
						load_tf_weights_in_openai_gpt(__snake_case,		__snake_case,		__snake_case	)

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


if __name__ == "__main__":
		__snake_case			:     Union[str, Any]										=      argparse.ArgumentParser()
		# Required parameters
		parser.add_argument(
		    '--openai_checkpoint_folder_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(
		    '--openai_config_file',
		    default='',
		    type=str,
		    help=(
		        'An optional config json file corresponding to the pre-trained OpenAI model. \n'
		        'This specifies the model architecture.'
		    ),
		)
		__snake_case			:     Dict										=      parser.parse_args()
		convert_openai_checkpoint_to_pytorch(
		    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
		)




'''simple docstring'''



from argparse import ArgumentParser

from .add_new_model import AddNewModelCommand
from .add_new_model_like import AddNewModelLikeCommand
from .convert import ConvertCommand
from .download import DownloadCommand
from .env import EnvironmentCommand
from .lfs import LfsCommands
from .pt_to_tf import PTtoTFCommand
from .run import RunCommand
from .serving import ServeCommand
from .user import UserCommands
def 						__lowerCamelCase	(       )	->							List[Any]:






						"""simple docstring"""





						A__					:       List[Any]     =ArgumentParser("""Transformers CLI tool""",		usage="""transformers-cli <command> [<args>]"""	)
						A__					:       List[Any]     =parser.add_subparsers(help="""transformers-cli command helpers"""	)

						# Register commands
						ConvertCommand.register_subcommand(__snake_case	)
						DownloadCommand.register_subcommand(__snake_case	)
						EnvironmentCommand.register_subcommand(__snake_case	)
						RunCommand.register_subcommand(__snake_case	)
						ServeCommand.register_subcommand(__snake_case	)
						UserCommands.register_subcommand(__snake_case	)
						AddNewModelCommand.register_subcommand(__snake_case	)
						AddNewModelLikeCommand.register_subcommand(__snake_case	)
						LfsCommands.register_subcommand(__snake_case	)
						PTtoTFCommand.register_subcommand(__snake_case	)

						# Let's go
						A__					:       List[str]     =parser.parse_args()

						if not hasattr(__snake_case,		"""func"""	):
												parser.print_help()
												exit(1	)

						# Run
						A__					:       Optional[Any]     =args.func(__snake_case	)
						service.run()


if __name__ == "__main__":
		main()

