





'''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				( lowercase						:      Any    ,							lowercase						:      Optional[int]    ,							lowercase						:      Dict						)	->	Optional[Any]:
				# Construct model
				if openai_config_file == "":
								_a								= OpenAIGPTConfig()
				else:
								_a								= OpenAIGPTConfig.from_json_file(lowercase						)
				_a								= OpenAIGPTModel(lowercase						)

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

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


if __name__ == "__main__":
					lowerCAmelCase_					:    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.'
					    ),
					)
					lowerCAmelCase_					:    List[Any]      	=			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 Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream

class 		UpperCamelCase__ (      lowerCAmelCase_   ):



     '''simple docstring'''

     def __init__(							self						:    Union[str, Any]						,lowerCamelCase__						:    Callable						,lowerCamelCase__						:    Optional[Features] = None						,lowerCamelCase__						:    str = None						,lowerCamelCase__						:    bool = False						,lowerCamelCase__						:    bool = False						,lowerCamelCase__						:    Optional[dict] = None						,lowerCamelCase__						:    Optional[int] = None						,**lowerCamelCase__						:    Optional[Any]						,)     ->		List[str]:




           '''simple docstring'''


           super().__init__(
               features=lowerCamelCase__						,cache_dir=lowerCamelCase__						,keep_in_memory=lowerCamelCase__						,streaming=lowerCamelCase__						,num_proc=lowerCamelCase__						,**lowerCamelCase__						,)
           SCREAMING_SNAKE_CASE		=						Generator(
               cache_dir=lowerCamelCase__						,features=lowerCamelCase__						,generator=lowerCamelCase__						,gen_kwargs=lowerCamelCase__						,**lowerCamelCase__						,)






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Union[str, Any]       )     ->		Optional[Any]:




           '''simple docstring'''


           if self.streaming:
                 SCREAMING_SNAKE_CASE		=						self.builder.as_streaming_dataset(split="""train"""       )
           # Build regular (map-style) dataset
           else:
                 SCREAMING_SNAKE_CASE		=						None
                 SCREAMING_SNAKE_CASE		=						None
                 SCREAMING_SNAKE_CASE		=						None
                 SCREAMING_SNAKE_CASE		=						None

                 self.builder.download_and_prepare(
                     download_config=lowerCamelCase__						,download_mode=lowerCamelCase__						,verification_mode=lowerCamelCase__						,base_path=lowerCamelCase__						,num_proc=self.num_proc						,)
                 SCREAMING_SNAKE_CASE		=						self.builder.as_dataset(
                     split="""train"""						,verification_mode=lowerCamelCase__						,in_memory=self.keep_in_memory       )
           return dataset


