
'''simple docstring'''

from typing import List, Optional

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


snake_case									=    logging.get_logger(__name__)

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




class    lowerCAmelCase       (     UpperCamelCase_  ):
 A_				:				Dict	=			"""autoformer"""
 A_				:				List[Any]	=			{
     """hidden_size""": """d_model""",
     """num_attention_heads""": """encoder_attention_heads""",
     """num_hidden_layers""": """encoder_layers""",
 }


 def __init__(    self  : str			,							a__  : Optional[int] = None			,							a__  : Optional[int] = None			,							a__  : str = "student_t"			,							a__  : str = "nll"			,							a__  : int = 1			,							a__  : List[int] = [1, 2, 3, 4, 5, 6, 7]			,							a__  : bool = True			,							a__  : int = 0			,							a__  : int = 0			,							a__  : int = 0			,							a__  : int = 0			,							a__  : Optional[List[int]] = None			,							a__  : Optional[List[int]] = None			,							a__  : int = 64			,							a__  : int = 2			,							a__  : int = 2			,							a__  : int = 2			,							a__  : int = 2			,							a__  : int = 32			,							a__  : int = 32			,							a__  : str = "gelu"			,							a__  : float = 0.1			,							a__  : float = 0.1			,							a__  : float = 0.1			,							a__  : float = 0.1			,							a__  : float = 0.1			,							a__  : int = 100			,							a__  : float = 0.02			,							a__  : bool = True			,							a__  : Optional[Any]=True			,							a__  : int = 10			,							a__  : int = 25			,							a__  : int = 3			,							**a__  : int			,							):
  '''simple docstring'''

  lowerCAmelCase__     :   str     		=	prediction_length
  lowerCAmelCase__     :   List[Any]     		=	context_length if context_length is not None else prediction_length
  lowerCAmelCase__     :   Tuple     		=	distribution_output
  lowerCAmelCase__     :   int     		=	loss
  lowerCAmelCase__     :   Tuple     		=	input_size
  lowerCAmelCase__     :   List[Any]     		=	num_time_features
  lowerCAmelCase__     :   Dict     		=	lags_sequence
  lowerCAmelCase__     :   Union[str, Any]     		=	scaling
  lowerCAmelCase__     :   Any     		=	num_dynamic_real_features
  lowerCAmelCase__     :   Optional[Any]     		=	num_static_real_features
  lowerCAmelCase__     :   Optional[Any]     		=	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`"    )
   lowerCAmelCase__     :   Tuple     		=	cardinality
  else:
   lowerCAmelCase__     :   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`"    )
   lowerCAmelCase__     :   Any     		=	embedding_dimension
  else:
   lowerCAmelCase__     :   Optional[int]     		=	[min(50			,							(cat + 1) // 2    ) for cat in self.cardinality]
  lowerCAmelCase__     :   Union[str, Any]     		=	num_parallel_samples

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

  lowerCAmelCase__     :   Optional[int]     		=	dropout
  lowerCAmelCase__     :   Any     		=	attention_dropout
  lowerCAmelCase__     :   int     		=	activation_dropout
  lowerCAmelCase__     :   str     		=	encoder_layerdrop
  lowerCAmelCase__     :   int     		=	decoder_layerdrop

  lowerCAmelCase__     :   Union[str, Any]     		=	activation_function
  lowerCAmelCase__     :   Optional[int]     		=	init_std

  lowerCAmelCase__     :   List[Any]     		=	use_cache

  # Autoformer
  lowerCAmelCase__     :   Optional[Any]     		=	label_length
  lowerCAmelCase__     :   Union[str, Any]     		=	moving_average
  lowerCAmelCase__     :   Optional[Any]     		=	autocorrelation_factor

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


 @property
 def    _A	(    self  : Dict    ):
  '''simple docstring'''

  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
  )







'''simple docstring'''

from pathlib import Path
from typing import List

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import get_tests_dir, is_tool_test
from transformers.tools.agent_types import AGENT_TYPE_MAPPING, AgentAudio, AgentImage, AgentText


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image


snake_case									=    ["""text""", """image""", """audio"""]


def        UpperCAmelCase_ (  lowerCamelCase_			):







 """simple docstring"""


 lowerCAmelCase__     :   str     		=	[]

 for input_type in input_types:
  if input_type == "text":
   inputs.append("Text input"			)
  elif input_type == "image":
   inputs.append(
       Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"			)			) / "000000039769.png"			).resize((5_1_2, 5_1_2)			)			)
  elif input_type == "audio":
   inputs.append(torch.ones(3_0_0_0			)			)
  elif isinstance(lowerCamelCase_      ,			lowerCamelCase_			):
   inputs.append(create_inputs(lowerCamelCase_			)			)
  else:
   raise ValueError(f'''Invalid type requested: {input_type}'''			)

 return inputs


def        UpperCAmelCase_ (  lowerCamelCase_			):







 """simple docstring"""


 lowerCAmelCase__     :   str     		=	[]

 for output in outputs:
  if isinstance(lowerCamelCase_      ,			(str, AgentText)			):
   output_types.append("text"			)
  elif isinstance(lowerCamelCase_      ,			(Image.Image, AgentImage)			):
   output_types.append("image"			)
  elif isinstance(lowerCamelCase_      ,			(torch.Tensor, AgentAudio)			):
   output_types.append("audio"			)
  else:
   raise ValueError(f'''Invalid output: {output}'''			)

 return output_types







@is_tool_test
class    lowerCAmelCase       :


 def    _A	(    self  : Any    ):
  '''simple docstring'''

  self.assertTrue(hasattr(self.tool			,							"inputs"    )    )
  self.assertTrue(hasattr(self.tool			,							"outputs"    )    )

  lowerCAmelCase__     :   Dict     		=	self.tool.inputs
  for _input in inputs:
   if isinstance(_input			,							a__    ):
    for __input in _input:
     self.assertTrue(__input in authorized_types    )
   else:
    self.assertTrue(_input in authorized_types    )

  lowerCAmelCase__     :   List[Any]     		=	self.tool.outputs
  for _output in outputs:
   self.assertTrue(_output in authorized_types    )


 def    _A	(    self  : Any    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[Any]     		=	create_inputs(self.tool.inputs    )
  lowerCAmelCase__     :   str     		=	self.tool(*a__    )

  # There is a single output
  if len(self.tool.outputs    ) == 1:
   lowerCAmelCase__     :   Union[str, Any]     		=	[outputs]

  self.assertListEqual(output_types(a__    )			,							self.tool.outputs    )


 def    _A	(    self  : List[str]    ):
  '''simple docstring'''

  self.assertTrue(hasattr(self.tool			,							"description"    )    )
  self.assertTrue(hasattr(self.tool			,							"default_checkpoint"    )    )
  self.assertTrue(self.tool.description.startswith("This is a tool that"    )    )


 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   str     		=	create_inputs(self.tool.inputs    )
  lowerCAmelCase__     :   str     		=	self.tool(*a__    )

  if not isinstance(a__			,							a__    ):
   lowerCAmelCase__     :   List[str]     		=	[outputs]

  self.assertEqual(len(a__    )			,							len(self.tool.outputs    )    )

  for output, output_type in zip(a__			,							self.tool.outputs    ):
   lowerCAmelCase__     :   List[Any]     		=	AGENT_TYPE_MAPPING[output_type]
   self.assertTrue(isinstance(a__			,							a__    )    )


 def    _A	(    self  : Optional[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	create_inputs(self.tool.inputs    )

  lowerCAmelCase__     :   Dict     		=	[]

  for _input, input_type in zip(a__			,							self.tool.inputs    ):
   if isinstance(a__			,							a__    ):
    _inputs.append([AGENT_TYPE_MAPPING[_input_type](_input    ) for _input_type in input_type]    )
   else:
    _inputs.append(AGENT_TYPE_MAPPING[input_type](_input    )    )

        # Should not raise an error
  lowerCAmelCase__     :   Any     		=	self.tool(*a__    )

  if not isinstance(a__			,							a__    ):
   lowerCAmelCase__     :   Tuple     		=	[outputs]

  self.assertEqual(len(a__    )			,							len(self.tool.outputs    )    )





