

"""simple docstring"""

import argparse
import json

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image
from torchvision import transforms

from transformers import BitImageProcessor, FocalNetConfig, FocalNetForImageClassification
from transformers.image_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, PILImageResampling



def       SCREAMING_SNAKE_CASE							( lowercase__   )			->						Any:
 lowerCAmelCase__   :				Optional[Any] 			=				[2, 2, 6, 2] if "tiny" in model_name else [2, 2, 1_8, 2]
 lowerCAmelCase__   :				Any 			=				True if "large" in model_name or "huge" in model_name else False
 lowerCAmelCase__   :				Optional[Any] 			=				True if "large" in model_name or "huge" in model_name else False
 lowerCAmelCase__   :				List[str] 			=				True if "large" in model_name or "huge" in model_name else False

 if "large" in model_name or "xlarge" in model_name or "huge" in model_name:
  if "fl3" in model_name:
   lowerCAmelCase__   :				int 			=				[3, 3, 3, 3]
   lowerCAmelCase__   :				List[str] 			=				[5, 5, 5, 5]
  elif "fl4" in model_name:
   lowerCAmelCase__   :				Tuple 			=				[4, 4, 4, 4]
   lowerCAmelCase__   :				Optional[Any] 			=				[3, 3, 3, 3]

 if "tiny" in model_name or "small" in model_name or "base" in model_name:
  lowerCAmelCase__   :				Tuple 			=				[3, 3, 3, 3]
  if "lrf" in model_name:
   lowerCAmelCase__   :				str 			=				[3, 3, 3, 3]
  else:
   lowerCAmelCase__   :				Any 			=				[2, 2, 2, 2]

 if "tiny" in model_name:
  lowerCAmelCase__   :				Optional[int] 			=				9_6
 elif "small" in model_name:
  lowerCAmelCase__   :				Tuple 			=				9_6
 elif "base" in model_name:
  lowerCAmelCase__   :				Optional[int] 			=				1_2_8
 elif "large" in model_name:
  lowerCAmelCase__   :				List[Any] 			=				1_9_2
 elif "xlarge" in model_name:
  lowerCAmelCase__   :				str 			=				2_5_6
 elif "huge" in model_name:
  lowerCAmelCase__   :				int 			=				3_5_2

 # set label information
 lowerCAmelCase__   :				Optional[int] 			=				"huggingface/label-files"
 if "large" in model_name or "huge" in model_name:
  lowerCAmelCase__   :				Dict 			=				"imagenet-22k-id2label.json"
 else:
  lowerCAmelCase__   :				List[Any] 			=				"imagenet-1k-id2label.json"

 lowerCAmelCase__   :				int 			=				json.load(open(hf_hub_download(lowercase__					,					lowercase__					,					repo_type="dataset"   )					,					"r"   )   )
 lowerCAmelCase__   :				Optional[Any] 			=				{int(lowercase__   ): v for k, v in idalabel.items()}
 lowerCAmelCase__   :				Dict 			=				{v: k for k, v in idalabel.items()}

 lowerCAmelCase__   :				List[str] 			=				FocalNetConfig(
     embed_dim=lowercase__					,					depths=lowercase__					,					focal_levels=lowercase__					,					focal_windows=lowercase__					,					use_conv_embed=lowercase__					,					idalabel=lowercase__					,					labelaid=lowercase__					,					use_post_layernorm=lowercase__					,					use_layerscale=lowercase__					,					)

 return config



def       SCREAMING_SNAKE_CASE							( lowercase__   )			->						int:
 if "patch_embed.proj" in name:
  lowerCAmelCase__   :				List[Any] 			=				name.replace("patch_embed.proj"					,					"embeddings.patch_embeddings.projection"   )
 if "patch_embed.norm" in name:
  lowerCAmelCase__   :				Union[str, Any] 			=				name.replace("patch_embed.norm"					,					"embeddings.norm"   )
 if "layers" in name:
  lowerCAmelCase__   :				str 			=				"encoder." + name
 if "encoder.layers" in name:
  lowerCAmelCase__   :				Tuple 			=				name.replace("encoder.layers"					,					"encoder.stages"   )
 if "downsample.proj" in name:
  lowerCAmelCase__   :				Optional[int] 			=				name.replace("downsample.proj"					,					"downsample.projection"   )
 if "blocks" in name:
  lowerCAmelCase__   :				Optional[int] 			=				name.replace("blocks"					,					"layers"   )
 if "modulation.f.weight" in name or "modulation.f.bias" in name:
  lowerCAmelCase__   :				List[Any] 			=				name.replace("modulation.f"					,					"modulation.projection_in"   )
 if "modulation.h.weight" in name or "modulation.h.bias" in name:
  lowerCAmelCase__   :				Tuple 			=				name.replace("modulation.h"					,					"modulation.projection_context"   )
 if "modulation.proj.weight" in name or "modulation.proj.bias" in name:
  lowerCAmelCase__   :				Union[str, Any] 			=				name.replace("modulation.proj"					,					"modulation.projection_out"   )

 if name == "norm.weight":
  lowerCAmelCase__   :				int 			=				"layernorm.weight"
 if name == "norm.bias":
  lowerCAmelCase__   :				int 			=				"layernorm.bias"

 if "head" in name:
  lowerCAmelCase__   :				Union[str, Any] 			=				name.replace("head"					,					"classifier"   )
 else:
  lowerCAmelCase__   :				str 			=				"focalnet." + name

 return name



def       SCREAMING_SNAKE_CASE							( lowercase__					,					lowercase__					,					lowercase__=False   )			->						str:
 # fmt: off
 lowerCAmelCase__   :				Optional[Any] 			=				{
     "focalnet-tiny": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_tiny_srf.pth",
     "focalnet-tiny-lrf": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_tiny_lrf.pth",
     "focalnet-small": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_small_srf.pth",
     "focalnet-small-lrf": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_small_lrf.pth",
     "focalnet-base": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_base_srf.pth",
     "focalnet-base-lrf": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_base_lrf.pth",
     "focalnet-large-lrf-fl3": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_large_lrf_384.pth",
     "focalnet-large-lrf-fl4": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_large_lrf_384_fl4.pth",
     "focalnet-xlarge-lrf-fl3": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_xlarge_lrf_384.pth",
     "focalnet-xlarge-lrf-fl4": "https://projects4jw.blob.core.windows.net/focalnet/release/classification/focalnet_xlarge_lrf_384_fl4.pth",
 }
 # fmt: on

 lowerCAmelCase__   :				Any 			=				model_name_to_url[model_name]
 print("Checkpoint URL: "					,					lowercase__   )
 lowerCAmelCase__   :				List[str] 			=				torch.hub.load_state_dict_from_url(lowercase__					,					map_location="cpu"   )["model"]

 # rename keys
 for key in state_dict.copy().keys():
  lowerCAmelCase__   :				Optional[int] 			=				state_dict.pop(lowercase__   )
  lowerCAmelCase__   :				Dict 			=				val

 lowerCAmelCase__   :				Optional[Any] 			=				get_focalnet_config(lowercase__   )
 lowerCAmelCase__   :				Union[str, Any] 			=				FocalNetForImageClassification(lowercase__   )
 model.eval()

 # load state dict
 model.load_state_dict(lowercase__   )

 # verify conversion
 lowerCAmelCase__   :				Optional[Any] 			=				"http://images.cocodataset.org/val2017/000000039769.jpg"

 lowerCAmelCase__   :				str 			=				BitImageProcessor(
     do_resize=lowercase__					,					size={"shortest_edge": 2_5_6}					,					resample=PILImageResampling.BILINEAR					,					do_center_crop=lowercase__					,					crop_size=2_2_4					,					do_normalize=lowercase__					,					image_mean=lowercase__					,					image_std=lowercase__					,					)
 lowerCAmelCase__   :				Dict 			=				Image.open(requests.get(lowercase__					,					stream=lowercase__   ).raw   )
 lowerCAmelCase__   :				str 			=				processor(images=lowercase__					,					return_tensors="pt"   )

 lowerCAmelCase__   :				Tuple 			=				transforms.Compose(
     [
         transforms.Resize(2_5_6   ),
         transforms.CenterCrop(2_2_4   ),
         transforms.ToTensor(),
         transforms.Normalize(mean=[0.485, 0.456, 0.406]					,					std=[0.229, 0.224, 0.225]   ),
     ]   )

 lowerCAmelCase__   :				Dict 			=				image_transforms(lowercase__   ).unsqueeze(0   )

 # verify pixel_values
 assert torch.allclose(inputs.pixel_values					,					lowercase__					,					atol=1E-4   )

 lowerCAmelCase__   :				Dict 			=				model(**lowercase__   )

 lowerCAmelCase__   :				Dict 			=				outputs.logits.argmax(-1   ).item()
 print("Predicted class:"					,					model.config.idalabel[predicted_class_idx]   )

 print("First values of logits:"					,					outputs.logits[0, :3]   )

 if model_name == "focalnet-tiny":
  lowerCAmelCase__   :				Dict 			=				torch.tensor([0.2_166, -0.4_368, 0.2_191]   )
 elif model_name == "focalnet-tiny-lrf":
  lowerCAmelCase__   :				Tuple 			=				torch.tensor([1.1_669, 0.0_125, -0.1_695]   )
 elif model_name == "focalnet-small":
  lowerCAmelCase__   :				Any 			=				torch.tensor([0.4_917, -0.0_430, 0.1_341]   )
 elif model_name == "focalnet-small-lrf":
  lowerCAmelCase__   :				int 			=				torch.tensor([-0.2_588, -0.5_342, -0.2_331]   )
 elif model_name == "focalnet-base":
  lowerCAmelCase__   :				Optional[Any] 			=				torch.tensor([-0.1_655, -0.4_090, -0.1_730]   )
 elif model_name == "focalnet-base-lrf":
  lowerCAmelCase__   :				Tuple 			=				torch.tensor([0.5_306, -0.0_483, -0.3_928]   )
 assert torch.allclose(outputs.logits[0, :3]					,					lowercase__					,					atol=1E-4   )
 print("Looks ok!"   )

 if pytorch_dump_folder_path is not None:
  print(F"""Saving model and processor of {model_name} to {pytorch_dump_folder_path}"""   )
  model.save_pretrained(lowercase__   )
  processor.save_pretrained(lowercase__   )

 if push_to_hub:
  print(F"""Pushing model and processor of {model_name} to the hub..."""   )
  model.push_to_hub(F"""{model_name}"""   )
  processor.push_to_hub(F"""{model_name}"""   )


if __name__ == "__main__":
    _UpperCamelCase		     =    argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        """--model_name""",
        default="""focalnet-tiny""",
        type=str,
        help="""Name of the FocalNet model you'd like to convert.""",
    )
    parser.add_argument(
        """--pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model directory."""
    )
    parser.add_argument(
        """--push_to_hub""",
        action="""store_true""",
        help="""Whether to push the model and processor to the hub.""",
    )

    _UpperCamelCase		     =    parser.parse_args()
    convert_focalnet_checkpoint(args.model_name, args.pytorch_dump_folder_path, args.push_to_hub)









"""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
_UpperCamelCase		     =    sys.version_info >= (3, 1_0)



def       SCREAMING_SNAKE_CASE							( lowercase__=None					,					lowercase__=None   )			->						List[Any]:
 return field(default_factory=lambda: default					,					metadata=lowercase__   )






@dataclass
class 			__a					:





       """simple docstring"""


       __UpperCamelCase					:      int
       __UpperCamelCase					:      float
       __UpperCamelCase					:      str
       __UpperCamelCase					:      bool






@dataclass
class 			__a					:





       """simple docstring"""


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






@dataclass
class 			__a					:





       """simple docstring"""


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






class 			__a					(						__magic_name__       ):





       """simple docstring"""


       __UpperCamelCase					:      List[str]    =						'titi'
       __UpperCamelCase					:      Tuple    =						'toto'






class 			__a					(						__magic_name__       ):





       """simple docstring"""


       __UpperCamelCase					:      Tuple    =						'titi'
       __UpperCamelCase					:      List[Any]    =						'toto'
       __UpperCamelCase					:      List[str]    =						42






@dataclass
class 			__a					:





       """simple docstring"""


       __UpperCamelCase					:      BasicEnum    =						"toto"






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[int] 			=				BasicEnum(self.foo   )






@dataclass
class 			__a					:





       """simple docstring"""


       __UpperCamelCase					:      MixedTypeEnum    =						"toto"






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				List[str] 			=				MixedTypeEnum(self.foo   )






@dataclass
class 			__a					:





       """simple docstring"""


       __UpperCamelCase					:      Optional[int]    =						None
       __UpperCamelCase					:      Optional[float]    =						field(default=__magic_name__       ,	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					:





       """simple docstring"""


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





       """simple docstring"""


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






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[Any] 			=				BasicEnum(self.required_enum   )






@dataclass
class 			__a					:





       """simple docstring"""


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





           """simple docstring"""


           __UpperCamelCase					:      bool    =						False
           __UpperCamelCase					:      bool    =						True
           __UpperCamelCase					:      bool | None    =						None






    @dataclass
    class 			__a					:





           """simple docstring"""


           __UpperCamelCase					:      int | None    =						None
           __UpperCamelCase					:      float | None    =						field(default=__magic_name__       ,	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       ):





       """simple docstring"""


       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case			,					snake_case   ):





        """simple docstring"""

        self.assertEqual(len(a._actions   )			,					len(b._actions   )   )
        for x, y in zip(a._actions			,					b._actions   ):
         lowerCAmelCase__   :				Union[str, Any] 			=				{k: v for k, v in vars(snake_case   ).items() if k != "container"}
         lowerCAmelCase__   :				Union[str, Any] 			=				{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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

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

        lowerCAmelCase__   :				Optional[int] 			=				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   )

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






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Tuple 			=				HfArgumentParser(snake_case   )

        lowerCAmelCase__   :				Optional[int] 			=				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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[Any] 			=				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   )

        lowerCAmelCase__   :				Optional[Any] 			=				[WithDefaultBoolExample]
        if is_python_no_less_than_3_10:
         dataclass_types.append(snake_case   )

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

         lowerCAmelCase__   :				Union[str, Any] 			=				parser.parse_args([]   )
         self.assertEqual(snake_case			,					Namespace(foo=snake_case			,					baz=snake_case			,					opt=snake_case   )   )

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

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

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

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






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Tuple 			=				HfArgumentParser(snake_case   )

        lowerCAmelCase__   :				Optional[Any] 			=				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   )

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

        lowerCAmelCase__   :				List[Any] 			=				parser.parse_args(["--foo", "titi"]   )
        self.assertEqual(args.foo			,					"titi"   )
        lowerCAmelCase__   :				Any 			=				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__   :				Tuple 			=				parser.parse_args_into_dataclasses(["--foo", "42"]   )[0]
        self.assertEqual(enum_ex.foo			,					MixedTypeEnum.fourtytwo   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        @dataclass
        class 			__a					:





               """simple docstring"""


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




        lowerCAmelCase__   :				Dict 			=				HfArgumentParser(snake_case   )

        lowerCAmelCase__   :				Dict 			=				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   )

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

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

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






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				str 			=				HfArgumentParser(snake_case   )

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

        lowerCAmelCase__   :				Tuple 			=				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]   )			,					)

        lowerCAmelCase__   :				List[Any] 			=				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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Dict 			=				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   )

        lowerCAmelCase__   :				Optional[Any] 			=				[OptionalExample]
        if is_python_no_less_than_3_10:
         dataclass_types.append(snake_case   )

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

         self.argparsersEqual(snake_case			,					snake_case   )

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

         lowerCAmelCase__   :				List[str] 			=				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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[Any] 			=				HfArgumentParser(snake_case   )

        lowerCAmelCase__   :				List[Any] 			=				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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Dict 			=				HfArgumentParser(snake_case   )

        lowerCAmelCase__   :				Optional[Any] 			=				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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Any 			=				HfArgumentParser(snake_case   )

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

        lowerCAmelCase__   :				Tuple 			=				parser.parse_dict(snake_case   )[0]
        lowerCAmelCase__   :				Any 			=				BasicExample(**snake_case   )
        self.assertEqual(snake_case			,					snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

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

        lowerCAmelCase__   :				List[Any] 			=				{
            "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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

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

        lowerCAmelCase__   :				Optional[Any] 			=				{
            "foo": 12,
            "bar": 3.14,
            "baz": "42",
            "flag": True,
        }
        with tempfile.TemporaryDirectory() as tmp_dir:
         lowerCAmelCase__   :				int 			=				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   )
         lowerCAmelCase__   :				Any 			=				parser.parse_yaml_file(Path(temp_local_path + ".json"   )   )[0]

        lowerCAmelCase__   :				str 			=				BasicExample(**snake_case   )
        self.assertEqual(snake_case			,					snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				str 			=				HfArgumentParser(snake_case   )

        lowerCAmelCase__   :				int 			=				{
            "foo": 12,
            "bar": 3.14,
            "baz": "42",
            "flag": True,
        }
        with tempfile.TemporaryDirectory() as tmp_dir:
         lowerCAmelCase__   :				Optional[Any] 			=				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   )
         lowerCAmelCase__   :				Dict 			=				parser.parse_yaml_file(Path(temp_local_path + ".yaml"   )   )[0]
        lowerCAmelCase__   :				int 			=				BasicExample(**snake_case   )
        self.assertEqual(snake_case			,					snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Union[str, Any] 			=				HfArgumentParser(snake_case   )
        self.assertIsNotNone(snake_case   )






