



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




def 	UpperCAmelCase     (		A	:						str=None     ,				A	:						Optional[int]=None       ):

		'''simple docstring'''


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




@dataclass
class 			lowercase__			:
							'''simple docstring'''







							_UpperCAmelCase      				=					42
							_UpperCAmelCase      				=					42
							_UpperCAmelCase      				=					42
							_UpperCAmelCase      				=					42







@dataclass
class 			lowercase__			:
							'''simple docstring'''







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







@dataclass
class 			lowercase__			:
							'''simple docstring'''







							_UpperCAmelCase      				=					False
							_UpperCAmelCase      				=					True
							_UpperCAmelCase      				=					None







class 			lowercase__			(      A    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					'''titi'''
							_UpperCAmelCase      				=					'''toto'''







class 			lowercase__			(      A    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					'''titi'''
							_UpperCAmelCase      				=					'''toto'''
							_UpperCAmelCase      				=					42







@dataclass
class 			lowercase__			:
							'''simple docstring'''







							_UpperCAmelCase      				=					"toto"






							def        lowerCamelCase_   (  self						)			->							int:
									_UpperCAmelCase							 =		BasicEnum(self.foo						)







@dataclass
class 			lowercase__			:
							'''simple docstring'''







							_UpperCAmelCase      				=					"toto"






							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		MixedTypeEnum(self.foo						)







@dataclass
class 			lowercase__			:
							'''simple docstring'''







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







@dataclass
class 			lowercase__			:
							'''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 			lowercase__			:
							'''simple docstring'''







							_UpperCAmelCase      				=					field()
							_UpperCAmelCase      				=					field()
							_UpperCAmelCase      				=					field()






							def        lowerCamelCase_   (  self						)			->							Tuple:
									_UpperCAmelCase							 =		BasicEnum(self.required_enum						)







@dataclass
class 			lowercase__			:
							'''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 			lowercase__			:
												'''simple docstring'''







												_UpperCAmelCase      				=					False
												_UpperCAmelCase      				=					True
												_UpperCAmelCase      				=					None







					@dataclass
					class 			lowercase__			:
												'''simple docstring'''







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






class 			lowercase__			(      unittest.TestCase    ):
							'''simple docstring'''







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

											self.assertEqual(snake_case	,       snake_case						)






							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

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






							def        lowerCamelCase_   (  self						)			->							Optional[int]:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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






							def        lowerCamelCase_   (  self						)			->							Optional[int]:
									_UpperCAmelCase							 =		argparse.ArgumentParser()
									expected.add_argument('--foo'	,       type=snake_case	,       default=snake_case	,       const=snake_case	,       nargs='?'						)
									expected.add_argument('--baz'	,       type=snake_case	,       default=snake_case	,       const=snake_case	,       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=snake_case	,       dest='baz'						)
									expected.add_argument('--opt'	,       type=snake_case	,       default=snake_case						)

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

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

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

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

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

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

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






							def        lowerCamelCase_   (  self						)			->							List[str]:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

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

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

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






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




									@dataclass
									class 			lowercase__			:
																'''simple docstring'''







																_UpperCAmelCase      				=					"toto"







									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

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

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

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






							def        lowerCamelCase_   (  self						)			->							Tuple:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

									self.argparsersEqual(snake_case	,       snake_case						)

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

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






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

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

									for dataclass_type in dataclass_types:
											_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

											self.argparsersEqual(snake_case	,       snake_case						)

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

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






							def        lowerCamelCase_   (  self						)			->							Any:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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






							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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






							def        lowerCamelCase_   (  self						)			->							Optional[Any]:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

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






							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

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






							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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

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






							def        lowerCamelCase_   (  self						)			->							Tuple:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)

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






							def        lowerCamelCase_   (  self						)			->							List[str]:
									_UpperCAmelCase							 =		HfArgumentParser(snake_case						)
									self.assertIsNotNone(snake_case						)







"""simple docstring"""





from typing import TYPE_CHECKING

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


lowercase  							=					{
    '''configuration_roberta''': ['''ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''RobertaConfig''', '''RobertaOnnxConfig'''],
    '''tokenization_roberta''': ['''RobertaTokenizer'''],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase  							=					['''RobertaTokenizerFast''']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase  							=					[
					    '''ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''RobertaForCausalLM''',
					    '''RobertaForMaskedLM''',
					    '''RobertaForMultipleChoice''',
					    '''RobertaForQuestionAnswering''',
					    '''RobertaForSequenceClassification''',
					    '''RobertaForTokenClassification''',
					    '''RobertaModel''',
					    '''RobertaPreTrainedModel''',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase  							=					[
					    '''TF_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TFRobertaForCausalLM''',
					    '''TFRobertaForMaskedLM''',
					    '''TFRobertaForMultipleChoice''',
					    '''TFRobertaForQuestionAnswering''',
					    '''TFRobertaForSequenceClassification''',
					    '''TFRobertaForTokenClassification''',
					    '''TFRobertaMainLayer''',
					    '''TFRobertaModel''',
					    '''TFRobertaPreTrainedModel''',
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase  							=					[
					    '''FlaxRobertaForCausalLM''',
					    '''FlaxRobertaForMaskedLM''',
					    '''FlaxRobertaForMultipleChoice''',
					    '''FlaxRobertaForQuestionAnswering''',
					    '''FlaxRobertaForSequenceClassification''',
					    '''FlaxRobertaForTokenClassification''',
					    '''FlaxRobertaModel''',
					    '''FlaxRobertaPreTrainedModel''',
					]


if TYPE_CHECKING:
					from .configuration_roberta import ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP, RobertaConfig, RobertaOnnxConfig
					from .tokenization_roberta import RobertaTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_roberta_fast import RobertaTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_roberta import (
										    ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
										    RobertaForCausalLM,
										    RobertaForMaskedLM,
										    RobertaForMultipleChoice,
										    RobertaForQuestionAnswering,
										    RobertaForSequenceClassification,
										    RobertaForTokenClassification,
										    RobertaModel,
										    RobertaPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_roberta import (
										    TF_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFRobertaForCausalLM,
										    TFRobertaForMaskedLM,
										    TFRobertaForMultipleChoice,
										    TFRobertaForQuestionAnswering,
										    TFRobertaForSequenceClassification,
										    TFRobertaForTokenClassification,
										    TFRobertaMainLayer,
										    TFRobertaModel,
										    TFRobertaPreTrainedModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_roberta import (
										    FlaxRobertaForCausalLM,
										    FlaxRobertaForMaskedLM,
										    FlaxRobertaForMultipleChoice,
										    FlaxRobertaForQuestionAnswering,
										    FlaxRobertaForSequenceClassification,
										    FlaxRobertaForTokenClassification,
										    FlaxRobertaModel,
										    FlaxRobertaPreTrainedModel,
										)

else:
					import sys

					lowercase  							=					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


