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


__lowercase							 =					logging.get_logger(__name__)

__lowercase							 =					{
    '''google/realm-cc-news-pretrained-embedder''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json'''
    ),
    '''google/realm-cc-news-pretrained-encoder''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json'''
    ),
    '''google/realm-cc-news-pretrained-scorer''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json'''
    ),
    '''google/realm-cc-news-pretrained-openqa''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json'''
    ),
    '''google/realm-orqa-nq-openqa''': '''https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json''',
    '''google/realm-orqa-nq-reader''': '''https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json''',
    '''google/realm-orqa-wq-openqa''': '''https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json''',
    '''google/realm-orqa-wq-reader''': '''https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json''',
    # See all REALM models at https://huggingface.co/models?filter=realm
}


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						Any						=      """realm"""







    def __init__(	self , __lowercase=30_522 , __lowercase=768 , __lowercase=128 , __lowercase=12 , __lowercase=12 , __lowercase=8 , __lowercase=3_072 , __lowercase="gelu_new" , __lowercase=0.1 , __lowercase=0.1 , __lowercase=512 , __lowercase=2 , __lowercase=0.02 , __lowercase=1E-1_2 , __lowercase=256 , __lowercase=10 , __lowercase=1E-3 , __lowercase=5 , __lowercase=320 , __lowercase=13_353_718 , __lowercase=5_000 , __lowercase=1 , __lowercase=0 , __lowercase=2 , **__lowercase , )       ->	Tuple:
        super().__init__(pad_token_id=__lowercase , bos_token_id=__lowercase , eos_token_id=__lowercase , **__lowercase)

        # Common config
        __UpperCamelCase     :Union[str, Any]			  =		vocab_size
        __UpperCamelCase     :int			  =		max_position_embeddings
        __UpperCamelCase     :List[Any]			  =		hidden_size
        __UpperCamelCase     :List[str]			  =		retriever_proj_size
        __UpperCamelCase     :int			  =		num_hidden_layers
        __UpperCamelCase     :str			  =		num_attention_heads
        __UpperCamelCase     :List[str]			  =		num_candidates
        __UpperCamelCase     :List[Any]			  =		intermediate_size
        __UpperCamelCase     :List[str]			  =		hidden_act
        __UpperCamelCase     :List[Any]			  =		hidden_dropout_prob
        __UpperCamelCase     :int			  =		attention_probs_dropout_prob
        __UpperCamelCase     :List[Any]			  =		initializer_range
        __UpperCamelCase     :Dict			  =		type_vocab_size
        __UpperCamelCase     :List[str]			  =		layer_norm_eps

        # Reader config
        __UpperCamelCase     :List[Any]			  =		span_hidden_size
        __UpperCamelCase     :int			  =		max_span_width
        __UpperCamelCase     :List[str]			  =		reader_layer_norm_eps
        __UpperCamelCase     :Optional[int]			  =		reader_beam_size
        __UpperCamelCase     :Optional[Any]			  =		reader_seq_len

        # Retrieval config
        __UpperCamelCase     :str			  =		num_block_records
        __UpperCamelCase     :Any			  =		searcher_beam_size








"""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     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )	->	Optional[int]:
		# Construct model
		if gpta_config_file == "":
				__lowerCAmelCase:       Optional[int]          =			GPTaConfig()
		else:
				__lowerCAmelCase:       List[str]          =			GPTaConfig.from_json_file(__SCREAMING_SNAKE_CASE )
		__lowerCAmelCase:       Optional[int]          =			GPTaModel(__SCREAMING_SNAKE_CASE )

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

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


if __name__ == "__main__":
			__A						   =			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						   =			parser.parse_args()
			convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)


