'''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__			(			a__			,      a__			,      a__      ):


						'''simple docstring'''






						if openai_config_file == "":
												_lowerCAmelCase										=OpenAIGPTConfig()
						else:
												_lowerCAmelCase										=OpenAIGPTConfig.from_json_file(a__      )
						_lowerCAmelCase										=OpenAIGPTModel(a__      )

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

						# 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()			,      a__      )
						print(F'''Save configuration file to {pytorch_config_dump_path}'''      )
						with open(a__			,      'w'			,      encoding='utf-8'      ) as f:
												f.write(config.to_json_string()      )


if __name__ == "__main__":
							lowercase_     		= 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_     		= parser.parse_args()
							convert_openai_checkpoint_to_pytorch(
							    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
							)






'''simple docstring'''

import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
class   SCREAMING_SNAKE_CASE			(						__lowercase):







		"""simple docstring"""
		lowercase   :      Any       =							['image_processor', 'tokenizer']
		lowercase   :      Any       =							'CLIPImageProcessor'
		lowercase   :      int       =							('CLIPTokenizer', 'CLIPTokenizerFast')






		def __init__(   self		,						__A=None		,						__A=None		,						**__A				) ->     str:
								_lowerCAmelCase										=None
								if "feature_extractor" in kwargs:
														warnings.warn(
														    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
														    ' instead.'		,						__A		,						)
														_lowerCAmelCase										=kwargs.pop('feature_extractor'				)

								_lowerCAmelCase										=image_processor if image_processor is not None else feature_extractor
								if image_processor is None:
														raise ValueError('You need to specify an `image_processor`.'				)
								if tokenizer is None:
														raise ValueError('You need to specify a `tokenizer`.'				)

								super().__init__(__A		,						__A				)






		def __call__(   self		,						__A=None		,						__A=None		,						__A=None		,						**__A				) ->     Optional[int]:

								if text is None and images is None:
														raise ValueError('You have to specify either text or images. Both cannot be none.'				)

								if text is not None:
														_lowerCAmelCase										=self.tokenizer(__A		,						return_tensors=__A		,						**__A				)

								if images is not None:
														_lowerCAmelCase										=self.image_processor(__A		,						return_tensors=__A		,						**__A				)

								if text is not None and images is not None:
														_lowerCAmelCase										=image_features.pixel_values
														return encoding
								elif text is not None:
														return encoding
								else:
														return BatchEncoding(data=dict(**__A				)		,						tensor_type=__A				)






		def 		UpperCamelCase__       (   self		,						*__A		,						**__A				) ->     Any:
								return self.tokenizer.batch_decode(*__A		,						**__A				)






		def 		UpperCamelCase__       (   self		,						*__A		,						**__A				) ->     Optional[int]:
								return self.tokenizer.decode(*__A		,						**__A				)






		@property
		def 		UpperCamelCase__       (   self				) ->     Tuple:
								_lowerCAmelCase										=self.tokenizer.model_input_names
								_lowerCAmelCase										=self.image_processor.model_input_names
								return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names				)				)






		@property
		def 		UpperCamelCase__       (   self				) ->     Optional[int]:
								warnings.warn(
								    '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'		,						__A		,						)
								return self.image_processor_class






		@property
		def 		UpperCamelCase__       (   self				) ->     Optional[Any]:
								warnings.warn(
								    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'		,						__A		,						)
								return self.image_processor





