




import warnings
from typing import List, Optional, Union

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




class 		UpperCamelCase__	(lowerCAmelCase__     ):

    '''simple docstring'''



    lowerCamelCase_      :	Dict	     =      ["""image_processor""", """tokenizer"""]
    lowerCamelCase_      :	Optional[Any]	     =      """FlavaImageProcessor"""
    lowerCamelCase_      :	Optional[Any]	     =      ("""BertTokenizer""", """BertTokenizerFast""")







    def __init__(    self     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  **UpperCamelCase__     )     ->      List[Any]:
           lowerCamelCase   :      Tuple			 =					None
           if "feature_extractor" in kwargs:
                  warnings.warn(
                      "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
                      " instead."     ,  UpperCamelCase__     ,  )
                  lowerCamelCase   :      Dict			 =					kwargs.pop("feature_extractor"     )

           lowerCamelCase   :      List[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__(UpperCamelCase__     ,  UpperCamelCase__     )
           lowerCamelCase   :      List[Any]			 =					self.image_processor







    def __call__(    self     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = True     ,  UpperCamelCase__ = False     ,  UpperCamelCase__ = False     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = 0     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = None     ,  UpperCamelCase__ = False     ,  UpperCamelCase__ = False     ,  UpperCamelCase__ = False     ,  UpperCamelCase__ = False     ,  UpperCamelCase__ = True     ,  UpperCamelCase__ = None     ,  **UpperCamelCase__     ,  )     ->      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   :      Union[str, Any]			 =					self.tokenizer(
                      text=UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__     ,  padding=UpperCamelCase__     ,  truncation=UpperCamelCase__     ,  max_length=UpperCamelCase__     ,  stride=UpperCamelCase__     ,  pad_to_multiple_of=UpperCamelCase__     ,  return_token_type_ids=UpperCamelCase__     ,  return_attention_mask=UpperCamelCase__     ,  return_overflowing_tokens=UpperCamelCase__     ,  return_special_tokens_mask=UpperCamelCase__     ,  return_offsets_mapping=UpperCamelCase__     ,  return_length=UpperCamelCase__     ,  verbose=UpperCamelCase__     ,  return_tensors=UpperCamelCase__     ,  **UpperCamelCase__     ,  )
           if images is not None:
                  lowerCamelCase   :      str			 =					self.image_processor(
                      UpperCamelCase__     ,  return_image_mask=UpperCamelCase__     ,  return_codebook_pixels=UpperCamelCase__     ,  return_tensors=UpperCamelCase__     ,  **UpperCamelCase__     ,  )

           if text is not None and images is not None:
                  encoding.update(UpperCamelCase__     )
                  return encoding
           elif text is not None:
                  return encoding
           else:
                  return BatchEncoding(data=dict(**UpperCamelCase__     )     ,  tensor_type=UpperCamelCase__     )







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







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







    @property
    def     _lowercase     (    self     )     ->      str:
           lowerCamelCase   :      Tuple			 =					self.tokenizer.model_input_names
           lowerCamelCase   :      Dict			 =					self.image_processor.model_input_names
           return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names     )     )







    @property
    def     _lowercase     (    self     )     ->      Tuple:
           warnings.warn(
               "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."     ,  UpperCamelCase__     ,  )
           return self.image_processor_class







    @property
    def     _lowercase     (    self     )     ->      Any:
           warnings.warn(
               "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."     ,  UpperCamelCase__     ,  )
           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 		lowercase							(     _snake_case						:      List[Any]     ,   _snake_case						:      Tuple     ,   _snake_case						:      int     )     ->List[Any]:
	"""simple docstring"""





	if openai_config_file == "":
		__snake_case	:						Dict						=				OpenAIGPTConfig()
	else:
		__snake_case	:						int						=				OpenAIGPTConfig.from_json_file(_snake_case     )
	__snake_case	:						Tuple						=				OpenAIGPTModel(_snake_case     )

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

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


if __name__ == "__main__":
			SCREAMING_SNAKE_CASE :    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."""
			    ),
			)
			SCREAMING_SNAKE_CASE :    Optional[int]									=				parser.parse_args()
			convert_openai_checkpoint_to_pytorch(
			    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
			)





