






import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


snake_case     					=		threading.Lock()
snake_case     					=		None

snake_case     					=		{
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

snake_case     					=		logging.WARNING

snake_case     					=		True


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   List[Any]						    =     os.getenv("TRANSFORMERS_VERBOSITY"    ,  _UpperCamelCase					)
  if env_level_str:
    if env_level_str in log_levels:
      return log_levels[env_level_str]
    else:
      logging.getLogger().warning(
          F'''Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '''
          F'''has to be one of: { ', '.join(log_levels.keys()					) }'''					)
  return _default_log_level


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return __name__.split("."					)[0]


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return logging.getLogger(_get_library_name()					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  global _default_handler

  with _lock:
    if _default_handler:
      # This library has already configured the library root logger.
      return
    SCREAMING_SNAKE_CASE							:   int						    =     logging.StreamHandler()  # Set sys.stderr as stream.
    SCREAMING_SNAKE_CASE							:   Dict						    =     sys.stderr.flush

    # Apply our default configuration to the library root logger.
    SCREAMING_SNAKE_CASE							:   Dict						    =     _get_library_root_logger()
    library_root_logger.addHandler(_default_handler					)
    library_root_logger.setLevel(_get_default_logging_level()					)
    SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     False


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  global _default_handler

  with _lock:
    if not _default_handler:
      return

    SCREAMING_SNAKE_CASE							:   Tuple						    =     _get_library_root_logger()
    library_root_logger.removeHandler(_default_handler					)
    library_root_logger.setLevel(logging.NOTSET					)
    SCREAMING_SNAKE_CASE							:   Dict						    =     None


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return log_levels


def 	lowerCamelCase__      (  lowercase = None					):

  """simple docstring"""






  if name is None:
    SCREAMING_SNAKE_CASE							:   Tuple						    =     _get_library_name()

  _configure_library_root_logger()
  return logging.getLogger(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  _configure_library_root_logger()
  return _get_library_root_logger().getEffectiveLevel()


def 	lowerCamelCase__      (  lowercase					):

  """simple docstring"""






  _configure_library_root_logger()
  _get_library_root_logger().setLevel(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return set_verbosity(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return set_verbosity(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return set_verbosity(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  return set_verbosity(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().removeHandler(_default_handler					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().addHandler(_default_handler					)


def 	lowerCamelCase__      (  lowercase					):

  """simple docstring"""






  _configure_library_root_logger()

  assert handler is not None
  _get_library_root_logger().addHandler(_UpperCamelCase					)


def 	lowerCamelCase__      (  lowercase					):

  """simple docstring"""






  _configure_library_root_logger()

  assert handler is not None and handler not in _get_library_root_logger().handlers
  _get_library_root_logger().removeHandler(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  _configure_library_root_logger()
  SCREAMING_SNAKE_CASE							:   str						    =     False


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  _configure_library_root_logger()
  SCREAMING_SNAKE_CASE							:   List[str]						    =     True


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   Any						    =     _get_library_root_logger().handlers

  for handler in handlers:
    SCREAMING_SNAKE_CASE							:   int						    =     logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"					)
    handler.setFormatter(_UpperCamelCase					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   List[str]						    =     _get_library_root_logger().handlers

  for handler in handlers:
    handler.setFormatter(_UpperCamelCase					)


def 	lowerCamelCase__      (  self    ,  *lowercase    ,  **lowercase					):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   Any						    =     os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"    ,  _UpperCamelCase					)
  if no_advisory_warnings:
    return
  self.warning(*_UpperCamelCase    ,  **_UpperCamelCase					)


snake_case     					=		warning_advice


@functools.lru_cache(_UpperCamelCase					)
def 	lowerCamelCase__      (  self    ,  *lowercase    ,  **lowercase					):

  """simple docstring"""






  self.warning(*_UpperCamelCase    ,  **_UpperCamelCase					)


snake_case     					=		warning_once


class 			SCREAMING_SNAKE_CASE      :
     '''simple docstring'''


     def __init__(					self							:						Dict       ,			*UpperCAmelCase_							:						List[str]       ,			**UpperCAmelCase_							:						Union[str, Any]   ):  # pylint: disable=unused-argument
       SCREAMING_SNAKE_CASE							:   Tuple						    =     args[0] if args else None


     def __iter__(					self							:						List[str]   ):
       return iter(self._iterator   )


     def __getattr__(					self							:						List[Any]       ,			UpperCAmelCase_							:						Dict   ):




       def empty_fn(*UpperCAmelCase_							:						Optional[int]       ,			**UpperCAmelCase_							:						Union[str, Any]   ):  # pylint: disable=unused-argument
         return

       return empty_fn


     def __enter__(					self							:						Optional[int]   ):
       return self






     def __exit__(					self							:						Optional[Any]       ,			UpperCAmelCase_							:						List[str]       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						Union[str, Any]   ):
       return





class 			SCREAMING_SNAKE_CASE      :
     '''simple docstring'''


     def __call__(					self							:						Optional[int]       ,			*UpperCAmelCase_							:						Union[str, Any]       ,			**UpperCAmelCase_							:						Tuple   ):




       if _tqdm_active:
         return tqdm_lib.tqdm(*A_       ,			**A_   )
       else:
         return EmptyTqdm(*A_       ,			**A_   )


     def 					_A							(					self							:						Union[str, Any]       ,			*UpperCAmelCase_							:						Optional[Any]       ,			**UpperCAmelCase_							:						int   ):
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     None
       if _tqdm_active:
         return tqdm_lib.tqdm.set_lock(*A_       ,			**A_   )






     def 					_A							(					self							:						Optional[int]   ):




       if _tqdm_active:
         return tqdm_lib.tqdm.get_lock()





snake_case     					=		_tqdm_cls()


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  global _tqdm_active
  return bool(_tqdm_active					)


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  global _tqdm_active
  SCREAMING_SNAKE_CASE							:   str						    =     True
  hf_hub_utils.enable_progress_bars()


def 	lowerCamelCase__      (  ):

  """simple docstring"""






  global _tqdm_active
  SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     False
  hf_hub_utils.disable_progress_bars()








"""simple docstring"""




import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()




def 			_lowerCAmelCase		(		_UpperCamelCase			,					_UpperCamelCase			,					_UpperCamelCase			,					_UpperCamelCase    ):






  """simple docstring"""



  _lowercase:      int   			=  BigBirdConfig.from_json_file(_UpperCamelCase    )
  print(f'''Building PyTorch model from configuration: {config}'''    )

  if is_trivia_qa:
    _lowercase:      Union[str, Any]   			=  BigBirdForQuestionAnswering(_UpperCamelCase    )
  else:
    _lowercase:      Dict   			=  BigBirdForPreTraining(_UpperCamelCase    )

  # Load weights from tf checkpoint
  load_tf_weights_in_big_bird(_UpperCamelCase			,					_UpperCamelCase			,					is_trivia_qa=_UpperCamelCase    )

  # Save pytorch-model
  print(f'''Save PyTorch model to {pytorch_dump_path}'''    )
  model.save_pretrained(_UpperCamelCase    )


if __name__ == "__main__":
  A__ :       List[Any]				= 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(
      '--big_bird_config_file',
      default=None,
      type=str,
      required=True,
      help=(
          'The config json file corresponding to the pre-trained BERT model. \n'
          'This 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(
      '--is_trivia_qa', action='store_true', help='Whether to convert a model with a trivia_qa head.'
  )
  A__ :       Optional[Any]				= parser.parse_args()
  convert_tf_checkpoint_to_pytorch(
      args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
  )
