




import unittest
from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryDirectory

from transformers import BertConfig, BertTokenizerFast, FeatureExtractionPipeline
from transformers.convert_graph_to_onnx import (
    convert,
    ensure_valid_input,
    generate_identified_filename,
    infer_shapes,
    quantize,
)
from transformers.testing_utils import require_tf, require_tokenizers, require_torch, slow


class        UpperCamelCase_					:

    '''simple docstring'''






    def  SCREAMING_SNAKE_CASE							(    self   :			Any      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Union[str, Any])		->Dict:





           '''simple docstring'''

           return None


class        UpperCamelCase_					:

    '''simple docstring'''






    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Optional[Any])		->Union[str, Any]:





           '''simple docstring'''

           return None


class        UpperCamelCase_					(				unittest.TestCase  ):

    '''simple docstring'''






    UpperCAmelCase__													=   [
        # (model_name, model_kwargs)
        ('''bert-base-cased''', {}),
        ('''gpt2''', {'''use_cache''': False}),  # We don't support exporting GPT2 past keys anymore
    ]


    @require_tf
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Union[str, Any])		->str:





           '''simple docstring'''

           for model, model_kwargs in OnnxExportTestCase.MODEL_TO_TEST:
                  self._test_export(UpperCAmelCase__      ,				'''tf'''      ,				12      ,				**UpperCAmelCase__)


    @require_torch
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->List[str]:





           '''simple docstring'''

           for model, model_kwargs in OnnxExportTestCase.MODEL_TO_TEST:
                  self._test_export(UpperCAmelCase__      ,				'''pt'''      ,				12      ,				**UpperCAmelCase__)


    @require_torch
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any])		->int:





           '''simple docstring'''

           from transformers import BertModel

           A__   				=					['''[UNK]''', '''[SEP]''', '''[CLS]''', '''[PAD]''', '''[MASK]''', '''some''', '''other''', '''words''']
           with NamedTemporaryFile(mode='''w+t''') as vocab_file:
                  vocab_file.write('''\n'''.join(UpperCAmelCase__))
                  vocab_file.flush()
                  A__   				=					BertTokenizerFast(vocab_file.name)

           with TemporaryDirectory() as bert_save_dir:
                  A__   				=					BertModel(BertConfig(vocab_size=len(UpperCAmelCase__)))
                  model.save_pretrained(UpperCAmelCase__)
                  self._test_export(UpperCAmelCase__      ,				'''pt'''      ,				12      ,				UpperCAmelCase__)


    @require_tf
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Union[str, Any]:





           '''simple docstring'''

           for model, model_kwargs in OnnxExportTestCase.MODEL_TO_TEST:
                  A__   				=					self._test_export(UpperCAmelCase__      ,				'''tf'''      ,				12      ,				**UpperCAmelCase__)
                  A__   				=					quantize(Path(UpperCAmelCase__))

                  # Ensure the actual quantized model is not bigger than the original one
                  if quantized_path.stat().st_size >= Path(UpperCAmelCase__).stat().st_size:
                         self.fail('''Quantized model is bigger than initial ONNX model''')


    @require_torch
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->Dict:





           '''simple docstring'''

           for model, model_kwargs in OnnxExportTestCase.MODEL_TO_TEST:
                  A__   				=					self._test_export(UpperCAmelCase__      ,				'''pt'''      ,				12      ,				**UpperCAmelCase__)
                  A__   				=					quantize(UpperCAmelCase__)

                  # Ensure the actual quantized model is not bigger than the original one
                  if quantized_path.stat().st_size >= Path(UpperCAmelCase__).stat().st_size:
                         self.fail('''Quantized model is bigger than initial ONNX model''')


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Dict=None      ,				**UpperCAmelCase__   :			Optional[int])		->Optional[Any]:





           '''simple docstring'''

           try:
                  # Compute path
                  with TemporaryDirectory() as tempdir:
                         A__   				=					Path(UpperCAmelCase__).joinpath('''model.onnx''')

                  # Remove folder if exists
                  if path.parent.exists():
                         path.parent.rmdir()

                  # Export
                  convert(UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				**UpperCAmelCase__)

                  return path
           except Exception as e:
                  self.fail(UpperCAmelCase__)


    @require_torch
    @require_tokenizers
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->List[str]:





           '''simple docstring'''

           from transformers import BertModel

           A__   				=					BertModel(BertConfig.from_pretrained('''lysandre/tiny-bert-random'''))
           A__   				=					BertTokenizerFast.from_pretrained('''lysandre/tiny-bert-random''')
           self._test_infer_dynamic_axis(UpperCAmelCase__      ,				UpperCAmelCase__      ,				'''pt''')


    @require_tf
    @require_tokenizers
    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->List[Any]:





           '''simple docstring'''

           from transformers import TFBertModel

           A__   				=					TFBertModel(BertConfig.from_pretrained('''lysandre/tiny-bert-random'''))
           A__   				=					BertTokenizerFast.from_pretrained('''lysandre/tiny-bert-random''')
           self._test_infer_dynamic_axis(UpperCAmelCase__      ,				UpperCAmelCase__      ,				'''tf''')


    def  SCREAMING_SNAKE_CASE							(    self   :			Any      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			int)		->Any:





           '''simple docstring'''

           A__   				=					FeatureExtractionPipeline(UpperCAmelCase__      ,				UpperCAmelCase__)

           A__   				=					['''input_ids''', '''token_type_ids''', '''attention_mask''', '''output_0''', '''output_1''']
           A__				,							A__				,							A__				,							A__   				=					infer_shapes(UpperCAmelCase__      ,				UpperCAmelCase__)

           # Assert all variables are present
           self.assertEqual(len(UpperCAmelCase__)      ,				len(UpperCAmelCase__))
           self.assertTrue(all(var_name in shapes for var_name in variable_names))
           self.assertSequenceEqual(variable_names[:3]      ,				UpperCAmelCase__)
           self.assertSequenceEqual(variable_names[3:]      ,				UpperCAmelCase__)

           # Assert inputs are {0: batch, 1: sequence}
           for var_name in ["input_ids", "token_type_ids", "attention_mask"]:
                  self.assertDictEqual(shapes[var_name]      ,				{0: '''batch''', 1: '''sequence'''})

           # Assert outputs are {0: batch, 1: sequence} and {0: batch}
           self.assertDictEqual(shapes['''output_0''']      ,				{0: '''batch''', 1: '''sequence'''})
           self.assertDictEqual(shapes['''output_1''']      ,				{0: '''batch'''})


    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Any:





           '''simple docstring'''

           A__   				=					['''input_ids''', '''attention_mask''', '''token_type_ids''']
           A__   				=					{'''input_ids''': [1, 2, 3, 4], '''attention_mask''': [0, 0, 0, 0], '''token_type_ids''': [1, 1, 1, 1]}
           A__				,							A__   				=					ensure_valid_input(FuncContiguousArgs()      ,				UpperCAmelCase__      ,				UpperCAmelCase__)

           # Should have exactly the same number of args (all are valid)
           self.assertEqual(len(UpperCAmelCase__)      ,				3)

           # Should have exactly the same input names
           self.assertEqual(set(UpperCAmelCase__)      ,				set(UpperCAmelCase__))

           # Parameter should be reordered according to their respective place in the function:
           # (input_ids, token_type_ids, attention_mask)
           self.assertEqual(UpperCAmelCase__      ,				(tokens['''input_ids'''], tokens['''token_type_ids'''], tokens['''attention_mask''']))

           # Generated args are interleaved with another args (for instance parameter "past" in GPT2)
           A__				,							A__   				=					ensure_valid_input(FuncNonContiguousArgs()      ,				UpperCAmelCase__      ,				UpperCAmelCase__)

           # Should have exactly the one arg (all before the one not provided "some_other_args")
           self.assertEqual(len(UpperCAmelCase__)      ,				1)
           self.assertEqual(len(UpperCAmelCase__)      ,				1)

           # Should have only "input_ids"
           self.assertEqual(inputs_args[0]      ,				tokens['''input_ids'''])
           self.assertEqual(ordered_input_names[0]      ,				'''input_ids''')





    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->int:





           '''simple docstring'''

           A__   				=					generate_identified_filename(Path('''/home/something/my_fake_model.onnx''')      ,				'''-test''')
           self.assertEqual('''/home/something/my_fake_model-test.onnx'''      ,				generated.as_posix())








def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> int:



       """simple docstring"""

       A__   				=					1
       for i in range(1				,       num + 1		):
              fact *= i
       return fact







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> int:



       """simple docstring"""

       A__   				=					0
       while number > 0:
              A__   				=					number % 10
              sum_of_digits += last_digit
              A__   				=					number // 10  # Removing the last_digit from the given number
       return sum_of_digits







def SCREAMING_SNAKE_CASE       ( lowercase_ = 100		)     -> int:



       """simple docstring"""

       A__   				=					factorial(lowercase_		)
       A__   				=					split_and_add(lowercase_		)
       return result


if __name__ == "__main__":
  print(solution(int(input("""Enter the Number: """).strip())))


