


'''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__  :					Any        =       sys.version_info >= (3, 1_0)







def _UpperCamelCase       (     __A=None      ,			__A=None    )							->		Optional[int]:


      '''simple docstring'''



      return field(default_factory=lambda: default      ,			metadata=__A    )
@dataclass
class 					lowercase_     :
    __UpperCAmelCase   			=	42
    __UpperCAmelCase   			=	42
    __UpperCAmelCase   			=	42
    __UpperCAmelCase   			=	42

@dataclass
class 					lowercase_     :
    __UpperCAmelCase   			=	42
    __UpperCAmelCase   			=	field(default='toto'  ,						metadata={'help': 'help message'}   )

@dataclass
class 					lowercase_     :
    __UpperCAmelCase   			=	False
    __UpperCAmelCase   			=	True
    __UpperCAmelCase   			=	None

class 					lowercase_     (    a__   ):
    __UpperCAmelCase   			=	'titi'
    __UpperCAmelCase   			=	'toto'

class 					lowercase_     (    a__   ):
    __UpperCAmelCase   			=	'titi'
    __UpperCAmelCase   			=	'toto'
    __UpperCAmelCase   			=	42

@dataclass
class 					lowercase_     :
    __UpperCAmelCase   			=	"toto"


    def    __a							(     self    ):
          UpperCamelCase__										=				BasicEnum(self.foo    )

@dataclass
class 					lowercase_     :
    __UpperCAmelCase   			=	"toto"


    def    __a							(     self    ):
          UpperCamelCase__										=				MixedTypeEnum(self.foo    )

@dataclass
class 					lowercase_     :
    __UpperCAmelCase   			=	None
    __UpperCAmelCase   			=	field(default=a__  ,						metadata={'help': 'help message'}   )
    __UpperCAmelCase   			=	None
    __UpperCAmelCase   			=	list_field(default=[]   )
    __UpperCAmelCase   			=	list_field(default=[]   )

@dataclass
class 					lowercase_     :
    __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_     :
    __UpperCAmelCase   			=	field()
    __UpperCAmelCase   			=	field()
    __UpperCAmelCase   			=	field()


    def    __a							(     self    ):
          UpperCamelCase__										=				BasicEnum(self.required_enum    )

@dataclass
class 					lowercase_     :
    __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_     :
      __UpperCAmelCase   			=	False
      __UpperCAmelCase   			=	True
      __UpperCAmelCase   			=	None

  @dataclass
  class 					lowercase_     :
      __UpperCAmelCase   			=	None
      __UpperCAmelCase   			=	field(default=a__  ,						metadata={'help': 'help message'}   )
      __UpperCAmelCase   			=	None
      __UpperCAmelCase   			=	list_field(default=[]   )
      __UpperCAmelCase   			=	list_field(default=[]   )



class 					lowercase_     (    unittest.TestCase   ):


    def    __a							(     self  ,					a  ,					a    ):
          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(a    ).items() if k != "container"}
                UpperCamelCase__										=				{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    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				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    )

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


    def    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				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    ):
          UpperCamelCase__										=				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    )

          UpperCamelCase__										=				[WithDefaultBoolExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(a    )

          for dataclass_type in dataclass_types:
                UpperCamelCase__										=				HfArgumentParser(a    )
                self.argparsersEqual(a  ,					a    )

                UpperCamelCase__										=				parser.parse_args([]    )
                self.assertEqual(a  ,					Namespace(foo=a  ,					baz=a  ,					opt=a    )    )

                UpperCamelCase__										=				parser.parse_args(["--foo", "--no_baz"]    )
                self.assertEqual(a  ,					Namespace(foo=a  ,					baz=a  ,					opt=a    )    )

                UpperCamelCase__										=				parser.parse_args(["--foo", "--baz"]    )
                self.assertEqual(a  ,					Namespace(foo=a  ,					baz=a  ,					opt=a    )    )

                UpperCamelCase__										=				parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]    )
                self.assertEqual(a  ,					Namespace(foo=a  ,					baz=a  ,					opt=a    )    )

                UpperCamelCase__										=				parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]    )
                self.assertEqual(a  ,					Namespace(foo=a  ,					baz=a  ,					opt=a    )    )


    def    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				argparse.ArgumentParser()
          expected.add_argument(
              "--foo"  ,					default="toto"  ,					choices=["titi", "toto", 42]  ,					type=make_choice_type_function(["titi", "toto", 42]    )  ,					)
          self.argparsersEqual(a  ,					a    )

          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    __a							(     self    ):
          @dataclass
          class 					lowercase_     :
              __UpperCAmelCase   			=	"toto"

          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				argparse.ArgumentParser()
          expected.add_argument(
              "--foo"  ,					default="toto"  ,					choices=("titi", "toto", 42)  ,					type=make_choice_type_function(["titi", "toto", 42]    )  ,					)
          self.argparsersEqual(a  ,					a    )

          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    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				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    )

          UpperCamelCase__										=				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]    )  ,					)

          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(a  ,					Namespace(foo_int=[1]  ,					bar_int=[2, 3]  ,					foo_str=["a", "b", "c"]  ,					foo_float=[0.1, 0.7]    )    )


    def    __a							(     self    ):
          UpperCamelCase__										=				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    )

          UpperCamelCase__										=				[OptionalExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(a    )

          for dataclass_type in dataclass_types:
                UpperCamelCase__										=				HfArgumentParser(a    )

                self.argparsersEqual(a  ,					a    )

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

                UpperCamelCase__										=				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    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				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    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

          UpperCamelCase__										=				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    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

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

          UpperCamelCase__										=				parser.parse_dict(a    )[0]
          UpperCamelCase__										=				BasicExample(**a    )
          self.assertEqual(a  ,					a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

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

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


    def    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

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

          UpperCamelCase__										=				BasicExample(**a    )
          self.assertEqual(a  ,					a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )

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


    def    __a							(     self    ):
          UpperCamelCase__										=				HfArgumentParser(a    )
          self.assertIsNotNone(a    )









from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_A		       =						logging.get_logger(__name__)

_A		       =						{
    'hustvl/yolos-small': 'https://huggingface.co/hustvl/yolos-small/resolve/main/config.json',
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}






class     UpperCAmelCase__       (					A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Optional[int]      =  "yolos"






    def __init__(			self					,   A_=768					,   A_=12					,   A_=12					,   A_=3072					,   A_="gelu"					,   A_=0.0					,   A_=0.0					,   A_=0.02					,   A_=1E-12					,   A_=[512, 864]					,   A_=16					,   A_=3					,   A_=True					,   A_=100					,   A_=True					,   A_=False					,   A_=1					,   A_=5					,   A_=2					,   A_=5					,   A_=2					,   A_=0.1					,   **A_					,   )  ->       Any:
         super().__init__(**A_    )

         __UpperCamelCase    							=hidden_size
         __UpperCamelCase    							=num_hidden_layers
         __UpperCamelCase    							=num_attention_heads
         __UpperCamelCase    							=intermediate_size
         __UpperCamelCase    							=hidden_act
         __UpperCamelCase    							=hidden_dropout_prob
         __UpperCamelCase    							=attention_probs_dropout_prob
         __UpperCamelCase    							=initializer_range
         __UpperCamelCase    							=layer_norm_eps
         __UpperCamelCase    							=image_size
         __UpperCamelCase    							=patch_size
         __UpperCamelCase    							=num_channels
         __UpperCamelCase    							=qkv_bias
         __UpperCamelCase    							=num_detection_tokens
         __UpperCamelCase    							=use_mid_position_embeddings
         __UpperCamelCase    							=auxiliary_loss
         # Hungarian matcher
         __UpperCamelCase    							=class_cost
         __UpperCamelCase    							=bbox_cost
         __UpperCamelCase    							=giou_cost
         # Loss coefficients
         __UpperCamelCase    							=bbox_loss_coefficient
         __UpperCamelCase    							=giou_loss_coefficient
         __UpperCamelCase    							=eos_coefficient






class     UpperCAmelCase__       (					A_		):



    """simple docstring"""






    UpperCAmelCase__						:		str      =  version.parse("1.11"		)






    @property
    def _a					(			self    )  ->       Mapping[str, Mapping[int, str]]:
         return OrderedDict(
             [
                 ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
             ]    )






    @property
    def _a					(			self    )  ->       float:
         return 1E-4






    @property
    def _a					(			self    )  ->       int:
         return 12





