



'''simple docstring'''
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class 							lowercase__     (							lowercase       ):
	lowercase__      =      """Speech2TextFeatureExtractor"""
	lowercase__      =      """Speech2TextTokenizer"""





	def __init__(			self :    Any			,lowerCamelCase__ :    Dict			,lowerCamelCase__ :    Optional[Any]			):







							'''simple docstring'''
							super().__init__(_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE			)
							_UpperCamelCase :		str			    =       self.feature_extractor
							_UpperCamelCase :		str			    =       False





	def __call__(			self :    Any			,*lowerCamelCase__ :    Tuple			,**lowerCamelCase__ :    int			):







							'''simple docstring'''





							if self._in_target_context_manager:
													return self.current_processor(*_SCREAMING_SNAKE_CASE			,**_SCREAMING_SNAKE_CASE			)

							if "raw_speech" in kwargs:
													warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'			)
													_UpperCamelCase :		Any			    =       kwargs.pop('raw_speech'			)
							else:
													_UpperCamelCase :		Optional[int]			    =       kwargs.pop('audio'			,_SCREAMING_SNAKE_CASE			)
							_UpperCamelCase :		Optional[int]			    =       kwargs.pop('sampling_rate'			,_SCREAMING_SNAKE_CASE			)
							_UpperCamelCase :		Optional[Any]			    =       kwargs.pop('text'			,_SCREAMING_SNAKE_CASE			)
							if len(_SCREAMING_SNAKE_CASE			) > 0:
													_UpperCamelCase :		List[Any]			    =       args[0]
													_UpperCamelCase :		Tuple			    =       args[1:]

							if audio is None and text is None:
													raise ValueError('You need to specify either an `audio` or `text` input to process.'			)

							if audio is not None:
													_UpperCamelCase :		Tuple			    =       self.feature_extractor(_SCREAMING_SNAKE_CASE			,*_SCREAMING_SNAKE_CASE			,sampling_rate=_SCREAMING_SNAKE_CASE			,**_SCREAMING_SNAKE_CASE			)
							if text is not None:
													_UpperCamelCase :		Optional[Any]			    =       self.tokenizer(_SCREAMING_SNAKE_CASE			,**_SCREAMING_SNAKE_CASE			)

							if text is None:
													return inputs
							elif audio is None:
													return encodings
							else:
													_UpperCamelCase :		str			    =       encodings['''input_ids''']
													return inputs





	def      UpperCamelCase_  (			self :    Union[str, Any]			,*lowerCamelCase__ :    Optional[int]			,**lowerCamelCase__ :    Optional[Any]			):







							'''simple docstring'''
							return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE			,**_SCREAMING_SNAKE_CASE			)





	def      UpperCamelCase_  (			self :    Dict			,*lowerCamelCase__ :    Union[str, Any]			,**lowerCamelCase__ :    Any			):







							'''simple docstring'''
							return self.tokenizer.decode(*_SCREAMING_SNAKE_CASE			,**_SCREAMING_SNAKE_CASE			)





	@contextmanager
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							warnings.warn(
							    '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
							    'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
							    'your audio inputs, or in a separate call.'			)
							_UpperCamelCase :		str			    =       True
							_UpperCamelCase :		List[str]			    =       self.tokenizer
							yield
							_UpperCamelCase :		Optional[int]			    =       self.feature_extractor
							_UpperCamelCase :		int			    =       False





'''simple docstring'''
import argparse

import torch

from transformers import LxmertConfig, LxmertForPreTraining, load_tf_weights_in_lxmert
from transformers.utils import logging


logging.set_verbosity_info()






def A__   (					UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_							):
						# Initialise PyTorch model
						_UpperCamelCase :		Any			    =       LxmertConfig.from_json_file(UpperCAmelCase_							)
						print(f'Building PyTorch model from configuration: {config}'							)
						_UpperCamelCase :		int			    =       LxmertForPreTraining(UpperCAmelCase_							)

						# Load weights from tf checkpoint
						load_tf_weights_in_lxmert(UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_							)

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


if __name__ == "__main__":
					snake_case_			:     int  	=  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.'
					)
					snake_case_			:     List[str]  	=  parser.parse_args()
					convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)


