


'''simple docstring'''






from math import factorial

__A						:						List[Any]  =  {str(digit): factorial(digit) for digit in range(10)}





def   UpperCAmelCase   (		lowerCamelCase_	:int			):







		'''simple docstring'''

		if not isinstance(lowercase_					,   lowercase_			):
				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(lowercase_			)			)





def   UpperCAmelCase   (		lowerCamelCase_	:Union[str, Any] = 60					,   lowerCamelCase_	:List[Any] = 1_00_00_00			):







		'''simple docstring'''

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

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

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

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

				snake_case_		:				Dict      							=    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 torch import nn

from transformers import MBartConfig, MBartForConditionalGeneration




def        lowercase__     (       lowercase_      )       ->		Tuple:




      """simple docstring"""

      _UpperCamelCase   :						Optional[int]    =							[
          "encoder.version",
          "decoder.version",
          "model.encoder.version",
          "model.decoder.version",
          "_float_tensor",
          "decoder.output_projection.weight",
      ]
      for k in ignore_keys:
            state_dict.pop(lowercase_		,lowercase_      )




def        lowercase__     (       lowercase_      )       ->		List[Any]:




      """simple docstring"""

      _UpperCamelCase,	_UpperCamelCase   :						Union[str, Any]    =							emb.weight.shape
      _UpperCamelCase   :						str    =							nn.Linear(lowercase_		,lowercase_		,bias=lowercase_      )
      _UpperCamelCase   :						List[Any]    =							emb.weight.data
      return lin_layer




def        lowercase__     (       lowercase_		,lowercase_="facebook/mbart-large-en-ro"		,lowercase_=False		,lowercase_=False      )       ->		List[str]:




      """simple docstring"""

      _UpperCamelCase   :						int    =							torch.load(lowercase_		,map_location="cpu"      )["model"]
      remove_ignore_keys_(lowercase_      )
      _UpperCamelCase   :						str    =							state_dict["encoder.embed_tokens.weight"].shape[0]

      _UpperCamelCase   :						int    =							MBartConfig.from_pretrained(lowercase_		,vocab_size=lowercase_      )
      if mbart_aa and finetuned:
            _UpperCamelCase   :						Union[str, Any]    =							"relu"

      _UpperCamelCase   :						Optional[int]    =							state_dict["decoder.embed_tokens.weight"]
      _UpperCamelCase   :						List[str]    =							MBartForConditionalGeneration(lowercase_      )
      model.model.load_state_dict(lowercase_      )

      if finetuned:
            _UpperCamelCase   :						Optional[Any]    =							make_linear_from_emb(model.model.shared      )

      return model


if __name__ == "__main__":
  lowerCamelCase__						= argparse.ArgumentParser()
  # Required parameters
  parser.add_argument(
      "fairseq_path", type=str, help="bart.large, bart.large.cnn or a path to a model.pt on local filesystem."
  )
  parser.add_argument("pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model.")
  parser.add_argument(
      "--hf_config",
      default="facebook/mbart-large-cc25",
      type=str,
      help="Which huggingface architecture to use: mbart-large",
  )
  parser.add_argument("--mbart_50", action="store_true", help="whether the model is mMART-50 checkpoint")
  parser.add_argument("--finetuned", action="store_true", help="whether the model is a fine-tuned checkpoint")
  lowerCamelCase__						= parser.parse_args()
  lowerCamelCase__						= convert_fairseq_mbart_checkpoint_from_disk(
      args.fairseq_path, hf_config_path=args.hf_config, finetuned=args.finetuned, mbart_aa=args.mbart_aa
  )
  model.save_pretrained(args.pytorch_dump_folder_path)
