


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







def 						__lowerCAmelCase		(		lowercase						:						Dict=None		,							lowercase						:						Union[str, Any]=None				)			->		Optional[Any]:


    """simple docstring"""





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







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: Any													=						42
   __UpperCAmelCase				: Any													=						42
   __UpperCAmelCase				: List[Any]													=						42
   __UpperCAmelCase				: int													=						42







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: List[Any]													=						42
   __UpperCAmelCase				: Any													=						field(default='''toto'''					,							metadata={'''help''': '''help message'''}			)







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: int													=						False
   __UpperCAmelCase				: List[str]													=						True
   __UpperCAmelCase				: List[str]													=						None







class _lowerCAmelCase       (   __lowercase			):
   __UpperCAmelCase				: Dict													=						'''titi'''
   __UpperCAmelCase				: Optional[Any]													=						'''toto'''







class _lowerCAmelCase       (   __lowercase			):
   __UpperCAmelCase				: Union[str, Any]													=						'''titi'''
   __UpperCAmelCase				: List[str]													=						'''toto'''
   __UpperCAmelCase				: Any													=						42







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: Optional[int]													=						'''toto'''







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

       '''simple docstring'''




       snake_case					:   Union[str, Any]         =					BasicEnum(self.foo		)







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: List[Any]													=						'''toto'''







   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       snake_case					:   int         =					MixedTypeEnum(self.foo		)







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: int													=						None
   __UpperCAmelCase				: Dict													=						field(default=__lowercase					,							metadata={'''help''': '''help message'''}			)
   __UpperCAmelCase				: Any													=						None
   __UpperCAmelCase				: Tuple													=						list_field(default=[]			)
   __UpperCAmelCase				: Tuple													=						list_field(default=[]			)







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: Dict													=						list_field(default=[]			)
   __UpperCAmelCase				: str													=						list_field(default=[1, 2, 3]			)
   __UpperCAmelCase				: Dict													=						list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']			)
   __UpperCAmelCase				: Union[str, Any]													=						list_field(default=[0.1, 0.2, 0.3]			)







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: Optional[int]													=						field()
   __UpperCAmelCase				: int													=						field()
   __UpperCAmelCase				: str													=						field()







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

       '''simple docstring'''




       snake_case					:   int         =					BasicEnum(self.required_enum		)







@dataclass
class _lowerCAmelCase       :
   __UpperCAmelCase				: List[Any]													=						42
   __UpperCAmelCase				: List[Any]													=						field()
   __UpperCAmelCase				: int													=						None
   __UpperCAmelCase				: Optional[int]													=						field(default='''toto'''					,							metadata={'''help''': '''help message'''}			)
   __UpperCAmelCase				: Optional[Any]													=						list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']			)


if is_python_no_less_than_3_10:







      @dataclass
      class _lowerCAmelCase       :
         __UpperCAmelCase				: int													=						False
         __UpperCAmelCase				: List[str]													=						True
         __UpperCAmelCase				: str													=						None







      @dataclass
      class _lowerCAmelCase       :
         __UpperCAmelCase				: Optional[int]													=						None
         __UpperCAmelCase				: str													=						field(default=__lowercase					,							metadata={'''help''': '''help message'''}			)
         __UpperCAmelCase				: List[Any]													=						None
         __UpperCAmelCase				: Any													=						list_field(default=[]			)
         __UpperCAmelCase				: List[Any]													=						list_field(default=[]			)







class _lowerCAmelCase       (   unittest.TestCase			):







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		)			->	str:

       '''simple docstring'''




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

           self.assertEqual(_A		,			_A		)







   def 				lowerCamelCase	(			self		)			->	str:

       '''simple docstring'''




       snake_case					:   Optional[Any]         =					HfArgumentParser(_A		)

       snake_case					:   List[str]         =					argparse.ArgumentParser()
       expected.add_argument("--foo"		,			type=_A		,			required=_A		)
       expected.add_argument("--bar"		,			type=_A		,			required=_A		)
       expected.add_argument("--baz"		,			type=_A		,			required=_A		)
       expected.add_argument("--flag"		,			type=_A		,			default=_A		,			const=_A		,			nargs="?"		)
       self.argparsersEqual(_A		,			_A		)

       snake_case					:   Union[str, Any]         =					["--foo", "1", "--baz", "quux", "--bar", "0.5"]
       ((snake_case						)      ,						)					:   int         =					parser.parse_args_into_dataclasses(_A		,			look_for_args_file=_A		)
       self.assertFalse(example.flag		)







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

       '''simple docstring'''




       snake_case					:   Dict         =					HfArgumentParser(_A		)

       snake_case					:   List[str]         =					argparse.ArgumentParser()
       expected.add_argument("--foo"		,			default=42		,			type=_A		)
       expected.add_argument("--baz"		,			default="toto"		,			type=_A		,			help="help message"		)
       self.argparsersEqual(_A		,			_A		)







   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       snake_case					:   Any         =					argparse.ArgumentParser()
       expected.add_argument("--foo"		,			type=_A		,			default=_A		,			const=_A		,			nargs="?"		)
       expected.add_argument("--baz"		,			type=_A		,			default=_A		,			const=_A		,			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=_A		,			dest="baz"		)
       expected.add_argument("--opt"		,			type=_A		,			default=_A		)

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

       for dataclass_type in dataclass_types:
           snake_case					:   Optional[Any]         =					HfArgumentParser(_A		)
           self.argparsersEqual(_A		,			_A		)

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

           snake_case					:   Tuple         =					parser.parse_args(["--foo", "--no_baz"]		)
           self.assertEqual(_A		,			Namespace(foo=_A		,			baz=_A		,			opt=_A		)		)

           snake_case					:   Dict         =					parser.parse_args(["--foo", "--baz"]		)
           self.assertEqual(_A		,			Namespace(foo=_A		,			baz=_A		,			opt=_A		)		)

           snake_case					:   Optional[Any]         =					parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]		)
           self.assertEqual(_A		,			Namespace(foo=_A		,			baz=_A		,			opt=_A		)		)

           snake_case					:   int         =					parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]		)
           self.assertEqual(_A		,			Namespace(foo=_A		,			baz=_A		,			opt=_A		)		)







   def 				lowerCamelCase	(			self		)			->	Dict:

       '''simple docstring'''




       snake_case					:   int         =					HfArgumentParser(_A		)

       snake_case					:   Dict         =					argparse.ArgumentParser()
       expected.add_argument(
           "--foo"		,			default="toto"		,			choices=["titi", "toto", 42]		,			type=make_choice_type_function(["titi", "toto", 42]		)		,			)
       self.argparsersEqual(_A		,			_A		)

       snake_case					:   Tuple         =					parser.parse_args([]		)
       self.assertEqual(args.foo		,			"toto"		)
       snake_case					:   Union[str, Any]         =					parser.parse_args_into_dataclasses([]		)[0]
       self.assertEqual(enum_ex.foo		,			MixedTypeEnum.toto		)

       snake_case					:   int         =					parser.parse_args(["--foo", "titi"]		)
       self.assertEqual(args.foo		,			"titi"		)
       snake_case					:   List[Any]         =					parser.parse_args_into_dataclasses(["--foo", "titi"]		)[0]
       self.assertEqual(enum_ex.foo		,			MixedTypeEnum.titi		)

       snake_case					:   str         =					parser.parse_args(["--foo", "42"]		)
       self.assertEqual(args.foo		,			42		)
       snake_case					:   List[Any]         =					parser.parse_args_into_dataclasses(["--foo", "42"]		)[0]
       self.assertEqual(enum_ex.foo		,			MixedTypeEnum.fourtytwo		)







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       @dataclass
       class _lowerCAmelCase       :
          __UpperCAmelCase				: Union[str, Any]													=						'''toto'''



       snake_case					:   Tuple         =					HfArgumentParser(_A		)

       snake_case					:   Any         =					argparse.ArgumentParser()
       expected.add_argument(
           "--foo"		,			default="toto"		,			choices=("titi", "toto", 42)		,			type=make_choice_type_function(["titi", "toto", 42]		)		,			)
       self.argparsersEqual(_A		,			_A		)

       snake_case					:   Optional[Any]         =					parser.parse_args([]		)
       self.assertEqual(args.foo		,			"toto"		)

       snake_case					:   Dict         =					parser.parse_args(["--foo", "titi"]		)
       self.assertEqual(args.foo		,			"titi"		)

       snake_case					:   str         =					parser.parse_args(["--foo", "42"]		)
       self.assertEqual(args.foo		,			42		)







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       snake_case					:   Union[str, Any]         =					HfArgumentParser(_A		)

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

       self.argparsersEqual(_A		,			_A		)

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

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







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

       '''simple docstring'''




       snake_case					:   Tuple         =					argparse.ArgumentParser()
       expected.add_argument("--foo"		,			default=_A		,			type=_A		)
       expected.add_argument("--bar"		,			default=_A		,			type=_A		,			help="help message"		)
       expected.add_argument("--baz"		,			default=_A		,			type=_A		)
       expected.add_argument("--ces"		,			nargs="+"		,			default=[]		,			type=_A		)
       expected.add_argument("--des"		,			nargs="+"		,			default=[]		,			type=_A		)

       snake_case					:   List[Any]         =					[OptionalExample]
       if is_python_no_less_than_3_10:
           dataclass_types.append(_A		)

       for dataclass_type in dataclass_types:
           snake_case					:   Tuple         =					HfArgumentParser(_A		)

           self.argparsersEqual(_A		,			_A		)

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

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







   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       snake_case					:   str         =					HfArgumentParser(_A		)

       snake_case					:   Optional[Any]         =					argparse.ArgumentParser()
       expected.add_argument("--required_list"		,			nargs="+"		,			type=_A		,			required=_A		)
       expected.add_argument("--required_str"		,			type=_A		,			required=_A		)
       expected.add_argument(
           "--required_enum"		,			type=make_choice_type_function(["titi", "toto"]		)		,			choices=["titi", "toto"]		,			required=_A		,			)
       self.argparsersEqual(_A		,			_A		)







   def 				lowerCamelCase	(			self		)			->	List[str]:

       '''simple docstring'''




       snake_case					:   int         =					HfArgumentParser(_A		)

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







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

       '''simple docstring'''




       snake_case					:   List[Any]         =					HfArgumentParser(_A		)

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

       snake_case					:   List[str]         =					parser.parse_dict(_A		)[0]
       snake_case					:   Optional[int]         =					BasicExample(**_A		)
       self.assertEqual(_A		,			_A		)







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

       '''simple docstring'''




       snake_case					:   Optional[Any]         =					HfArgumentParser(_A		)

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

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







   def 				lowerCamelCase	(			self		)			->	List[str]:

       '''simple docstring'''




       snake_case					:   List[Any]         =					HfArgumentParser(_A		)

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

       snake_case					:   Dict         =					BasicExample(**_A		)
       self.assertEqual(_A		,			_A		)







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

       '''simple docstring'''




       snake_case					:   str         =					HfArgumentParser(_A		)

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







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

       '''simple docstring'''




       snake_case					:   int         =					HfArgumentParser(_A		)
       self.assertIsNotNone(_A		)









"""simple docstring"""



import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
  from transformers.models.roberta.modeling_flax_roberta import (
      FlaxRobertaForCausalLM,
      FlaxRobertaForMaskedLM,
      FlaxRobertaForMultipleChoice,
      FlaxRobertaForQuestionAnswering,
      FlaxRobertaForSequenceClassification,
      FlaxRobertaForTokenClassification,
      FlaxRobertaModel,
  )







class _lowerCAmelCase       (   unittest.TestCase			):







   def __init__(			self		,			UpperCamelCase__		,			UpperCamelCase__=13		,			UpperCamelCase__=7		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=99		,			UpperCamelCase__=32		,			UpperCamelCase__=5		,			UpperCamelCase__=4		,			UpperCamelCase__=37		,			UpperCamelCase__="gelu"		,			UpperCamelCase__=0.1		,			UpperCamelCase__=0.1		,			UpperCamelCase__=512		,			UpperCamelCase__=16		,			UpperCamelCase__=2		,			UpperCamelCase__=0.02		,			UpperCamelCase__=4		,			)			->	Dict:

       '''simple docstring'''




       snake_case					:   Any         =					parent
       snake_case					:   int         =					batch_size
       snake_case					:   Optional[Any]         =					seq_length
       snake_case					:   Dict         =					is_training
       snake_case					:   str         =					use_attention_mask
       snake_case					:   List[Any]         =					use_token_type_ids
       snake_case					:   Tuple         =					use_labels
       snake_case					:   str         =					vocab_size
       snake_case					:   Optional[Any]         =					hidden_size
       snake_case					:   Optional[Any]         =					num_hidden_layers
       snake_case					:   Dict         =					num_attention_heads
       snake_case					:   int         =					intermediate_size
       snake_case					:   Union[str, Any]         =					hidden_act
       snake_case					:   Optional[Any]         =					hidden_dropout_prob
       snake_case					:   int         =					attention_probs_dropout_prob
       snake_case					:   Optional[int]         =					max_position_embeddings
       snake_case					:   Dict         =					type_vocab_size
       snake_case					:   str         =					type_sequence_label_size
       snake_case					:   List[Any]         =					initializer_range
       snake_case					:   Dict         =					num_choices







   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       snake_case					:   Optional[int]         =					ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size		)

       snake_case					:   Optional[int]         =					None
       if self.use_attention_mask:
           snake_case					:   Optional[Any]         =					random_attention_mask([self.batch_size, self.seq_length]		)

       snake_case					:   List[Any]         =					None
       if self.use_token_type_ids:
           snake_case					:   Dict         =					ids_tensor([self.batch_size, self.seq_length]		,			self.type_vocab_size		)

       snake_case					:   Union[str, Any]         =					RobertaConfig(
           vocab_size=self.vocab_size		,			hidden_size=self.hidden_size		,			num_hidden_layers=self.num_hidden_layers		,			num_attention_heads=self.num_attention_heads		,			intermediate_size=self.intermediate_size		,			hidden_act=self.hidden_act		,			hidden_dropout_prob=self.hidden_dropout_prob		,			attention_probs_dropout_prob=self.attention_probs_dropout_prob		,			max_position_embeddings=self.max_position_embeddings		,			type_vocab_size=self.type_vocab_size		,			is_decoder=UpperCamelCase__		,			initializer_range=self.initializer_range		,			)

       return config, input_ids, token_type_ids, attention_mask







   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       snake_case					:   List[str]         =					self.prepare_config_and_inputs()
       snake_case      ,snake_case      ,snake_case      ,snake_case					:   List[Any]         =					config_and_inputs
       snake_case					:   Tuple         =					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
       return config, inputs_dict







   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       snake_case					:   List[str]         =					self.prepare_config_and_inputs()
       snake_case      ,snake_case      ,snake_case      ,snake_case					:   List[Any]         =					config_and_inputs

       snake_case					:   int         =					True
       snake_case					:   Optional[int]         =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]		)
       snake_case					:   Optional[Any]         =					ids_tensor([self.batch_size, self.seq_length]		,			vocab_size=2		)

       return (
           config,
           input_ids,
           token_type_ids,
           encoder_hidden_states,
           encoder_attention_mask,
       )







@require_flax
class _lowerCAmelCase       (   snake_case_					,							unittest.TestCase			):
   __UpperCAmelCase				: int													=						True

   __UpperCAmelCase				: Optional[Any]													=						(
       (
           FlaxRobertaModel,
           FlaxRobertaForCausalLM,
           FlaxRobertaForMaskedLM,
           FlaxRobertaForSequenceClassification,
           FlaxRobertaForTokenClassification,
           FlaxRobertaForMultipleChoice,
           FlaxRobertaForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )







   def 				lowerCamelCase	(			self		)			->	Dict:

       '''simple docstring'''




       snake_case					:   Dict         =					FlaxRobertaModelTester(self		)







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

       '''simple docstring'''




       for model_class_name in self.all_model_classes:
           snake_case					:   Dict         =					model_class_name.from_pretrained("roberta-base"		,			from_pt=UpperCamelCase__		)
           snake_case					:   List[str]         =					model(np.ones((1, 1)		)		)
           self.assertIsNotNone(UpperCamelCase__		)





