





"""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 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						Optional[Any]							,						SCREAMING_SNAKE_CASE     :						str							,						SCREAMING_SNAKE_CASE     :						int			):







      '''simple docstring'''




      if openai_config_file == "":
            lowerCAmelCase  						=       OpenAIGPTConfig()
      else:
            lowerCAmelCase  						=       OpenAIGPTConfig.from_json_file(SCREAMING_SNAKE_CASE			)
      lowerCAmelCase  						=       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
      lowerCAmelCase  						=       pytorch_dump_folder_path + """/""" + WEIGHTS_NAME
      lowerCAmelCase  						=       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__":
       SCREAMING_SNAKE_CASE__					=   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__					=   parser.parse_args()
       convert_openai_checkpoint_to_pytorch(
           args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
       )









from typing import Optional

import pyspark

from .. import Features, NamedSplit
from ..download import DownloadMode
from ..packaged_modules.spark.spark import Spark
from .abc import AbstractDatasetReader





class 	snake_case_   (		__A					):







			'''simple docstring'''

			def __init__(     self :				int							,   _UpperCamelCase :				pyspark.sql.DataFrame							,   _UpperCamelCase :				Optional[NamedSplit] = None							,   _UpperCamelCase :				Optional[Features] = None							,   _UpperCamelCase :				bool = True							,   _UpperCamelCase :				str = None							,   _UpperCamelCase :				bool = False							,   _UpperCamelCase :				str = None							,   _UpperCamelCase :				bool = True							,   _UpperCamelCase :				str = "arrow"							,   **_UpperCamelCase :				Tuple							,   )      ->str:
									super().__init__(
									    split=_UpperCamelCase							,   features=_UpperCamelCase							,   cache_dir=_UpperCamelCase							,   keep_in_memory=_UpperCamelCase							,   streaming=_UpperCamelCase							,   **_UpperCamelCase							,   )
									snake_case_   =	load_from_cache_file
									snake_case_   =	file_format
									snake_case_   =	Spark(
									    df=_UpperCamelCase							,   features=_UpperCamelCase							,   cache_dir=_UpperCamelCase							,   working_dir=_UpperCamelCase							,   **_UpperCamelCase							,   )







			def 				snake_case__(     self :				int							)      ->Tuple:
									if self.streaming:
															return self.builder.as_streaming_dataset(split=self.split							)
									snake_case_   =	None if self._load_from_cache_file else DownloadMode.FORCE_REDOWNLOAD
									self.builder.download_and_prepare(
									    download_mode=_UpperCamelCase							,   file_format=self._file_format							,   )
									return self.builder.as_dataset(split=self.split							)