
'''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__ :			str											=		sys.version_info >= (3, 10)







def 	A  (   UpperCamelCase_       :  Any=None    ,						UpperCamelCase_       :  List[Any]=None   )       ->							Optional[int]:







			'''simple docstring'''



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






@dataclass
class  A  :
	snake_case__   :int
	snake_case__   :float
	snake_case__   :str
	snake_case__   :bool






@dataclass
class  A  :
	snake_case__   :int   =  42
	snake_case__   :str   =  field(default='toto'	,   metadata={'help': 'help message'}     )






@dataclass
class  A  :
	snake_case__   :bool   =  False
	snake_case__   :bool   =  True
	snake_case__   :Optional[bool]   =  None






class  A  (						SCREAMING_SNAKE_CASE__     ):
	snake_case__   :Any   =  'titi'
	snake_case__   :Optional[int]   =  'toto'






class  A  (						SCREAMING_SNAKE_CASE__     ):
	snake_case__   :Union[str, Any]   =  'titi'
	snake_case__   :str   =  'toto'
	snake_case__   :int   =  42






@dataclass
class  A  :
	snake_case__   :BasicEnum   =  "toto"





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				BasicEnum(self.foo				)






@dataclass
class  A  :
	snake_case__   :MixedTypeEnum   =  "toto"





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Tuple				):


				"""simple docstring"""

				lowerCAmelCase__										=				MixedTypeEnum(self.foo				)






@dataclass
class  A  :
	snake_case__   :Optional[int]   =  None
	snake_case__   :Optional[float]   =  field(default=SCREAMING_SNAKE_CASE__	,   metadata={'help': 'help message'}     )
	snake_case__   :Optional[str]   =  None
	snake_case__   :Optional[List[str]]   =  list_field(default=[]     )
	snake_case__   :Optional[List[int]]   =  list_field(default=[]     )






@dataclass
class  A  :
	snake_case__   :List[int]   =  list_field(default=[]     )
	snake_case__   :List[int]   =  list_field(default=[1, 2, 3]     )
	snake_case__   :List[str]   =  list_field(default=['Hallo', 'Bonjour', 'Hello']     )
	snake_case__   :List[float]   =  list_field(default=[0.1, 0.2, 0.3]     )






@dataclass
class  A  :
	snake_case__   :List[int]   =  field()
	snake_case__   :str   =  field()
	snake_case__   :BasicEnum   =  field()





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Dict				):


				"""simple docstring"""

				lowerCAmelCase__										=				BasicEnum(self.required_enum				)






@dataclass
class  A  :
	snake_case__   :int
	snake_case__   :"BasicEnum"   =  field()
	snake_case__   :"Optional[bool]"   =  None
	snake_case__   :"str"   =  field(default='toto'	,   metadata={'help': 'help message'}     )
	snake_case__   :"List[str]"   =  list_field(default=['Hallo', 'Bonjour', 'Hello']     )


if is_python_no_less_than_3_10:






		@dataclass
		class  A  :
			snake_case__   :bool   =  False
			snake_case__   :bool   =  True
			snake_case__   :bool | None   =  None






		@dataclass
		class  A  :
			snake_case__   :int | None   =  None
			snake_case__   :float | None   =  field(default=SCREAMING_SNAKE_CASE__	,   metadata={'help': 'help message'}     )
			snake_case__   :str | None   =  None
			snake_case__   :list[str] | None   =  list_field(default=[]     )
			snake_case__   :list[int] | None   =  list_field(default=[]     )






class  A  (						unittest.TestCase     ):





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any   ,				__magic_name__      :							argparse.ArgumentParser   ,				__magic_name__      :							argparse.ArgumentParser				):


				"""simple docstring"""

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

							self.assertEqual(__magic_name__   ,				__magic_name__				)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							str				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

				lowerCAmelCase__										=				argparse.ArgumentParser()
				expected.add_argument("--foo"   ,				type=__magic_name__   ,				required=__magic_name__				)
				expected.add_argument("--bar"   ,				type=__magic_name__   ,				required=__magic_name__				)
				expected.add_argument("--baz"   ,				type=__magic_name__   ,				required=__magic_name__				)
				expected.add_argument("--flag"   ,				type=__magic_name__   ,				default=__magic_name__   ,				const=__magic_name__   ,				nargs="?"				)
				self.argparsersEqual(__magic_name__   ,				__magic_name__				)

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

				lowerCAmelCase__										=				argparse.ArgumentParser()
				expected.add_argument("--foo"   ,				default=42   ,				type=__magic_name__				)
				expected.add_argument("--baz"   ,				default="toto"   ,				type=__magic_name__   ,				help="help message"				)
				self.argparsersEqual(__magic_name__   ,				__magic_name__				)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Dict				):


				"""simple docstring"""

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

				lowerCAmelCase__										=				[WithDefaultBoolExample]
				if is_python_no_less_than_3_10:
							dataclass_types.append(__magic_name__				)

				for dataclass_type in dataclass_types:
							lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)
							self.argparsersEqual(__magic_name__   ,				__magic_name__				)

							lowerCAmelCase__										=				parser.parse_args([]				)
							self.assertEqual(__magic_name__   ,				Namespace(foo=__magic_name__   ,				baz=__magic_name__   ,				opt=__magic_name__				)				)

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

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

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

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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

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

				lowerCAmelCase__										=				parser.parse_args(["--foo", "titi"]				)
				self.assertEqual(args.foo   ,				"titi"				)
				lowerCAmelCase__										=				parser.parse_args_into_dataclasses(["--foo", "titi"]				)[0]
				self.assertEqual(enum_ex.foo   ,				MixedTypeEnum.titi				)

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							int				):


				"""simple docstring"""

				@dataclass
				class  A  :
					snake_case__   :Literal["titi", "toto", 42]   =  "toto"

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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

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

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

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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

				self.argparsersEqual(__magic_name__   ,				__magic_name__				)

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

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Dict				):


				"""simple docstring"""

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

				lowerCAmelCase__										=				[OptionalExample]
				if is_python_no_less_than_3_10:
							dataclass_types.append(__magic_name__				)

				for dataclass_type in dataclass_types:
							lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

							self.argparsersEqual(__magic_name__   ,				__magic_name__				)

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

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							int				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

				lowerCAmelCase__										=				argparse.ArgumentParser()
				expected.add_argument("--required_list"   ,				nargs="+"   ,				type=__magic_name__   ,				required=__magic_name__				)
				expected.add_argument("--required_str"   ,				type=__magic_name__   ,				required=__magic_name__				)
				expected.add_argument(
				    "--required_enum"   ,				type=make_choice_type_function(["titi", "toto"]				)   ,				choices=["titi", "toto"]   ,				required=__magic_name__   ,				)
				self.argparsersEqual(__magic_name__   ,				__magic_name__				)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Tuple				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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

				lowerCAmelCase__										=				parser.parse_dict(__magic_name__				)[0]
				lowerCAmelCase__										=				BasicExample(**__magic_name__				)
				self.assertEqual(__magic_name__   ,				__magic_name__				)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[int]				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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

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





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[int]				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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

				lowerCAmelCase__										=				BasicExample(**__magic_name__				)
				self.assertEqual(__magic_name__   ,				__magic_name__				)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							str				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)

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







	def 				__SCREAMING_SNAKE_CASE	(       self      :							Optional[Any]				):


				"""simple docstring"""

				lowerCAmelCase__										=				HfArgumentParser(__magic_name__				)
				self.assertIsNotNone(__magic_name__				)











'''simple docstring'''







from typing import List, Optional

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


lowercase      :   Optional[Any]      =       logging.get_logger(__name__)

lowercase      :   Any      =       {
    """huggingface/autoformer-tourism-monthly""": """https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json""",
}







class 					_a (a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     List[str]          =					"""autoformer"""
     lowerCAmelCase_  :     int          =					{
         """hidden_size""": """d_model""",
         """num_attention_heads""": """encoder_attention_heads""",
         """num_hidden_layers""": """encoder_layers""",
     }







     def __init__(				self							,__a = None							,__a = None							,__a = "student_t"							,__a = "nll"							,__a = 1							,__a = [1, 2, 3, 4, 5, 6, 7]							,__a = True							,__a = 0							,__a = 0							,__a = 0							,__a = 0							,__a = None							,__a = None							,__a = 64							,__a = 2							,__a = 2							,__a = 2							,__a = 2							,__a = 32							,__a = 32							,__a = "gelu"							,__a = 0.1							,__a = 0.1							,__a = 0.1							,__a = 0.1							,__a = 0.1							,__a = 100							,__a = 0.02							,__a = True							,__a=True							,__a = 10							,__a = 25							,__a = 3							,**__a							,)      ->				Union[str, Any]:
          # time series specific configuration
          snake_case			:      List[str]        =			prediction_length
          snake_case			:      str        =			context_length if context_length is not None else prediction_length
          snake_case			:      List[Any]        =			distribution_output
          snake_case			:      Any        =			loss
          snake_case			:      Union[str, Any]        =			input_size
          snake_case			:      Optional[int]        =			num_time_features
          snake_case			:      Union[str, Any]        =			lags_sequence
          snake_case			:      Any        =			scaling
          snake_case			:      str        =			num_dynamic_real_features
          snake_case			:      Union[str, Any]        =			num_static_real_features
          snake_case			:      Optional[int]        =			num_static_categorical_features
          if cardinality is not None and num_static_categorical_features > 0:
               if len(__a							) != num_static_categorical_features:
                    raise ValueError(
                        """The cardinality should be a list of the same length as `num_static_categorical_features`"""							)
               snake_case			:      int        =			cardinality
          else:
               snake_case			:      Optional[Any]        =			[0]
          if embedding_dimension is not None and num_static_categorical_features > 0:
               if len(__a							) != num_static_categorical_features:
                    raise ValueError(
                        """The embedding dimension should be a list of the same length as `num_static_categorical_features`"""							)
               snake_case			:      int        =			embedding_dimension
          else:
               snake_case			:      List[str]        =			[min(50							,(cat + 1) // 2							) for cat in self.cardinality]
          snake_case			:      Optional[int]        =			num_parallel_samples

          # Transformer architecture configuration
          snake_case			:      Any        =			input_size * len(self.lags_sequence							) + self._number_of_features
          snake_case			:      Union[str, Any]        =			d_model
          snake_case			:      Any        =			encoder_attention_heads
          snake_case			:      Union[str, Any]        =			decoder_attention_heads
          snake_case			:      Optional[Any]        =			encoder_ffn_dim
          snake_case			:      Any        =			decoder_ffn_dim
          snake_case			:      List[Any]        =			encoder_layers
          snake_case			:      List[str]        =			decoder_layers

          snake_case			:      str        =			dropout
          snake_case			:      Union[str, Any]        =			attention_dropout
          snake_case			:      Optional[Any]        =			activation_dropout
          snake_case			:      Tuple        =			encoder_layerdrop
          snake_case			:      Any        =			decoder_layerdrop

          snake_case			:      Any        =			activation_function
          snake_case			:      int        =			init_std

          snake_case			:      Optional[Any]        =			use_cache

          # Autoformer
          snake_case			:      int        =			label_length
          snake_case			:      str        =			moving_average
          snake_case			:      Tuple        =			autocorrelation_factor

          super().__init__(is_encoder_decoder=__a							,**__a							)







     @property
     def 			snake_case_      (				self							)      ->				int:
          return (
              sum(self.embedding_dimension							)
              + self.num_dynamic_real_features
              + self.num_time_features
              + self.num_static_real_features
              + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
          )



