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






def 			a_						(			__lowercase  :      int=None			,   __lowercase  :      List[Any]=None					)					->    List[Any]:
			return field(default_factory=lambda: default			,   metadata=lowercase__					)




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						int
	_UpperCAmelCase			:						float
	_UpperCAmelCase			:						str
	_UpperCAmelCase			:						bool




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						int         =   4_2
	_UpperCAmelCase			:						str         =   field(default="toto"				,metadata={"help": "help message"}   )




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						bool         =   False
	_UpperCAmelCase			:						bool         =   True
	_UpperCAmelCase			:						Optional[bool]         =   None




class   SCREAMING_SNAKE_CASE__	(      UpperCAmelCase   ):





	'''simple docstring'''



	_UpperCAmelCase			:						List[str]         =   'titi'
	_UpperCAmelCase			:						Tuple         =   'toto'




class   SCREAMING_SNAKE_CASE__	(      UpperCAmelCase   ):





	'''simple docstring'''



	_UpperCAmelCase			:						Tuple         =   'titi'
	_UpperCAmelCase			:						List[Any]         =   'toto'
	_UpperCAmelCase			:						List[str]         =   4_2




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						BasicEnum         =   "toto"



	def 					A				(    self      :       Any      ):


				'''simple docstring'''


				_snake_case            =     BasicEnum(self.foo      )




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						MixedTypeEnum         =   "toto"



	def 					A				(    self      :       List[str]      ):


				'''simple docstring'''


				_snake_case            =     MixedTypeEnum(self.foo      )




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						Optional[int]         =   None
	_UpperCAmelCase			:						Optional[float]         =   field(default=UpperCAmelCase				,metadata={"help": "help message"}   )
	_UpperCAmelCase			:						Optional[str]         =   None
	_UpperCAmelCase			:						Optional[List[str]]         =   list_field(default=[]   )
	_UpperCAmelCase			:						Optional[List[int]]         =   list_field(default=[]   )




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						List[int]         =   list_field(default=[]   )
	_UpperCAmelCase			:						List[int]         =   list_field(default=[1, 2, 3]   )
	_UpperCAmelCase			:						List[str]         =   list_field(default=["Hallo", "Bonjour", "Hello"]   )
	_UpperCAmelCase			:						List[float]         =   list_field(default=[0.1, 0.2, 0.3]   )




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						List[int]         =   field()
	_UpperCAmelCase			:						str         =   field()
	_UpperCAmelCase			:						BasicEnum         =   field()



	def 					A				(    self      :       Any      ):


				'''simple docstring'''


				_snake_case            =     BasicEnum(self.required_enum      )




@dataclass
class   SCREAMING_SNAKE_CASE__	:





	'''simple docstring'''



	_UpperCAmelCase			:						int
	_UpperCAmelCase			:						"BasicEnum"         =   field()
	_UpperCAmelCase			:						"Optional[bool]"         =   None
	_UpperCAmelCase			:						"str"         =   field(default="toto"				,metadata={"help": "help message"}   )
	_UpperCAmelCase			:						"List[str]"         =   list_field(default=["Hallo", "Bonjour", "Hello"]   )


if is_python_no_less_than_3_10:




			@dataclass
			class   SCREAMING_SNAKE_CASE__	:





				'''simple docstring'''



				_UpperCAmelCase			:						bool         =   False
				_UpperCAmelCase			:						bool         =   True
				_UpperCAmelCase			:						bool | None         =   None




			@dataclass
			class   SCREAMING_SNAKE_CASE__	:





				'''simple docstring'''



				_UpperCAmelCase			:						int | None         =   None
				_UpperCAmelCase			:						float | None         =   field(default=UpperCAmelCase				,metadata={"help": "help message"}   )
				_UpperCAmelCase			:						str | None         =   None
				_UpperCAmelCase			:						list[str] | None         =   list_field(default=[]   )
				_UpperCAmelCase			:						list[int] | None         =   list_field(default=[]   )




class   SCREAMING_SNAKE_CASE__	(      unittest.TestCase   ):





	'''simple docstring'''



	def 					A				(    self      :       Optional[int]     ,    lowercase      :       Union[str, Any]     ,    lowercase      :       List[Any]      ):


				'''simple docstring'''


				self.assertEqual(len(a._actions      )     ,    len(b._actions      )      )
				for x, y in zip(a._actions     ,    b._actions      ):
							_snake_case            =     {k: v for k, v in vars(lowercase      ).items() if k != "container"}
							_snake_case            =     {k: v for k, v in vars(lowercase      ).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'     ,    lowercase      ) and yy.get('choices'     ,    lowercase      ):
										for expected_choice in yy["choices"] + xx["choices"]:
													self.assertEqual(xx['type'](lowercase      )     ,    yy['type'](lowercase      )      )
										del xx["type"], yy["type"]

							self.assertEqual(lowercase     ,    lowercase      )



	def 					A				(    self      :       int      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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

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



	def 					A				(    self      :       Dict      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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



	def 					A				(    self      :       Dict      ):


				'''simple docstring'''


				_snake_case            =     argparse.ArgumentParser()
				expected.add_argument('--foo'     ,    type=lowercase     ,    default=lowercase     ,    const=lowercase     ,    nargs='?'      )
				expected.add_argument('--baz'     ,    type=lowercase     ,    default=lowercase     ,    const=lowercase     ,    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=lowercase     ,    dest='baz'      )
				expected.add_argument('--opt'     ,    type=lowercase     ,    default=lowercase      )

				_snake_case            =     [WithDefaultBoolExample]
				if is_python_no_less_than_3_10:
							dataclass_types.append(lowercase      )

				for dataclass_type in dataclass_types:
							_snake_case            =     HfArgumentParser(lowercase      )
							self.argparsersEqual(lowercase     ,    lowercase      )

							_snake_case            =     parser.parse_args([]      )
							self.assertEqual(lowercase     ,    Namespace(foo=lowercase     ,    baz=lowercase     ,    opt=lowercase      )      )

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

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

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

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



	def 					A				(    self      :       Union[str, Any]      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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

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

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

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



	def 					A				(    self      :       str      ):


				'''simple docstring'''


				@dataclass
				class   SCREAMING_SNAKE_CASE__	:





					'''simple docstring'''



					_UpperCAmelCase			:						Literal["titi", "toto", 4_2]         =   "toto"




				_snake_case            =     HfArgumentParser(lowercase      )

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

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

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

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



	def 					A				(    self      :       List[Any]      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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

				self.argparsersEqual(lowercase     ,    lowercase      )

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

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



	def 					A				(    self      :       Optional[Any]      ):


				'''simple docstring'''


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

				_snake_case            =     [OptionalExample]
				if is_python_no_less_than_3_10:
							dataclass_types.append(lowercase      )

				for dataclass_type in dataclass_types:
							_snake_case            =     HfArgumentParser(lowercase      )

							self.argparsersEqual(lowercase     ,    lowercase      )

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

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



	def 					A				(    self      :       List[str]      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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



	def 					A				(    self      :       Union[str, Any]      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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



	def 					A				(    self      :       List[str]      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

				_snake_case            =     {
				    "foo": 12,
				    "bar": 3.14,
				    "baz": "42",
				    "flag": True,
				}

				_snake_case            =     parser.parse_dict(lowercase      )[0]
				_snake_case            =     BasicExample(**lowercase      )
				self.assertEqual(lowercase     ,    lowercase      )



	def 					A				(    self      :       Union[str, Any]      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

				_snake_case            =     {
				    "foo": 12,
				    "bar": 3.14,
				    "baz": "42",
				    "flag": True,
				    "extra": 42,
				}

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



	def 					A				(    self      :       int      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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

				_snake_case            =     BasicExample(**lowercase      )
				self.assertEqual(lowercase     ,    lowercase      )



	def 					A				(    self      :       int      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )

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





	def 					A				(    self      :       Dict      ):


				'''simple docstring'''


				_snake_case            =     HfArgumentParser(lowercase      )
				self.assertIsNotNone(lowercase      )


"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


if is_sentencepiece_available():
    from ..ta.tokenization_ta import TaTokenizer
else:
    from ...utils.dummy_sentencepiece_objects import TaTokenizer

_UpperCamelCase		     =    TaTokenizer

if is_tokenizers_available():
    from ..ta.tokenization_ta_fast import TaTokenizerFast
else:
    from ...utils.dummy_tokenizers_objects import TaTokenizerFast

_UpperCamelCase		     =    TaTokenizerFast

_UpperCamelCase		     =    {"""configuration_mt5""": ["""MT5Config""", """MT5OnnxConfig"""]}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		     =    [
        """MT5EncoderModel""",
        """MT5ForConditionalGeneration""",
        """MT5ForQuestionAnswering""",
        """MT5Model""",
        """MT5PreTrainedModel""",
        """MT5Stack""",
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		     =    ["""TFMT5EncoderModel""", """TFMT5ForConditionalGeneration""", """TFMT5Model"""]

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		     =    ["""FlaxMT5EncoderModel""", """FlaxMT5ForConditionalGeneration""", """FlaxMT5Model"""]


if TYPE_CHECKING:
    from .configuration_mta import MTaConfig, MTaOnnxConfig

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_mta import (
            MTaEncoderModel,
            MTaForConditionalGeneration,
            MTaForQuestionAnswering,
            MTaModel,
            MTaPreTrainedModel,
            MTaStack,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_mta import TFMTaEncoderModel, TFMTaForConditionalGeneration, TFMTaModel

    try:
        if not is_flax_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_flax_mta import FlaxMTaEncoderModel, FlaxMTaForConditionalGeneration, FlaxMTaModel

else:
    import sys

    _UpperCamelCase		     =    _LazyModule(
        __name__,
        globals()["""__file__"""],
        _import_structure,
        extra_objects={"""MT5Tokenizer""": MTaTokenizer, """MT5TokenizerFast""": MTaTokenizerFast},
        module_spec=__spec__,
    )






