



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


A_		:     Tuple        =     threading.Lock()
A_		:     Optional[logging.Handler]        =     None

A_		:     List[Any]        =     {
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

A_		:     Optional[Any]        =     logging.WARNING

A_		:     List[Any]        =     True


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 a						=		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 	UpperCAmelCase__      (      ):






 '''simple docstring'''

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


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 return logging.getLogger(_get_library_name()					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 global _default_handler

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

  # Apply our default configuration to the library root logger.
  a						=		_get_library_root_logger()
  library_root_logger.addHandler(_default_handler					)
  library_root_logger.setLevel(_get_default_logging_level()					)
  a						=		False


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 global _default_handler

 with _lock:
  if not _default_handler:
   return

  a						=		_get_library_root_logger()
  library_root_logger.removeHandler(_default_handler					)
  library_root_logger.setLevel(logging.NOTSET					)
  a						=		None


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 return log_levels


def 	UpperCAmelCase__      (      UpperCAmelCase__ :Optional[str] = None					):






 '''simple docstring'''

 if name is None:
  a						=		_get_library_name()

 _configure_library_root_logger()
 return logging.getLogger(UpperCAmelCase__					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 _configure_library_root_logger()
 return _get_library_root_logger().getEffectiveLevel()


def 	UpperCAmelCase__      (      UpperCAmelCase__ :int					):






 '''simple docstring'''

 _configure_library_root_logger()
 _get_library_root_logger().setLevel(UpperCAmelCase__					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 return set_verbosity(UpperCAmelCase__					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 return set_verbosity(UpperCAmelCase__					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 return set_verbosity(UpperCAmelCase__					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 return set_verbosity(UpperCAmelCase__					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 _configure_library_root_logger()

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


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 _configure_library_root_logger()

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


def 	UpperCAmelCase__      (      UpperCAmelCase__ :logging.Handler					):






 '''simple docstring'''

 _configure_library_root_logger()

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


def 	UpperCAmelCase__      (      UpperCAmelCase__ :logging.Handler					):






 '''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 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 _configure_library_root_logger()
 a						=		False


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 _configure_library_root_logger()
 a						=		True


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 a						=		_get_library_root_logger().handlers

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


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 a						=		_get_library_root_logger().handlers

 for handler in handlers:
  handler.setFormatter(UpperCAmelCase__					)


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






 '''simple docstring'''

 a						=		os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS" ,					UpperCAmelCase__					)
 if no_advisory_warnings:
  return
 self.warning(*UpperCAmelCase__ ,					**UpperCAmelCase__					)


A_		:     List[str]        =     warning_advice


@functools.lru_cache(UpperCAmelCase__					)
def 	UpperCAmelCase__      (      self :Dict ,					*UpperCAmelCase__ :int ,					**UpperCAmelCase__ :int					):






 '''simple docstring'''

 self.warning(*UpperCAmelCase__ ,					**UpperCAmelCase__					)


A_		:     List[Any]        =     warning_once



class 		_lowercase		:

   def __init__(      self			:       str							,   *__lowerCAmelCase			:       Union[str, Any]							,   **__lowerCAmelCase			:       str							)       ->				Dict:  # pylint: disable=unused-argument


    """simple docstring"""






    a						=		args[0] if args else None

   def __iter__(      self			:       List[Any]							)       ->				Tuple:


    """simple docstring"""






    return iter(self._iterator							)

   def __getattr__(      self			:       Dict							,   __lowerCAmelCase			:       str							)       ->				Optional[Any]:


    """simple docstring"""






    def empty_fn(*__lowerCAmelCase			:       Optional[int]							,   **__lowerCAmelCase			:       Optional[int]							):  # pylint: disable=unused-argument
     return

    return empty_fn

   def __enter__(      self			:       Tuple							)       ->				Optional[int]:


    """simple docstring"""






    return self




   def __exit__(      self			:       Any							,   __lowerCAmelCase			:       Optional[int]							,   __lowerCAmelCase			:       str							,   __lowerCAmelCase			:       List[Any]							)       ->				List[str]:


    """simple docstring"""






    return



class 		_lowercase		:

   def __call__(      self			:       List[Any]							,   *__lowerCAmelCase			:       List[Any]							,   **__lowerCAmelCase			:       Any							)       ->				Optional[int]:


    """simple docstring"""






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

   def 		A							(      self			:       Dict							,   *__lowerCAmelCase			:       Any							,   **__lowerCAmelCase			:       Dict							)       ->				Optional[int]:


    """simple docstring"""






    a						=		None
    if _tqdm_active:
     return tqdm_lib.tqdm.set_lock(*__lowerCAmelCase							,   **__lowerCAmelCase							)




   def 		A							(      self			:       List[Any]							)       ->				Tuple:


    """simple docstring"""






    if _tqdm_active:
     return tqdm_lib.tqdm.get_lock()

A_		:     List[str]        =     _tqdm_cls()


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 global _tqdm_active
 return bool(_tqdm_active					)


def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 global _tqdm_active
 a						=		True
 hf_hub_utils.enable_progress_bars()




def 	UpperCAmelCase__      (      ):






 '''simple docstring'''

 global _tqdm_active
 a						=		False
 hf_hub_utils.disable_progress_bars()






import argparse

from transformers import TaConfig, TaForConditionalGeneration, load_tf_weights_in_ta
from transformers.utils import logging


logging.set_verbosity_info()


def 	UpperCAmelCase__      (      UpperCAmelCase__ :Optional[int] ,					UpperCAmelCase__ :List[str] ,					UpperCAmelCase__ :Any					):






 '''simple docstring'''

 a						=		TaConfig.from_json_file(UpperCAmelCase__					)
 print(F"""Building PyTorch model from configuration: {config}"""					)
 a						=		TaForConditionalGeneration(UpperCAmelCase__					)

 # Load weights from tf checkpoint
 load_tf_weights_in_ta(UpperCAmelCase__ ,					UpperCAmelCase__ ,					UpperCAmelCase__					)

 # Save pytorch-model
 print(F"""Save PyTorch model to {pytorch_dump_path}"""					)
 model.save_pretrained(UpperCAmelCase__					)


if __name__ == "__main__":
     A_		:     Union[str, 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(
         '''--config_file''',
         default=None,
         type=str,
         required=True,
         help=(
             '''The config json file corresponding to the pre-trained T5 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.'''
     )
     A_		:     Tuple        =     parser.parse_args()
     convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)

