'''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							(   _UpperCamelCase	:	Optional[int]				,     _UpperCamelCase	:	List[str]				,     _UpperCamelCase	:	Any       ):


      '''simple docstring'''


      if openai_config_file == "":
            UpperCAmelCase_      =	OpenAIGPTConfig()
      else:
            UpperCAmelCase_      =	OpenAIGPTConfig.from_json_file(SCREAMING_SNAKE_CASE_       )
      UpperCAmelCase_      =	OpenAIGPTModel(SCREAMING_SNAKE_CASE_       )

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

      # Save pytorch-model
      UpperCAmelCase_      =	pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
      UpperCAmelCase_      =	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__":
      lowercase__	:   int										=       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."
          ),
      )
      lowercase__	:   Any										=       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 ...configuration_utils import PretrainedConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE			=						logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE			=						{
    "facebook/dpr-ctx_encoder-single-nq-base": (
        "https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json"
    ),
    "facebook/dpr-question_encoder-single-nq-base": (
        "https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json"
    ),
    "facebook/dpr-reader-single-nq-base": (
        "https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json"
    ),
    "facebook/dpr-ctx_encoder-multiset-base": (
        "https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json"
    ),
    "facebook/dpr-question_encoder-multiset-base": (
        "https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json"
    ),
    "facebook/dpr-reader-multiset-base": (
        "https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json"
    ),
}
class   __UpperCAmelCase				(     lowerCAmelCase				):



					'''simple docstring'''





					_UpperCamelCase							=		"""dpr"""



					def __init__(	self     :						Optional[Any]      ,       _lowercase     :						Dict=30_522      ,       _lowercase     :						Tuple=768      ,       _lowercase     :						int=12      ,       _lowercase     :						List[str]=12      ,       _lowercase     :						Union[str, Any]=3_072      ,       _lowercase     :						Dict="gelu"      ,       _lowercase     :						Dict=0.1      ,       _lowercase     :						Any=0.1      ,       _lowercase     :						Union[str, Any]=512      ,       _lowercase     :						Optional[int]=2      ,       _lowercase     :						Union[str, Any]=0.02      ,       _lowercase     :						List[Any]=1E-12      ,       _lowercase     :						List[str]=0      ,       _lowercase     :						Dict="absolute"      ,       _lowercase     :						int = 0      ,       **_lowercase     :						int      ,       )    ->							int:
								super().__init__(pad_token_id=_lowercase      ,       **_lowercase)

								A_									= vocab_size
								A_									= hidden_size
								A_									= num_hidden_layers
								A_									= num_attention_heads
								A_									= hidden_act
								A_									= intermediate_size
								A_									= hidden_dropout_prob
								A_									= attention_probs_dropout_prob
								A_									= max_position_embeddings
								A_									= type_vocab_size
								A_									= initializer_range
								A_									= layer_norm_eps
								A_									= projection_dim
								A_									= position_embedding_type




