


"""simple docstring"""






import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType




class 							A_      (       _a ):
  lowerCAmelCase__      			=	['image_processor', 'tokenizer']
  lowerCAmelCase__      			=	'ViltImageProcessor'
  lowerCAmelCase__      			=	('BertTokenizer', 'BertTokenizerFast')


  def __init__(			self:						Union[str, Any]							,__lowerCAmelCase:						Dict=None							,__lowerCAmelCase:						str=None							,**__lowerCAmelCase:						Optional[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				str							=     None
     if "feature_extractor" in kwargs:
        warnings.warn(
            "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
            " instead."							,__lowerCAmelCase							,)
        _lowerCamelCase   :				Optional[Any]							=     kwargs.pop("feature_extractor"    )

     _lowerCamelCase   :				Any							=     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__(__lowerCAmelCase							,__lowerCAmelCase    )
     _lowerCamelCase   :				Optional[Any]							=     self.image_processor


  def __call__(			self:						str							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None							,__lowerCAmelCase:						bool = True							,__lowerCAmelCase:						Union[bool, str, PaddingStrategy] = False							,__lowerCAmelCase:						Union[bool, str, TruncationStrategy] = None							,__lowerCAmelCase:						Optional[int] = None							,__lowerCAmelCase:						int = 0							,__lowerCAmelCase:						Optional[int] = None							,__lowerCAmelCase:						Optional[bool] = None							,__lowerCAmelCase:						Optional[bool] = None							,__lowerCAmelCase:						bool = False							,__lowerCAmelCase:						bool = False							,__lowerCAmelCase:						bool = False							,__lowerCAmelCase:						bool = False							,__lowerCAmelCase:						bool = True							,__lowerCAmelCase:						Optional[Union[str, TensorType]] = None							,**__lowerCAmelCase:						int							,):







     '''simple docstring'''







     _lowerCamelCase   :				Union[str, Any]							=     self.tokenizer(
         text=__lowerCAmelCase							,add_special_tokens=__lowerCAmelCase							,padding=__lowerCAmelCase							,truncation=__lowerCAmelCase							,max_length=__lowerCAmelCase							,stride=__lowerCAmelCase							,pad_to_multiple_of=__lowerCAmelCase							,return_token_type_ids=__lowerCAmelCase							,return_attention_mask=__lowerCAmelCase							,return_overflowing_tokens=__lowerCAmelCase							,return_special_tokens_mask=__lowerCAmelCase							,return_offsets_mapping=__lowerCAmelCase							,return_length=__lowerCAmelCase							,verbose=__lowerCAmelCase							,return_tensors=__lowerCAmelCase							,**__lowerCAmelCase							,)
     # add pixel_values + pixel_mask
     _lowerCamelCase   :				int							=     self.image_processor(__lowerCAmelCase							,return_tensors=__lowerCAmelCase    )
     encoding.update(__lowerCAmelCase    )

     return encoding


  def 							_lowercase					(			self:						Any							,*__lowerCAmelCase:						str							,**__lowerCAmelCase:						int    ):







     '''simple docstring'''







     return self.tokenizer.batch_decode(*__lowerCAmelCase							,**__lowerCAmelCase    )


  def 							_lowercase					(			self:						Dict							,*__lowerCAmelCase:						int							,**__lowerCAmelCase:						List[str]    ):







     '''simple docstring'''







     return self.tokenizer.decode(*__lowerCAmelCase							,**__lowerCAmelCase    )


  @property
  def 							_lowercase					(			self:						Tuple    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[int]							=     self.tokenizer.model_input_names
     _lowerCamelCase   :				int							=     self.image_processor.model_input_names
     return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names    )    )


  @property
  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     warnings.warn(
         "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."							,__lowerCAmelCase							,)
     return self.image_processor_class






  @property
  def 							_lowercase					(			self:						str    ):







     '''simple docstring'''







     warnings.warn(
         "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."							,__lowerCAmelCase							,)
     return self.image_processor





'''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(							SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_     )		->		str:
			# Construct model
			if openai_config_file == "":
						A_									= OpenAIGPTConfig()
			else:
						A_									= OpenAIGPTConfig.from_json_file(SCREAMING_SNAKE_CASE_     )
			A_									= 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
			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()       ,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
							)




