





"""simple docstring"""





import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin




class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      _A     :       List[str]         =       'MCTCTFeatureExtractor'
      _A     :       Union[str, Any]         =       'AutoTokenizer'

      def __init__(							self       :      List[Any]						,				__lowercase       :      Union[str, Any]						,				__lowercase       :      Tuple ):


        '''simple docstring'''




        super().__init__(__lowercase						,				__lowercase )
        __UpperCAmelCase    :						List[str]       =						self.feature_extractor
        __UpperCAmelCase    :						Tuple       =						False

      def __call__(							self       :      List[Any]						,				*__lowercase       :      Any						,				**__lowercase       :      int ):


        '''simple docstring'''




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

        if "raw_speech" in kwargs:
          warnings.warn('''Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.''' )
          __UpperCAmelCase    :						Tuple       =						kwargs.pop('''raw_speech''' )
        else:
          __UpperCAmelCase    :						Tuple       =						kwargs.pop('''audio'''						,				__lowercase )
        __UpperCAmelCase    :						List[Any]       =						kwargs.pop('''sampling_rate'''						,				__lowercase )
        __UpperCAmelCase    :						Union[str, Any]       =						kwargs.pop('''text'''						,				__lowercase )
        if len(__lowercase ) > 0:
          __UpperCAmelCase    :						Optional[int]       =						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    :						str       =						self.feature_extractor(__lowercase						,				*__lowercase						,				sampling_rate=__lowercase						,				**__lowercase )
        if text is not None:
          __UpperCAmelCase    :						Dict       =						self.tokenizer(__lowercase						,				**__lowercase )

        if text is None:
          return inputs
        elif audio is None:
          return encodings
        else:
          __UpperCAmelCase    :						Optional[Any]       =						encodings['''input_ids''']
          return inputs

      def       A_					(							self       :      List[str]						,				*__lowercase       :      int						,				**__lowercase       :      Optional[int] ):


        '''simple docstring'''




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

      def       A_					(							self       :      str						,				*__lowercase       :      List[str]						,				**__lowercase       :      List[Any] ):


        '''simple docstring'''




        if self._in_target_context_manager:
          return self.current_processor.pad(*__lowercase						,				**__lowercase )

        __UpperCAmelCase    :						Any       =						kwargs.pop('''input_features'''						,				__lowercase )
        __UpperCAmelCase    :						Optional[Any]       =						kwargs.pop('''labels'''						,				__lowercase )
        if len(__lowercase ) > 0:
          __UpperCAmelCase    :						Optional[Any]       =						args[0]
          __UpperCAmelCase    :						Any       =						args[1:]

        if input_features is not None:
          __UpperCAmelCase    :						List[Any]       =						self.feature_extractor.pad(__lowercase						,				*__lowercase						,				**__lowercase )
        if labels is not None:
          __UpperCAmelCase    :						Optional[Any]       =						self.tokenizer.pad(__lowercase						,				**__lowercase )

        if labels is None:
          return input_features
        elif input_features is None:
          return labels
        else:
          __UpperCAmelCase    :						Dict       =						labels['''input_ids''']
          return input_features

      def       A_					(							self       :      int						,				*__lowercase       :      List[Any]						,				**__lowercase       :      Union[str, Any] ):


        '''simple docstring'''




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







      @contextmanager
      def       A_					(							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    :						Dict       =						True
        __UpperCAmelCase    :						Tuple       =						self.tokenizer
        yield
        __UpperCAmelCase    :						Optional[int]       =						self.feature_extractor
        __UpperCAmelCase    :						Tuple       =						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       lowerCamelCase_       (   UpperCAmelCase_  ,			UpperCAmelCase_  ,			UpperCAmelCase_  )						->Optional[int]:





  """simple docstring"""


  __UpperCAmelCase    :						Dict       =						LxmertConfig.from_json_file(UpperCAmelCase_  )
  print(f'''Building PyTorch model from configuration: {config}'''  )
  __UpperCAmelCase    :						Tuple       =						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__":
  lowercase__				:Optional[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.'
  )
  lowercase__				:Union[str, Any]				   =       parser.parse_args()
  convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)