


"""simple docstring"""
import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE :    Union[str, Any]									=				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE :    int									=				{
    """RUCAIBox/mvp""": """https://huggingface.co/RUCAIBox/mvp/resolve/main/config.json""",
}



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='mvp'
		lowerCamelCase__				=['past_key_values']
		lowerCamelCase__				={'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}



		def __init__(self				,       a_=5_02_67				,       a_=10_24				,       a_=12				,       a_=40_96				,       a_=16				,       a_=12				,       a_=40_96				,       a_=16				,       a_=0.0				,       a_=0.0				,       a_="gelu"				,       a_=10_24				,       a_=0.1				,       a_=0.0				,       a_=0.0				,       a_=0.02				,       a_=0.0				,       a_=False				,       a_=True				,       a_=1				,       a_=0				,       a_=2				,       a_=True				,       a_=2				,       a_=2				,       a_=False				,       a_=1_00				,       a_=8_00				,       **a_				,       ):





			'''simple docstring'''

			__snake_case	:						int						=				vocab_size
			__snake_case	:						str						=				max_position_embeddings
			__snake_case	:						Any						=				d_model
			__snake_case	:						str						=				encoder_ffn_dim
			__snake_case	:						Any						=				encoder_layers
			__snake_case	:						int						=				encoder_attention_heads
			__snake_case	:						Optional[int]						=				decoder_ffn_dim
			__snake_case	:						Optional[int]						=				decoder_layers
			__snake_case	:						Optional[int]						=				decoder_attention_heads
			__snake_case	:						List[Any]						=				dropout
			__snake_case	:						Tuple						=				attention_dropout
			__snake_case	:						Optional[int]						=				activation_dropout
			__snake_case	:						Union[str, Any]						=				activation_function
			__snake_case	:						Optional[Any]						=				init_std
			__snake_case	:						Dict						=				encoder_layerdrop
			__snake_case	:						List[Any]						=				decoder_layerdrop
			__snake_case	:						str						=				classifier_dropout
			__snake_case	:						Tuple						=				use_cache
			__snake_case	:						Union[str, Any]						=				encoder_layers
			__snake_case	:						Dict						=				scale_embedding  # scale factor will be sqrt(d_model) if True
			__snake_case	:						List[str]						=				use_prompt
			__snake_case	:						str						=				prompt_length
			__snake_case	:						Any						=				prompt_mid_dim

			super().__init__(
			    pad_token_id=a_				,       bos_token_id=a_				,       eos_token_id=a_				,       is_encoder_decoder=a_				,       decoder_start_token_id=a_				,       forced_eos_token_id=a_				,       **a_				,       )

			if self.forced_bos_token_id is None and kwargs.get('''force_bos_token_to_be_generated'''				,       a_					):
				__snake_case	:						str						=				self.bos_token_id
				warnings.warn(
				    f"""Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. """
				    '''The config can simply be saved and uploaded again to be fixed.'''					)









"""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 		lowercase							(     _snake_case						:      List[Any]     ,   _snake_case						:      Tuple     ,   _snake_case						:      int     )     ->List[Any]:
	"""simple docstring"""





	if openai_config_file == "":
		__snake_case	:						Dict						=				OpenAIGPTConfig()
	else:
		__snake_case	:						int						=				OpenAIGPTConfig.from_json_file(_snake_case     )
	__snake_case	:						Tuple						=				OpenAIGPTModel(_snake_case     )

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

	# Save pytorch-model
	__snake_case	:						str						=				pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
	__snake_case	:						Optional[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__":
			SCREAMING_SNAKE_CASE :    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."""
			    ),
			)
			SCREAMING_SNAKE_CASE :    Optional[int]									=				parser.parse_args()
			convert_openai_checkpoint_to_pytorch(
			    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
			)





