





import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()






def 					SCREAMING_SNAKE_CASE__				(							UpperCamelCase__:				Tuple       , UpperCamelCase__:				str       , UpperCamelCase__:				int       , UpperCamelCase__:				List[Any]     ):
		# Initialise PyTorch model
		SCREAMING_SNAKE_CASE__								=   FunnelConfig.from_json_file(UpperCamelCase__     )
		print(f'''Building PyTorch model from configuration: {config}'''     )
		SCREAMING_SNAKE_CASE__								=   FunnelBaseModel(UpperCamelCase__     ) if base_model else FunnelModel(UpperCamelCase__     )

		# Load weights from tf checkpoint
		load_tf_weights_in_funnel(UpperCamelCase__       , UpperCamelCase__       , UpperCamelCase__     )

		# Save pytorch-model
		print(f'''Save PyTorch model to {pytorch_dump_path}'''     )
		torch.save(model.state_dict()       , UpperCamelCase__     )


if __name__ == "__main__":
	_lowerCamelCase 					=      argparse.ArgumentParser()
	# Required parameters
	parser.add_argument(
	    '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
	)
	parser.add_argument(
	    '--config_file',
	    default=None,
	    type=str,
	    required=True,
	    help='The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.',
	)
	parser.add_argument(
	    '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
	)
	parser.add_argument(
	    '--base_model', action='store_true', help='Whether you want just the base model (no decoder) or not.'
	)
	_lowerCamelCase 					=      parser.parse_args()
	convert_tf_checkpoint_to_pytorch(
	    args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
	)






from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class 	UpperCamelCase_							(  UpperCamelCase__     ):
							lowerCamelCase_							     =       ["image_processor", "tokenizer"]
							lowerCamelCase_							     =       "AutoImageProcessor"
							lowerCamelCase_							     =       "AutoTokenizer"


							def __init__(				self     :Optional[int]				,					__A     :Optional[Any]				,					__A     :Dict		) -> Dict:



									"""simple docstring"""



									super().__init__(__A				,					__A		)
									SCREAMING_SNAKE_CASE__								=   self.image_processor


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



									"""simple docstring"""



									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:
											SCREAMING_SNAKE_CASE__								=   self.tokenizer(__A				,					return_tensors=__A				,					**__A		)

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

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


							def   _snake_case	(				self     :str				,					*__A     :List[str]				,					**__A     :List[str]		) -> List[Any]:



									"""simple docstring"""



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


							def   _snake_case	(				self     :List[str]				,					*__A     :Any				,					**__A     :Any		) -> Tuple:



									"""simple docstring"""



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


							@property
							def   _snake_case	(				self     :Dict		) -> List[Any]:



									"""simple docstring"""



									return ["input_ids", "attention_mask", "pixel_values"]