

"""simple docstring"""


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
UpperCAmelCase													=sys.version_info >= (3, 10)



def   _A					(	_a	:						Optional[Any]=None     ,   _a	:						Tuple=None				):



      """simple docstring"""






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





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




    _lowerCamelCase					=   42
    _lowerCamelCase					=   42
    _lowerCamelCase					=   42
    _lowerCamelCase					=   42





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




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





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




    _lowerCamelCase					=   False
    _lowerCamelCase					=   True
    _lowerCamelCase					=   None





class lowerCamelCase__   (				SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   '''titi'''
    _lowerCamelCase					=   '''toto'''





class lowerCamelCase__   (				SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   '''titi'''
    _lowerCamelCase					=   '''toto'''
    _lowerCamelCase					=   42





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




    _lowerCamelCase					=   "toto"




    def UpperCamelCase__		( self    )    ->      int:
          A				  =		BasicEnum(self.foo    )





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




    _lowerCamelCase					=   "toto"




    def UpperCamelCase__		( self    )    ->      List[str]:
          A				  =		MixedTypeEnum(self.foo    )





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




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





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




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





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




    _lowerCamelCase					=   field()
    _lowerCamelCase					=   field()
    _lowerCamelCase					=   field()




    def UpperCamelCase__		( self    )    ->      str:
          A				  =		BasicEnum(self.required_enum    )





@dataclass
class lowerCamelCase__   :



    '''simple docstring'''




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


if is_python_no_less_than_3_10:





  @dataclass
  class lowerCamelCase__   :



      '''simple docstring'''




      _lowerCamelCase					=   False
      _lowerCamelCase					=   True
      _lowerCamelCase					=   None





  @dataclass
  class lowerCamelCase__   :



      '''simple docstring'''




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





class lowerCamelCase__   (				unittest.TestCase    ):



    '''simple docstring'''




    def UpperCamelCase__		( self ,lowerCamelCase_ ,lowerCamelCase_    )    ->      Optional[int]:
          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(lowerCamelCase_    ).items() if k != """container"""}
                A				  =		{k: v for k, v in vars(lowerCamelCase_    ).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""" ,lowerCamelCase_    ) and yy.get("""choices""" ,lowerCamelCase_    ):
                      for expected_choice in yy["choices"] + xx["choices"]:
                            self.assertEqual(xx["""type"""](lowerCamelCase_    ) ,yy["""type"""](lowerCamelCase_    )    )
                      del xx["type"], yy["type"]

                self.assertEqual(lowerCamelCase_ ,lowerCamelCase_    )




    def UpperCamelCase__		( self    )    ->      Union[str, Any]:
          A				  =		HfArgumentParser(lowerCamelCase_    )

          A				  =		argparse.ArgumentParser()
          expected.add_argument("""--foo""" ,type=lowerCamelCase_ ,required=lowerCamelCase_    )
          expected.add_argument("""--bar""" ,type=lowerCamelCase_ ,required=lowerCamelCase_    )
          expected.add_argument("""--baz""" ,type=lowerCamelCase_ ,required=lowerCamelCase_    )
          expected.add_argument("""--flag""" ,type=lowerCamelCase_ ,default=lowerCamelCase_ ,const=lowerCamelCase_ ,nargs="""?"""    )
          self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )

          A				  =		["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
          ((A)  ,			)				  =		parser.parse_args_into_dataclasses(lowerCamelCase_ ,look_for_args_file=lowerCamelCase_    )
          self.assertFalse(example.flag    )




    def UpperCamelCase__		( self    )    ->      Dict:
          A				  =		HfArgumentParser(lowerCamelCase_    )

          A				  =		argparse.ArgumentParser()
          expected.add_argument("""--foo""" ,default=4_2 ,type=lowerCamelCase_    )
          expected.add_argument("""--baz""" ,default="""toto""" ,type=lowerCamelCase_ ,help="""help message"""    )
          self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )




    def UpperCamelCase__		( self    )    ->      int:
          A				  =		argparse.ArgumentParser()
          expected.add_argument("""--foo""" ,type=lowerCamelCase_ ,default=lowerCamelCase_ ,const=lowerCamelCase_ ,nargs="""?"""    )
          expected.add_argument("""--baz""" ,type=lowerCamelCase_ ,default=lowerCamelCase_ ,const=lowerCamelCase_ ,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=lowerCamelCase_ ,dest="""baz"""    )
          expected.add_argument("""--opt""" ,type=lowerCamelCase_ ,default=lowerCamelCase_    )

          A				  =		[WithDefaultBoolExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(lowerCamelCase_    )

          for dataclass_type in dataclass_types:
                A				  =		HfArgumentParser(lowerCamelCase_    )
                self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )

                A				  =		parser.parse_args([]    )
                self.assertEqual(lowerCamelCase_ ,Namespace(foo=lowerCamelCase_ ,baz=lowerCamelCase_ ,opt=lowerCamelCase_    )    )

                A				  =		parser.parse_args(["""--foo""", """--no_baz"""]    )
                self.assertEqual(lowerCamelCase_ ,Namespace(foo=lowerCamelCase_ ,baz=lowerCamelCase_ ,opt=lowerCamelCase_    )    )

                A				  =		parser.parse_args(["""--foo""", """--baz"""]    )
                self.assertEqual(lowerCamelCase_ ,Namespace(foo=lowerCamelCase_ ,baz=lowerCamelCase_ ,opt=lowerCamelCase_    )    )

                A				  =		parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]    )
                self.assertEqual(lowerCamelCase_ ,Namespace(foo=lowerCamelCase_ ,baz=lowerCamelCase_ ,opt=lowerCamelCase_    )    )

                A				  =		parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]    )
                self.assertEqual(lowerCamelCase_ ,Namespace(foo=lowerCamelCase_ ,baz=lowerCamelCase_ ,opt=lowerCamelCase_    )    )




    def UpperCamelCase__		( self    )    ->      Optional[Any]:
          A				  =		HfArgumentParser(lowerCamelCase_    )

          A				  =		argparse.ArgumentParser()
          expected.add_argument(
              """--foo""" ,default="""toto""" ,choices=["""titi""", """toto""", 4_2] ,type=make_choice_type_function(["""titi""", """toto""", 4_2]    ) ,)
          self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )

          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 ,4_2    )
          A				  =		parser.parse_args_into_dataclasses(["""--foo""", """42"""]    )[0]
          self.assertEqual(enum_ex.foo ,MixedTypeEnum.fourtytwo    )




    def UpperCamelCase__		( self    )    ->      List[Any]:





          @dataclass
          class lowerCamelCase__   :



              '''simple docstring'''




              _lowerCamelCase					=   "toto"




          A				  =		HfArgumentParser(lowerCamelCase_    )

          A				  =		argparse.ArgumentParser()
          expected.add_argument(
              """--foo""" ,default="""toto""" ,choices=("""titi""", """toto""", 4_2) ,type=make_choice_type_function(["""titi""", """toto""", 4_2]    ) ,)
          self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )

          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 ,4_2    )




    def UpperCamelCase__		( self    )    ->      Dict:
          A				  =		HfArgumentParser(lowerCamelCase_    )

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

          self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )

          A				  =		parser.parse_args([]    )
          self.assertEqual(
              lowerCamelCase_ ,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(lowerCamelCase_ ,Namespace(foo_int=[1] ,bar_int=[2, 3] ,foo_str=["""a""", """b""", """c"""] ,foo_float=[0.1, 0.7]    )    )




    def UpperCamelCase__		( self    )    ->      Optional[int]:
          A				  =		argparse.ArgumentParser()
          expected.add_argument("""--foo""" ,default=lowerCamelCase_ ,type=lowerCamelCase_    )
          expected.add_argument("""--bar""" ,default=lowerCamelCase_ ,type=lowerCamelCase_ ,help="""help message"""    )
          expected.add_argument("""--baz""" ,default=lowerCamelCase_ ,type=lowerCamelCase_    )
          expected.add_argument("""--ces""" ,nargs="""+""" ,default=[] ,type=lowerCamelCase_    )
          expected.add_argument("""--des""" ,nargs="""+""" ,default=[] ,type=lowerCamelCase_    )

          A				  =		[OptionalExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(lowerCamelCase_    )

          for dataclass_type in dataclass_types:
                A				  =		HfArgumentParser(lowerCamelCase_    )

                self.argparsersEqual(lowerCamelCase_ ,lowerCamelCase_    )

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

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




    def UpperCamelCase__		( self    )    ->      List[str]:
          A				  =		HfArgumentParser(lowerCamelCase_    )

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




    def UpperCamelCase__		( self    )    ->      Any:
          A				  =		HfArgumentParser(lowerCamelCase_    )

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




    def UpperCamelCase__		( self    )    ->      Dict:
          A				  =		HfArgumentParser(lowerCamelCase_    )

          A				  =		{
              """foo""": 1_2,
              """bar""": 3.14,
              """baz""": """42""",
              """flag""": True,
          }

          A				  =		parser.parse_dict(lowerCamelCase_    )[0]
          A				  =		BasicExample(**lowerCamelCase_    )
          self.assertEqual(lowerCamelCase_ ,lowerCamelCase_    )




    def UpperCamelCase__		( self    )    ->      List[Any]:
          A				  =		HfArgumentParser(lowerCamelCase_    )

          A				  =		{
              """foo""": 1_2,
              """bar""": 3.14,
              """baz""": """42""",
              """flag""": True,
              """extra""": 4_2,
          }

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




    def UpperCamelCase__		( self    )    ->      Union[str, Any]:
          A				  =		HfArgumentParser(lowerCamelCase_    )

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

          A				  =		BasicExample(**lowerCamelCase_    )
          self.assertEqual(lowerCamelCase_ ,lowerCamelCase_    )




    def UpperCamelCase__		( self    )    ->      List[Any]:
          A				  =		HfArgumentParser(lowerCamelCase_    )

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




    def UpperCamelCase__		( self    )    ->      str:
          A				  =		HfArgumentParser(lowerCamelCase_    )
          self.assertIsNotNone(lowerCamelCase_    )







"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


UpperCAmelCase													={
    "configuration_mega": ["MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP", "MegaConfig", "MegaOnnxConfig"],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase													=[
      "MEGA_PRETRAINED_MODEL_ARCHIVE_LIST",
      "MegaForCausalLM",
      "MegaForMaskedLM",
      "MegaForMultipleChoice",
      "MegaForQuestionAnswering",
      "MegaForSequenceClassification",
      "MegaForTokenClassification",
      "MegaModel",
      "MegaPreTrainedModel",
  ]

if TYPE_CHECKING:
  from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_mega import (
        MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
        MegaForCausalLM,
        MegaForMaskedLM,
        MegaForMultipleChoice,
        MegaForQuestionAnswering,
        MegaForSequenceClassification,
        MegaForTokenClassification,
        MegaModel,
        MegaPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase													=_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




