




import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
_lowerCamelCase      :						Optional[Any]							=  sys.version_info >= (3, 10)







def SCREAMING_SNAKE_CASE							(			lowercase_=None					,							lowercase_=None		)  ->			str:



       """simple docstring"""

       return field(default_factory=lambda: default					,							metadata=__snake_case		)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = 42
    UpperCAmelCase__				    = 42
    UpperCAmelCase__				    = 42
    UpperCAmelCase__				    = 42


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = 42
    UpperCAmelCase__				    = field(default='''toto'''						,   metadata={'''help''': '''help message'''}	)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = False
    UpperCAmelCase__				    = True
    UpperCAmelCase__				    = None


class 							UpperCamelCase_       (					a__	):

    '''simple docstring'''






    UpperCAmelCase__				    = '''titi'''
    UpperCAmelCase__				    = '''toto'''


class 							UpperCamelCase_       (					a__	):

    '''simple docstring'''






    UpperCAmelCase__				    = '''titi'''
    UpperCAmelCase__				    = '''toto'''
    UpperCAmelCase__				    = 42


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = '''toto'''


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





           '''simple docstring'''

           A__ 					=       BasicEnum(self.foo)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = '''toto'''


    def 			SCREAMING_SNAKE_CASE				(     self :      List[Any])		->Union[str, Any]:





           '''simple docstring'''

           A__ 					=       MixedTypeEnum(self.foo)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = None
    UpperCAmelCase__				    = field(default=a__						,   metadata={'''help''': '''help message'''}	)
    UpperCAmelCase__				    = None
    UpperCAmelCase__				    = list_field(default=[]	)
    UpperCAmelCase__				    = list_field(default=[]	)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = list_field(default=[]	)
    UpperCAmelCase__				    = list_field(default=[1, 2, 3]	)
    UpperCAmelCase__				    = list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']	)
    UpperCAmelCase__				    = list_field(default=[0.1, 0.2, 0.3]	)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = field()
    UpperCAmelCase__				    = field()
    UpperCAmelCase__				    = field()


    def 			SCREAMING_SNAKE_CASE				(     self :      Union[str, Any])		->List[str]:





           '''simple docstring'''

           A__ 					=       BasicEnum(self.required_enum)


@dataclass
class 							UpperCamelCase_       :

    '''simple docstring'''






    UpperCAmelCase__				    = 42
    UpperCAmelCase__				    = field()
    UpperCAmelCase__				    = None
    UpperCAmelCase__				    = field(default='''toto'''						,   metadata={'''help''': '''help message'''}	)
    UpperCAmelCase__				    = list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']	)


if is_python_no_less_than_3_10:


  @dataclass
  class 							UpperCamelCase_       :

      '''simple docstring'''






      UpperCAmelCase__				    = False
      UpperCAmelCase__				    = True
      UpperCAmelCase__				    = None


  @dataclass
  class 							UpperCamelCase_       :

      '''simple docstring'''






      UpperCAmelCase__				    = None
      UpperCAmelCase__				    = field(default=a__						,   metadata={'''help''': '''help message'''}	)
      UpperCAmelCase__				    = None
      UpperCAmelCase__				    = list_field(default=[]	)
      UpperCAmelCase__				    = list_field(default=[]	)


class 							UpperCamelCase_       (					unittest.TestCase	):

    '''simple docstring'''






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





           '''simple docstring'''

           self.assertEqual(len(a._actions)   ,					len(b._actions))
           for x, y in zip(a._actions   ,					b._actions):
                  A__ 					=       {k: v for k, v in vars(_UpperCAmelCase).items() if k != 'container'}
                  A__ 					=       {k: v for k, v in vars(_UpperCAmelCase).items() if k != 'container'}

                  # Choices with mixed type have custom function as "type"
                  # So we need to compare results directly for equality
                  if xx.get('''choices'''   ,					_UpperCAmelCase) and yy.get('''choices'''   ,					_UpperCAmelCase):
                         for expected_choice in yy["choices"] + xx["choices"]:
                                self.assertEqual(xx['''type'''](_UpperCAmelCase)   ,					yy['''type'''](_UpperCAmelCase))
                         del xx["type"], yy["type"]

                  self.assertEqual(_UpperCAmelCase   ,					_UpperCAmelCase)


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--foo'''   ,					type=_UpperCAmelCase   ,					required=_UpperCAmelCase)
           expected.add_argument('''--bar'''   ,					type=_UpperCAmelCase   ,					required=_UpperCAmelCase)
           expected.add_argument('''--baz'''   ,					type=_UpperCAmelCase   ,					required=_UpperCAmelCase)
           expected.add_argument('''--flag'''   ,					type=_UpperCAmelCase   ,					default=_UpperCAmelCase   ,					const=_UpperCAmelCase   ,					nargs='''?''')
           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)

           A__ 					=       ['--foo', '1', '--baz', 'quux', '--bar', '0.5']
           (A__) 					=       parser.parse_args_into_dataclasses(_UpperCAmelCase   ,					look_for_args_file=_UpperCAmelCase)
           self.assertFalse(example.flag)


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--foo'''   ,					default=42   ,					type=_UpperCAmelCase)
           expected.add_argument('''--baz'''   ,					default='''toto'''   ,					type=_UpperCAmelCase   ,					help='''help message''')
           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)


    def 			SCREAMING_SNAKE_CASE				(     self :      Dict)		->List[Any]:





           '''simple docstring'''

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--foo'''   ,					type=_UpperCAmelCase   ,					default=_UpperCAmelCase   ,					const=_UpperCAmelCase   ,					nargs='''?''')
           expected.add_argument('''--baz'''   ,					type=_UpperCAmelCase   ,					default=_UpperCAmelCase   ,					const=_UpperCAmelCase   ,					nargs='''?''')
           # A boolean no_* argument always has to come after its "default: True" regular counter-part
           # and its default must be set to False
           expected.add_argument('''--no_baz'''   ,					action='''store_false'''   ,					default=_UpperCAmelCase   ,					dest='''baz''')
           expected.add_argument('''--opt'''   ,					type=_UpperCAmelCase   ,					default=_UpperCAmelCase)

           A__ 					=       [WithDefaultBoolExample]
           if is_python_no_less_than_3_10:
                  dataclass_types.append(_UpperCAmelCase)

           for dataclass_type in dataclass_types:
                  A__ 					=       HfArgumentParser(_UpperCAmelCase)
                  self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)

                  A__ 					=       parser.parse_args([])
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=_UpperCAmelCase   ,					baz=_UpperCAmelCase   ,					opt=_UpperCAmelCase))

                  A__ 					=       parser.parse_args(['''--foo''', '''--no_baz'''])
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=_UpperCAmelCase   ,					baz=_UpperCAmelCase   ,					opt=_UpperCAmelCase))

                  A__ 					=       parser.parse_args(['''--foo''', '''--baz'''])
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=_UpperCAmelCase   ,					baz=_UpperCAmelCase   ,					opt=_UpperCAmelCase))

                  A__ 					=       parser.parse_args(['''--foo''', '''True''', '''--baz''', '''True''', '''--opt''', '''True'''])
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=_UpperCAmelCase   ,					baz=_UpperCAmelCase   ,					opt=_UpperCAmelCase))

                  A__ 					=       parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False'''])
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=_UpperCAmelCase   ,					baz=_UpperCAmelCase   ,					opt=_UpperCAmelCase))


    def 			SCREAMING_SNAKE_CASE				(     self :      int)		->Any:





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument(
               '''--foo'''   ,					default='''toto'''   ,					choices=['''titi''', '''toto''', 42]   ,					type=make_choice_type_function(['''titi''', '''toto''', 42])   ,					)
           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)

           A__ 					=       parser.parse_args([])
           self.assertEqual(args.foo   ,					'''toto''')
           A__ 					=       parser.parse_args_into_dataclasses([])[0]
           self.assertEqual(enum_ex.foo   ,					MixedTypeEnum.toto)

           A__ 					=       parser.parse_args(['''--foo''', '''titi'''])
           self.assertEqual(args.foo   ,					'''titi''')
           A__ 					=       parser.parse_args_into_dataclasses(['''--foo''', '''titi'''])[0]
           self.assertEqual(enum_ex.foo   ,					MixedTypeEnum.titi)

           A__ 					=       parser.parse_args(['''--foo''', '''42'''])
           self.assertEqual(args.foo   ,					42)
           A__ 					=       parser.parse_args_into_dataclasses(['''--foo''', '''42'''])[0]
           self.assertEqual(enum_ex.foo   ,					MixedTypeEnum.fourtytwo)


    def 			SCREAMING_SNAKE_CASE				(     self :      List[str])		->int:





           '''simple docstring'''

           @dataclass
           class 							UpperCamelCase_       :

               '''simple docstring'''






               UpperCAmelCase__				    = '''toto'''
           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument(
               '''--foo'''   ,					default='''toto'''   ,					choices=('''titi''', '''toto''', 42)   ,					type=make_choice_type_function(['''titi''', '''toto''', 42])   ,					)
           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)

           A__ 					=       parser.parse_args([])
           self.assertEqual(args.foo   ,					'''toto''')

           A__ 					=       parser.parse_args(['''--foo''', '''titi'''])
           self.assertEqual(args.foo   ,					'''titi''')

           A__ 					=       parser.parse_args(['''--foo''', '''42'''])
           self.assertEqual(args.foo   ,					42)


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--foo_int'''   ,					nargs='''+'''   ,					default=[]   ,					type=_UpperCAmelCase)
           expected.add_argument('''--bar_int'''   ,					nargs='''+'''   ,					default=[1, 2, 3]   ,					type=_UpperCAmelCase)
           expected.add_argument('''--foo_str'''   ,					nargs='''+'''   ,					default=['''Hallo''', '''Bonjour''', '''Hello''']   ,					type=_UpperCAmelCase)
           expected.add_argument('''--foo_float'''   ,					nargs='''+'''   ,					default=[0.1, 0.2, 0.3]   ,					type=_UpperCAmelCase)

           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)

           A__ 					=       parser.parse_args([])
           self.assertEqual(
               _UpperCAmelCase   ,					Namespace(foo_int=[]   ,					bar_int=[1, 2, 3]   ,					foo_str=['''Hallo''', '''Bonjour''', '''Hello''']   ,					foo_float=[0.1, 0.2, 0.3])   ,					)

           A__ 					=       parser.parse_args('''--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'''.split())
           self.assertEqual(_UpperCAmelCase   ,					Namespace(foo_int=[1]   ,					bar_int=[2, 3]   ,					foo_str=['''a''', '''b''', '''c''']   ,					foo_float=[0.1, 0.7]))


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





           '''simple docstring'''

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--foo'''   ,					default=_UpperCAmelCase   ,					type=_UpperCAmelCase)
           expected.add_argument('''--bar'''   ,					default=_UpperCAmelCase   ,					type=_UpperCAmelCase   ,					help='''help message''')
           expected.add_argument('''--baz'''   ,					default=_UpperCAmelCase   ,					type=_UpperCAmelCase)
           expected.add_argument('''--ces'''   ,					nargs='''+'''   ,					default=[]   ,					type=_UpperCAmelCase)
           expected.add_argument('''--des'''   ,					nargs='''+'''   ,					default=[]   ,					type=_UpperCAmelCase)

           A__ 					=       [OptionalExample]
           if is_python_no_less_than_3_10:
                  dataclass_types.append(_UpperCAmelCase)

           for dataclass_type in dataclass_types:
                  A__ 					=       HfArgumentParser(_UpperCAmelCase)

                  self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)

                  A__ 					=       parser.parse_args([])
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=_UpperCAmelCase   ,					bar=_UpperCAmelCase   ,					baz=_UpperCAmelCase   ,					ces=[]   ,					des=[]))

                  A__ 					=       parser.parse_args('''--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'''.split())
                  self.assertEqual(_UpperCAmelCase   ,					Namespace(foo=12   ,					bar=3.14   ,					baz='''42'''   ,					ces=['''a''', '''b''', '''c''']   ,					des=[1, 2, 3]))


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--required_list'''   ,					nargs='''+'''   ,					type=_UpperCAmelCase   ,					required=_UpperCAmelCase)
           expected.add_argument('''--required_str'''   ,					type=_UpperCAmelCase   ,					required=_UpperCAmelCase)
           expected.add_argument(
               '''--required_enum'''   ,					type=make_choice_type_function(['''titi''', '''toto'''])   ,					choices=['''titi''', '''toto''']   ,					required=_UpperCAmelCase   ,					)
           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       argparse.ArgumentParser()
           expected.add_argument('''--foo'''   ,					type=_UpperCAmelCase   ,					required=_UpperCAmelCase)
           expected.add_argument(
               '''--required_enum'''   ,					type=make_choice_type_function(['''titi''', '''toto'''])   ,					choices=['''titi''', '''toto''']   ,					required=_UpperCAmelCase   ,					)
           expected.add_argument('''--opt'''   ,					type=_UpperCAmelCase   ,					default=_UpperCAmelCase)
           expected.add_argument('''--baz'''   ,					default='''toto'''   ,					type=_UpperCAmelCase   ,					help='''help message''')
           expected.add_argument('''--foo_str'''   ,					nargs='''+'''   ,					default=['''Hallo''', '''Bonjour''', '''Hello''']   ,					type=_UpperCAmelCase)
           self.argparsersEqual(_UpperCAmelCase   ,					_UpperCAmelCase)


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       {
               'foo': 12,
               'bar': 3.14,
               'baz': '42',
               'flag': True,
           }

           A__ 					=       parser.parse_dict(_UpperCAmelCase)[0]
           A__ 					=       BasicExample(**_UpperCAmelCase)
           self.assertEqual(_UpperCAmelCase   ,					_UpperCAmelCase)


    def 			SCREAMING_SNAKE_CASE				(     self :      List[str])		->Tuple:





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       {
               'foo': 12,
               'bar': 3.14,
               'baz': '42',
               'flag': True,
               'extra': 42,
           }

           self.assertRaises(_UpperCAmelCase   ,					parser.parse_dict   ,					_UpperCAmelCase   ,					allow_extra_keys=_UpperCAmelCase)


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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       {
               'foo': 12,
               'bar': 3.14,
               'baz': '42',
               'flag': True,
           }
           with tempfile.TemporaryDirectory() as tmp_dir:
                  A__ 					=       os.path.join(_UpperCAmelCase   ,					'''temp_json''')
                  os.mkdir(_UpperCAmelCase)
                  with open(temp_local_path + '''.json'''   ,					'''w+''') as f:
                         json.dump(_UpperCAmelCase   ,					_UpperCAmelCase)
                  A__ 					=       parser.parse_yaml_file(Path(temp_local_path + '''.json'''))[0]

           A__ 					=       BasicExample(**_UpperCAmelCase)
           self.assertEqual(_UpperCAmelCase   ,					_UpperCAmelCase)


    def 			SCREAMING_SNAKE_CASE				(     self :      str)		->List[Any]:





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)

           A__ 					=       {
               'foo': 12,
               'bar': 3.14,
               'baz': '42',
               'flag': True,
           }
           with tempfile.TemporaryDirectory() as tmp_dir:
                  A__ 					=       os.path.join(_UpperCAmelCase   ,					'''temp_yaml''')
                  os.mkdir(_UpperCAmelCase)
                  with open(temp_local_path + '''.yaml'''   ,					'''w+''') as f:
                         yaml.dump(_UpperCAmelCase   ,					_UpperCAmelCase)
                  A__ 					=       parser.parse_yaml_file(Path(temp_local_path + '''.yaml'''))[0]
           A__ 					=       BasicExample(**_UpperCAmelCase)
           self.assertEqual(_UpperCAmelCase   ,					_UpperCAmelCase)





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





           '''simple docstring'''

           A__ 					=       HfArgumentParser(_UpperCAmelCase)
           self.assertIsNotNone(_UpperCAmelCase)









'''simple docstring'''




import fire

from transformers import AutoConfig, AutoModelForSeqaSeqLM, AutoTokenizer






def 			_lowerCAmelCase     (    __snake_case    :					str					,				__snake_case    :					str					,				**__snake_case    :					List[Any]     )	->	Any:
     __A		:					Optional[Any]						=			AutoConfig.from_pretrained(__snake_case					,				**__snake_case     )
     __A		:					int						=			AutoModelForSeqaSeqLM.from_config(__snake_case     )
     model.save_pretrained(__snake_case     )
     AutoTokenizer.from_pretrained(__snake_case     ).save_pretrained(__snake_case     )
     return model


if __name__ == "__main__":
  fire.Fire(save_randomly_initialized_version)