






"""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 		__lowerCamelCase	(  __UpperCamelCase=None      ,       __UpperCamelCase=None       )						->    Tuple:

		"""simple docstring"""







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


@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






		a_	:				int
		a_	:				float
		a_	:				str
		a_	:				bool







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






		a_	:				int            =							42
		a_	:				str            =							field(default="""toto""" ,							metadata={"""help""": """help message"""}			)







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






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







class 		__lowerCamelCase				( A__			):





		'''simple docstring'''






		a_	:				Optional[Any]            =							"titi"
		a_	:				Dict            =							"toto"







class 		__lowerCamelCase				( A__			):





		'''simple docstring'''






		a_	:				Optional[Any]            =							"titi"
		a_	:				str            =							"toto"
		a_	:				Tuple            =							42







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






		a_	:				BasicEnum            =							"toto"





		def    lowerCamelCase       (   self							:	Dict	):
				lowerCAmelCase_   :							List[Any]									=			BasicEnum(self.foo	)







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






		a_	:				MixedTypeEnum            =							"toto"





		def    lowerCamelCase       (   self							:	Optional[int]	):
				lowerCAmelCase_   :							List[Any]									=			MixedTypeEnum(self.foo	)







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






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







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






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







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






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





		def    lowerCamelCase       (   self							:	List[str]	):
				lowerCAmelCase_   :							List[Any]									=			BasicEnum(self.required_enum	)







@dataclass
class 		__lowerCamelCase				:





		'''simple docstring'''






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


if is_python_no_less_than_3_10:


					@dataclass
					class 		__lowerCamelCase				:





							'''simple docstring'''






							a_	:				bool            =							False
							a_	:				bool            =							True
							a_	:				bool | None            =							None







					@dataclass
					class 		__lowerCamelCase				:





							'''simple docstring'''






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



class 		__lowerCamelCase				( unittest.TestCase			):





		'''simple docstring'''






		def    lowerCamelCase       (   self							:	Dict						,			a_							:	int						,			a_							:	List[str]	):
				self.assertEqual(len(a._actions	)						,			len(b._actions	)	)
				for x, y in zip(a._actions						,			b._actions	):
						lowerCAmelCase_   :							Any									=			{k: v for k, v in vars(a_	).items() if k != """container"""}
						lowerCAmelCase_   :							str									=			{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	):
				lowerCAmelCase_   :							Tuple									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							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_	)

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





		def    lowerCamelCase       (   self							:	List[str]	):
				lowerCAmelCase_   :							Union[str, Any]									=			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    lowerCamelCase       (   self							:	Optional[int]	):
				lowerCAmelCase_   :							int									=			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_   :							Union[str, Any]									=			[WithDefaultBoolExample]
				if is_python_no_less_than_3_10:
						dataclass_types.append(a_	)

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

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

						lowerCAmelCase_   :							int									=			parser.parse_args(["--foo", "--no_baz"]	)
						self.assertEqual(a_						,			Namespace(foo=a_						,			baz=a_						,			opt=a_	)	)

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

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

						lowerCAmelCase_   :							Dict									=			parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]	)
						self.assertEqual(a_						,			Namespace(foo=a_						,			baz=a_						,			opt=a_	)	)





		def    lowerCamelCase       (   self							:	int	):
				lowerCAmelCase_   :							Optional[Any]									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							List[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_	)

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

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

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





		def    lowerCamelCase       (   self							:	Optional[Any]	):


				@dataclass
				class 		__lowerCamelCase				:





						'''simple docstring'''






						a_	:				Literal["titi", "toto", 42]            =							"toto"







				lowerCAmelCase_   :							Union[str, Any]									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							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_	)

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

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

				lowerCAmelCase_   :							Optional[Any]									=			parser.parse_args(["--foo", "42"]	)
				self.assertEqual(args.foo						,			42	)





		def    lowerCamelCase       (   self							:	Optional[Any]	):
				lowerCAmelCase_   :							str									=			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_   :							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]	)						,			)

				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    lowerCamelCase       (   self							:	Union[str, Any]	):
				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[Any]									=			[OptionalExample]
				if is_python_no_less_than_3_10:
						dataclass_types.append(a_	)

				for dataclass_type in dataclass_types:
						lowerCAmelCase_   :							Union[str, Any]									=			HfArgumentParser(a_	)

						self.argparsersEqual(a_						,			a_	)

						lowerCAmelCase_   :							Optional[int]									=			parser.parse_args([]	)
						self.assertEqual(a_						,			Namespace(foo=a_						,			bar=a_						,			baz=a_						,			ces=[]						,			des=[]	)	)

						lowerCAmelCase_   :							Any									=			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							:	int	):
				lowerCAmelCase_   :							Dict									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							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							:	str	):
				lowerCAmelCase_   :							str									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							Union[str, 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]	):
				lowerCAmelCase_   :							Dict									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							List[str]									=			{
				    """foo""": 12,
				    """bar""": 3.14,
				    """baz""": """42""",
				    """flag""": True,
				}

				lowerCAmelCase_   :							Dict									=			parser.parse_dict(a_	)[0]
				lowerCAmelCase_   :							Any									=			BasicExample(**a_	)
				self.assertEqual(a_						,			a_	)





		def    lowerCamelCase       (   self							:	Optional[Any]	):
				lowerCAmelCase_   :							Optional[int]									=			HfArgumentParser(a_	)

				lowerCAmelCase_   :							Optional[Any]									=			{
				    """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							:	Dict	):
				lowerCAmelCase_   :							List[Any]									=			HfArgumentParser(a_	)

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

				lowerCAmelCase_   :							Any									=			BasicExample(**a_	)
				self.assertEqual(a_						,			a_	)





		def    lowerCamelCase       (   self							:	Any	):
				lowerCAmelCase_   :							int									=			HfArgumentParser(a_	)

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





		def    lowerCamelCase       (   self							:	List[str]	):
				lowerCAmelCase_   :							Any									=			HfArgumentParser(a_	)
				self.assertIsNotNone(a_	)


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


lowercase  :					List[str]						    =							logging.get_logger(__name__)

lowercase  :					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 __snake_case		(      lowerCAmelCase     ):
    _a		:						Union[str, Any]=				"visual_bert"
    def __init__(  self		,snake_case=30522		,snake_case=768		,snake_case=512		,snake_case=12		,snake_case=12		,snake_case=3072		,snake_case="gelu"		,snake_case=0.1		,snake_case=0.1		,snake_case=512		,snake_case=2		,snake_case=0.02		,snake_case=1e-12		,snake_case=False		,snake_case=True		,snake_case=1		,snake_case=0		,snake_case=2		,**snake_case		,):



           '''simple docstring'''







           super().__init__(pad_token_id=snake_case		,bos_token_id=snake_case		,eos_token_id=snake_case		,**snake_case      )

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