
"""simple docstring"""






from argparse import ArgumentParser, Namespace

from ..utils import logging
from . import BaseTransformersCLICommand






def 						_snake_case       (	lowercase__		:  Namespace		)  ->				Optional[int]:


			'''simple docstring'''





			return ConvertCommand(
			    args.model_type      ,     args.tf_checkpoint      ,     args.pytorch_dump_output      ,     args.config      ,     args.finetuning_task_name		)


__UpperCAmelCase       =  '\ntransformers can only be used from the commandline to convert TensorFlow models in PyTorch, In that case, it requires\nTensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.\n'




class 			_SCREAMING_SNAKE_CASE					(			A__							):






			@staticmethod
			def  __lowerCAmelCase (					__A       )			->     List[str]:
						lowerCAmelCase_    :Dict			     =  parser.add_parser(
						    """convert"""       ,   help="""CLI tool to run convert model from original author checkpoints to Transformers PyTorch checkpoints."""       ,   )
						train_parser.add_argument("""--model_type"""       ,   type=__UpperCAmelCase       ,   required=__UpperCAmelCase       ,   help="""Model\'s type."""       )
						train_parser.add_argument(
						    """--tf_checkpoint"""       ,   type=__UpperCAmelCase       ,   required=__UpperCAmelCase       ,   help="""TensorFlow checkpoint path or folder."""       )
						train_parser.add_argument(
						    """--pytorch_dump_output"""       ,   type=__UpperCAmelCase       ,   required=__UpperCAmelCase       ,   help="""Path to the PyTorch saved model output."""       )
						train_parser.add_argument("""--config"""       ,   type=__UpperCAmelCase       ,   default=""""""       ,   help="""Configuration file path or folder."""       )
						train_parser.add_argument(
						    """--finetuning_task_name"""       ,   type=__UpperCAmelCase       ,   default=__UpperCAmelCase       ,   help="""Optional fine-tuning task name if the TF model was a finetuned model."""       ,   )
						train_parser.set_defaults(func=__UpperCAmelCase       )






			def __init__(					self       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   *__A       ,   )			->     Optional[Any]:
						lowerCAmelCase_    :Tuple			     =  logging.get_logger("""transformers-cli/converting"""       )

						self._logger.info(f"""Loading model {model_type}"""       )
						lowerCAmelCase_    :int			     =  model_type
						lowerCAmelCase_    :Dict			     =  tf_checkpoint
						lowerCAmelCase_    :str			     =  pytorch_dump_output
						lowerCAmelCase_    :Dict			     =  config
						lowerCAmelCase_    :Any			     =  finetuning_task_name






			def  __lowerCAmelCase (					self       )			->     Optional[Any]:


						if self._model_type == "albert":
									try:
												from ..models.albert.convert_albert_original_tf_checkpoint_to_pytorch import (
												    convert_tf_checkpoint_to_pytorch,
												)
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						elif self._model_type == "bert":
									try:
												from ..models.bert.convert_bert_original_tf_checkpoint_to_pytorch import (
												    convert_tf_checkpoint_to_pytorch,
												)
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						elif self._model_type == "funnel":
									try:
												from ..models.funnel.convert_funnel_original_tf_checkpoint_to_pytorch import (
												    convert_tf_checkpoint_to_pytorch,
												)
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						elif self._model_type == "t5":
									try:
												from ..models.ta.convert_ta_original_tf_checkpoint_to_pytorch import convert_tf_checkpoint_to_pytorch
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						elif self._model_type == "gpt":
									from ..models.openai.convert_openai_original_tf_checkpoint_to_pytorch import (
									    convert_openai_checkpoint_to_pytorch,
									)

									convert_openai_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						elif self._model_type == "transfo_xl":
									try:
												from ..models.transfo_xl.convert_transfo_xl_original_tf_checkpoint_to_pytorch import (
												    convert_transfo_xl_checkpoint_to_pytorch,
												)
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									if "ckpt" in self._tf_checkpoint.lower():
												lowerCAmelCase_    :Optional[int]			     =  self._tf_checkpoint
												lowerCAmelCase_    :List[Any]			     =  """"""
									else:
												lowerCAmelCase_    :Dict			     =  self._tf_checkpoint
												lowerCAmelCase_    :Union[str, Any]			     =  """"""
									convert_transfo_xl_checkpoint_to_pytorch(
									    __UpperCAmelCase       ,   self._config       ,   self._pytorch_dump_output       ,   __UpperCAmelCase       )
						elif self._model_type == "gpt2":
									try:
												from ..models.gpta.convert_gpta_original_tf_checkpoint_to_pytorch import (
												    convert_gpta_checkpoint_to_pytorch,
												)
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									convert_gpta_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						elif self._model_type == "xlnet":
									try:
												from ..models.xlnet.convert_xlnet_original_tf_checkpoint_to_pytorch import (
												    convert_xlnet_checkpoint_to_pytorch,
												)
									except ImportError:
												raise ImportError(__UpperCAmelCase       )

									convert_xlnet_checkpoint_to_pytorch(
									    self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       ,   self._finetuning_task_name       )
						elif self._model_type == "xlm":
									from ..models.xlm.convert_xlm_original_pytorch_checkpoint_to_pytorch import (
									    convert_xlm_checkpoint_to_pytorch,
									)

									convert_xlm_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._pytorch_dump_output       )
						elif self._model_type == "lxmert":
									from ..models.lxmert.convert_lxmert_original_tf_checkpoint_to_pytorch import (
									    convert_lxmert_checkpoint_to_pytorch,
									)

									convert_lxmert_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._pytorch_dump_output       )
						elif self._model_type == "rembert":
									from ..models.rembert.convert_rembert_tf_checkpoint_to_pytorch import (
									    convert_rembert_tf_checkpoint_to_pytorch,
									)

									convert_rembert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       )
						else:
									raise ValueError(
									    """--model_type should be selected in the list [bert, gpt, gpt2, t5, transfo_xl, xlnet, xlm, lxmert]"""       )














from math import factorial

UpperCAmelCase__				   =		{str(digit): factorial(digit) for digit in range(10)}
def 						_a    (      a :int )							->			int:
 if not isinstance(a	,							a ):
  raise TypeError('''Parameter number must be int''' )

 if number < 0:
  raise ValueError('''Parameter number must be greater than or equal to 0''' )

 # Converts number in string to iterate on its digits and adds its factorial.
 return sum(DIGIT_FACTORIAL[digit] for digit in str(a ) )
def 						_a    (      a :int = 60	,							a :int = 1_000_000 )							->			int:

 if not isinstance(a	,							a ) or not isinstance(a	,							a ):
  raise TypeError('''Parameters chain_length and number_limit must be int''' )

 if chain_length <= 0 or number_limit <= 0:
  raise ValueError(
      '''Parameters chain_length and number_limit must be greater than 0''' )

 # the counter for the chains with the exact desired length
 a		  =      0
 # the cached sizes of the previous chains
 a		  =      {}

 for start_chain_element in range(1	,							a ):
  # The temporary set will contain the elements of the chain
  a		  =      set()
  a		  =      0

  # Stop computing the chain when you find a cached size, a repeating item or the
  # length is greater then the desired one.
  a		  =      start_chain_element
  while (
      chain_element not in chain_sets_lengths
      and chain_element not in chain_set
      and chain_set_length <= chain_length
  ):
   chain_set.add(a )
   chain_set_length += 1
   a		  =      digit_factorial_sum(a )

  if chain_element in chain_sets_lengths:
   chain_set_length += chain_sets_lengths[chain_element]

  a		  =      chain_set_length

  # If chain contains the exact amount of elements increase the counter
  if chain_set_length == chain_length:
   chains_counter += 1

 return chains_counter


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(f"""{solution()}""")


