





"""simple docstring"""





import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar




class 							snake_case							(			unittest.TestCase ):

      '''simple docstring'''



      def       A_					(							self       :      Optional[int] ):


        '''simple docstring'''




        __UpperCAmelCase    :						int       =						logging.get_logger()

        # the current default level is logging.WARNING
        __UpperCAmelCase    :						Tuple       =						logging.get_verbosity()

        logging.set_verbosity_error()
        self.assertEqual(logger.getEffectiveLevel()						,				logging.get_verbosity() )

        logging.set_verbosity_warning()
        self.assertEqual(logger.getEffectiveLevel()						,				logging.get_verbosity() )

        logging.set_verbosity_info()
        self.assertEqual(logger.getEffectiveLevel()						,				logging.get_verbosity() )

        logging.set_verbosity_debug()
        self.assertEqual(logger.getEffectiveLevel()						,				logging.get_verbosity() )

        # restore to the original level
        logging.set_verbosity(__lowercase )

      def       A_					(							self       :      Any ):


        '''simple docstring'''




        __UpperCAmelCase    :						Union[str, Any]       =						logging.get_verbosity()

        __UpperCAmelCase    :						Union[str, Any]       =						logging.get_logger('''transformers.models.bart.tokenization_bart''' )
        __UpperCAmelCase    :						Union[str, Any]       =						'''Testing 1, 2, 3'''

        # should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
        if level_origin <= logging.WARNING:
          with CaptureLogger(__lowercase ) as cl:
            logger.warning(__lowercase )
          self.assertEqual(cl.out						,				msg + '''\n''' )

        # this is setting the level for all of `transformers.*` loggers
        logging.set_verbosity_error()

        # should not be able to log warnings
        with CaptureLogger(__lowercase ) as cl:
          logger.warning(__lowercase )
        self.assertEqual(cl.out						,				'''''' )

        # should be able to log warnings again
        logging.set_verbosity_warning()
        with CaptureLogger(__lowercase ) as cl:
          logger.warning(__lowercase )
        self.assertEqual(cl.out						,				msg + '''\n''' )

        # restore to the original level
        logging.set_verbosity(__lowercase )

      @mockenv(TRANSFORMERS_VERBOSITY='''error''' )
      def       A_					(							self       :      Optional[Any] ):


        '''simple docstring'''




        transformers.utils.logging._reset_library_root_logger()
        # this action activates the env var
        __UpperCAmelCase    :						str       =						logging.get_logger('''transformers.models.bart.tokenization_bart''' )

        __UpperCAmelCase    :						str       =						os.getenv('''TRANSFORMERS_VERBOSITY'''						,				__lowercase )
        __UpperCAmelCase    :						List[Any]       =						logging.log_levels[env_level_str]

        __UpperCAmelCase    :						Union[str, Any]       =						logging.get_verbosity()
        self.assertEqual(
            __lowercase						,				__lowercase						,				f'''TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'''						,				)

        # restore to the original level
        __UpperCAmelCase    :						int       =						''''''
        transformers.utils.logging._reset_library_root_logger()

      @mockenv(TRANSFORMERS_VERBOSITY='''super-error''' )
      def       A_					(							self       :      List[Any] ):


        '''simple docstring'''




        transformers.utils.logging._reset_library_root_logger()
        __UpperCAmelCase    :						Any       =						logging.logging.getLogger()
        with CaptureLogger(__lowercase ) as cl:
          # this action activates the env var
          logging.get_logger('''transformers.models.bart.tokenization_bart''' )
        self.assertIn('''Unknown option TRANSFORMERS_VERBOSITY=super-error'''						,				cl.out )

        # no need to restore as nothing was changed







      def       A_					(							self       :      Optional[int] ):


        '''simple docstring'''




        transformers.utils.logging._reset_library_root_logger()

        __UpperCAmelCase    :						Any       =						logging.get_logger('''transformers.models.bart.tokenization_bart''' )
        __UpperCAmelCase    :						Optional[Any]       =						'''Testing 1, 2, 3'''

        with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='''1''' ):
          # nothing should be logged as env var disables this method
          with CaptureLogger(__lowercase ) as cl:
            logger.warning_advice(__lowercase )
          self.assertEqual(cl.out						,				'''''' )

        with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='''''' ):
          # should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
          with CaptureLogger(__lowercase ) as cl:
            logger.warning_advice(__lowercase )
          self.assertEqual(cl.out						,				msg + '''\n''' )


def       lowerCamelCase_       (   )						->Dict:





  """simple docstring"""


  disable_progress_bar()
  assert are_progress_bars_disabled()

  enable_progress_bar()
  assert not are_progress_bars_disabled()






"""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)