"""simple docstring"""






from math import factorial

__A			   = {str(digit): factorial(digit) for digit in range(1_0)}



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase )  ->  int:
   if not isinstance(__UpperCAmelCase       ,    __UpperCAmelCase ):
      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(__UpperCAmelCase ) )



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase = 6_0       ,    __UpperCAmelCase = 1_0_0_0_0_0_0 )  ->  int:

   if not isinstance(__UpperCAmelCase       ,    __UpperCAmelCase ) or not isinstance(__UpperCAmelCase       ,    __UpperCAmelCase ):
      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
   lowercase__:   Tuple					=      0
   # the cached sizes of the previous chains
   lowercase__:   dict[int, int]					=      {}

   for start_chain_element in range(1       ,    __UpperCAmelCase ):
      # The temporary set will contain the elements of the chain
      lowercase__:   Union[str, Any]					=      set()
      lowercase__:   str					=      0

      # Stop computing the chain when you find a cached size, a repeating item or the
      # length is greater then the desired one.
      lowercase__:   Any					=      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(__UpperCAmelCase )
         chain_set_length += 1
         lowercase__:   Any					=      digit_factorial_sum(__UpperCAmelCase )

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

      lowercase__:   Optional[int]					=      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()}''')

"""simple docstring"""






import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  List[Any]:
   # Initialise PyTorch model
   lowercase__:   Optional[Any]					=      FunnelConfig.from_json_file(__UpperCAmelCase )
   print(F"""Building PyTorch model from configuration: {config}""" )
   lowercase__:   List[Any]					=      FunnelBaseModel(__UpperCAmelCase ) if base_model else FunnelModel(__UpperCAmelCase )

   # Load weights from tf checkpoint
   load_tf_weights_in_funnel(__UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )

   # Save pytorch-model
   print(F"""Save PyTorch model to {pytorch_dump_path}""" )
   torch.save(model.state_dict()       ,    __UpperCAmelCase )


if __name__ == "__main__":
       __A			   = 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."
       )
       parser.add_argument(
           "--base_model", action="store_true", help="Whether you want just the base model (no decoder) or not."
       )
       __A			   = parser.parse_args()
       convert_tf_checkpoint_to_pytorch(
           args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
       )
