"""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
_a				:		Optional[Any]	   =       sys.version_info >= (3, 10)





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	int=None      ,_lowerCamelCase						:	Union[str, Any]=None     )	->				int:
  return field(default_factory=lambda: default      ,metadata=_lowerCamelCase     )
@dataclass
class 						__A							:
     _UpperCamelCase							:      int
     _UpperCamelCase							:      float
     _UpperCamelCase							:      str
     _UpperCamelCase							:      bool







@dataclass
class 						__A							:
     _UpperCamelCase							:      int		 =		42
     _UpperCamelCase							:      str		 =		field(default="toto"   ,     metadata={"help": "help message"}		)







@dataclass
class 						__A							:
     _UpperCamelCase							:      bool		 =		False
     _UpperCamelCase							:      bool		 =		True
     _UpperCamelCase							:      Optional[bool]		 =		None







class 						__A							(			SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		"titi"
     _UpperCamelCase							:      List[str]		 =		"toto"







class 						__A							(			SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[str]		 =		"titi"
     _UpperCamelCase							:      Dict		 =		"toto"
     _UpperCamelCase							:      Tuple		 =		42







@dataclass
class 						__A							:
     _UpperCamelCase							:      BasicEnum		 =		"toto"






     def    __A  (		self  ):
       _lowerCAmelCase						:	Union[str, Any]        =					BasicEnum(self.foo  )







@dataclass
class 						__A							:
     _UpperCamelCase							:      MixedTypeEnum		 =		"toto"






     def    __A  (		self  ):
       _lowerCAmelCase						:	Tuple        =					MixedTypeEnum(self.foo  )







@dataclass
class 						__A							:
     _UpperCamelCase							:      Optional[int]		 =		None
     _UpperCamelCase							:      Optional[float]		 =		field(default=SCREAMING_SNAKE_CASE_   ,     metadata={"help": "help message"}		)
     _UpperCamelCase							:      Optional[str]		 =		None
     _UpperCamelCase							:      Optional[List[str]]		 =		list_field(default=[]		)
     _UpperCamelCase							:      Optional[List[int]]		 =		list_field(default=[]		)







@dataclass
class 						__A							:
     _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 						__A							:
     _UpperCamelCase							:      List[int]		 =		field()
     _UpperCamelCase							:      str		 =		field()
     _UpperCamelCase							:      BasicEnum		 =		field()






     def    __A  (		self  ):
       _lowerCAmelCase						:	Dict        =					BasicEnum(self.required_enum  )







@dataclass
class 						__A							:
     _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 						__A							:
          _UpperCamelCase							:      bool		 =		False
          _UpperCamelCase							:      bool		 =		True
          _UpperCamelCase							:      bool | None		 =		None







     @dataclass
     class 						__A							:
          _UpperCamelCase							:      int | None		 =		None
          _UpperCamelCase							:      float | None		 =		field(default=SCREAMING_SNAKE_CASE_   ,     metadata={"help": "help message"}		)
          _UpperCamelCase							:      str | None		 =		None
          _UpperCamelCase							:      list[str] | None		 =		list_field(default=[]		)
          _UpperCamelCase							:      list[int] | None		 =		list_field(default=[]		)






class 						__A							(			unittest.TestCase		):






     def    __A  (		self    ,					a__    ,					a__  ):
       self.assertEqual(len(a._actions  )    ,					len(b._actions  )  )
       for x, y in zip(a._actions    ,					b._actions  ):
         _lowerCAmelCase						:	Optional[Any]        =					{k: v for k, v in vars(a__  ).items() if k != """container"""}
         _lowerCAmelCase						:	Optional[int]        =					{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    __A  (		self  ):
       _lowerCAmelCase						:	Optional[Any]        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	Union[str, Any]        =					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__  )

       _lowerCAmelCase						:	Dict        =					["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
       ((_lowerCAmelCase)      ,     )						:	Optional[Any]        =					parser.parse_args_into_dataclasses(a__    ,					look_for_args_file=a__  )
       self.assertFalse(example.flag  )






     def    __A  (		self  ):
       _lowerCAmelCase						:	Dict        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	int        =					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    __A  (		self  ):
       _lowerCAmelCase						:	Dict        =					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__  )

       _lowerCAmelCase						:	Optional[int]        =					[WithDefaultBoolExample]
       if is_python_no_less_than_3_10:
         dataclass_types.append(a__  )

       for dataclass_type in dataclass_types:
         _lowerCAmelCase						:	str        =					HfArgumentParser(a__  )
         self.argparsersEqual(a__    ,					a__  )

         _lowerCAmelCase						:	Optional[int]        =					parser.parse_args([]  )
         self.assertEqual(a__    ,					Namespace(foo=a__    ,					baz=a__    ,					opt=a__  )  )

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

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

         _lowerCAmelCase						:	Optional[int]        =					parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]  )
         self.assertEqual(a__    ,					Namespace(foo=a__    ,					baz=a__    ,					opt=a__  )  )

         _lowerCAmelCase						:	Union[str, Any]        =					parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]  )
         self.assertEqual(a__    ,					Namespace(foo=a__    ,					baz=a__    ,					opt=a__  )  )






     def    __A  (		self  ):
       _lowerCAmelCase						:	List[Any]        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	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__  )

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

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

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






     def    __A  (		self  ):
       @dataclass
       class 						__A							:
            _UpperCamelCase							:      Literal["titi", "toto", 42]		 =		"toto"







       _lowerCAmelCase						:	Optional[int]        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	List[str]        =					argparse.ArgumentParser()
       expected.add_argument(
           """--foo"""    ,					default="""toto"""    ,					choices=("""titi""", """toto""", 42)    ,					type=make_choice_type_function(["""titi""", """toto""", 42]  )    ,					)
       self.argparsersEqual(a__    ,					a__  )

       _lowerCAmelCase						:	int        =					parser.parse_args([]  )
       self.assertEqual(args.foo    ,					"""toto"""  )

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

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






     def    __A  (		self  ):
       _lowerCAmelCase						:	Optional[int]        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	Optional[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__  )

       _lowerCAmelCase						:	Any        =					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]  )    ,					)

       _lowerCAmelCase						:	Optional[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    __A  (		self  ):
       _lowerCAmelCase						:	str        =					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__  )

       _lowerCAmelCase						:	List[str]        =					[OptionalExample]
       if is_python_no_less_than_3_10:
         dataclass_types.append(a__  )

       for dataclass_type in dataclass_types:
         _lowerCAmelCase						:	List[Any]        =					HfArgumentParser(a__  )

         self.argparsersEqual(a__    ,					a__  )

         _lowerCAmelCase						:	Any        =					parser.parse_args([]  )
         self.assertEqual(a__    ,					Namespace(foo=a__    ,					bar=a__    ,					baz=a__    ,					ces=[]    ,					des=[]  )  )

         _lowerCAmelCase						:	Optional[int]        =					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.1_4    ,					baz="""42"""    ,					ces=["""a""", """b""", """c"""]    ,					des=[1, 2, 3]  )  )






     def    __A  (		self  ):
       _lowerCAmelCase						:	int        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	Union[str, 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    __A  (		self  ):
       _lowerCAmelCase						:	Optional[int]        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	Optional[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    __A  (		self  ):
       _lowerCAmelCase						:	Dict        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	List[Any]        =					{
           """foo""": 12,
           """bar""": 3.1_4,
           """baz""": """42""",
           """flag""": True,
       }

       _lowerCAmelCase						:	Dict        =					parser.parse_dict(a__  )[0]
       _lowerCAmelCase						:	List[Any]        =					BasicExample(**a__  )
       self.assertEqual(a__    ,					a__  )






     def    __A  (		self  ):
       _lowerCAmelCase						:	Dict        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	Optional[int]        =					{
           """foo""": 12,
           """bar""": 3.1_4,
           """baz""": """42""",
           """flag""": True,
           """extra""": 42,
       }

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






     def    __A  (		self  ):
       _lowerCAmelCase						:	Tuple        =					HfArgumentParser(a__  )

       _lowerCAmelCase						:	str        =					{
           """foo""": 12,
           """bar""": 3.1_4,
           """baz""": """42""",
           """flag""": True,
       }
       with tempfile.TemporaryDirectory() as tmp_dir:
         _lowerCAmelCase						:	Any        =					os.path.join(a__    ,					"""temp_json"""  )
         os.mkdir(a__  )
         with open(temp_local_path + """.json"""    ,					"""w+"""  ) as f:
           json.dump(a__    ,					a__  )
         _lowerCAmelCase						:	Optional[Any]        =					parser.parse_yaml_file(Path(temp_local_path + """.json"""  )  )[0]

       _lowerCAmelCase						:	Tuple        =					BasicExample(**a__  )
       self.assertEqual(a__    ,					a__  )






     def    __A  (		self  ):
       _lowerCAmelCase						:	Tuple        =					HfArgumentParser(a__  )

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






     def    __A  (		self  ):
       _lowerCAmelCase						:	int        =					HfArgumentParser(a__  )
       self.assertIsNotNone(a__  )





"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


_a				:		Any	   =       logging.get_logger(__name__)

_a				:		Any	   =       {
    'uclanlp/visualbert-vqa': 'https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json',
    'uclanlp/visualbert-vqa-pre': 'https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json',
    'uclanlp/visualbert-vqa-coco-pre': (
        'https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json'
    ),
    'uclanlp/visualbert-vcr': 'https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json',
    'uclanlp/visualbert-vcr-pre': 'https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json',
    'uclanlp/visualbert-vcr-coco-pre': (
        'https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json'
    ),
    'uclanlp/visualbert-nlvr2': 'https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json',
    'uclanlp/visualbert-nlvr2-pre': 'https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json',
    'uclanlp/visualbert-nlvr2-coco-pre': (
        'https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json'
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}
class 						__A							(			SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		"visual_bert"






     def __init__(		self    ,					a__=30522    ,					a__=768    ,					a__=512    ,					a__=12    ,					a__=12    ,					a__=3072    ,					a__="gelu"    ,					a__=0.1    ,					a__=0.1    ,					a__=512    ,					a__=2    ,					a__=0.0_2    ,					a__=1e-12    ,					a__=False    ,					a__=True    ,					a__=1    ,					a__=0    ,					a__=2    ,					**a__    ,					):
       super().__init__(pad_token_id=a__    ,					bos_token_id=a__    ,					eos_token_id=a__    ,					**a__  )

       _lowerCAmelCase						:	Optional[Any]        =					vocab_size
       _lowerCAmelCase						:	int        =					max_position_embeddings
       _lowerCAmelCase						:	Optional[Any]        =					hidden_size
       _lowerCAmelCase						:	Optional[int]        =					visual_embedding_dim
       _lowerCAmelCase						:	Optional[int]        =					num_hidden_layers
       _lowerCAmelCase						:	List[Any]        =					num_attention_heads
       _lowerCAmelCase						:	Any        =					intermediate_size
       _lowerCAmelCase						:	List[Any]        =					hidden_act
       _lowerCAmelCase						:	int        =					hidden_dropout_prob
       _lowerCAmelCase						:	Optional[Any]        =					attention_probs_dropout_prob
       _lowerCAmelCase						:	Any        =					initializer_range
       _lowerCAmelCase						:	List[Any]        =					type_vocab_size
       _lowerCAmelCase						:	Union[str, Any]        =					layer_norm_eps
       _lowerCAmelCase						:	Optional[Any]        =					bypass_transformer
       _lowerCAmelCase						:	List[Any]        =					special_visual_initialize




