
from typing import List, Optional

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


_A   =			logging.get_logger(__name__)

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







class 					lowerCamelCase		(  SCREAMING_SNAKE_CASE__  ):
     UpperCAmelCase__    :							Optional[int]									=		'autoformer'
     UpperCAmelCase__    :							Optional[int]									=		{
         'hidden_size': 'd_model',
         'num_attention_heads': 'encoder_attention_heads',
         'num_hidden_layers': 'encoder_layers',
     }





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

         # Transformer architecture configuration
         snake_case								= input_size * len(self.lags_sequence       ) + self._number_of_features
         snake_case								= d_model
         snake_case								= encoder_attention_heads
         snake_case								= decoder_attention_heads
         snake_case								= encoder_ffn_dim
         snake_case								= decoder_ffn_dim
         snake_case								= encoder_layers
         snake_case								= decoder_layers

         snake_case								= dropout
         snake_case								= attention_dropout
         snake_case								= activation_dropout
         snake_case								= encoder_layerdrop
         snake_case								= decoder_layerdrop

         snake_case								= activation_function
         snake_case								= init_std

         snake_case								= use_cache

         # Autoformer
         snake_case								= label_length
         snake_case								= moving_average
         snake_case								= autocorrelation_factor

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





     @property
     def 		UpperCAmelCase(self				:   Optional[int]       )						->						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
         )






import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)







class 					lowerCamelCase		(  unittest.TestCase  ):





     def 		UpperCAmelCase(self				:   Tuple       )						->						List[str]:
         snake_case								= ["a", "b", "c"]

         # Defaults to last layer if both are None
         snake_case					,							snake_case								= get_aligned_output_features_output_indices(_A    ,   _A    ,   _A       )
         self.assertEqual(_A    ,   ["c"]       )
         self.assertEqual(_A    ,   [2]       )

         # Out indices set to match out features
         snake_case					,							snake_case								= get_aligned_output_features_output_indices(["a", "c"]    ,   _A    ,   _A       )
         self.assertEqual(_A    ,   ["a", "c"]       )
         self.assertEqual(_A    ,   [0, 2]       )

         # Out features set to match out indices
         snake_case					,							snake_case								= get_aligned_output_features_output_indices(_A    ,   [0, 2]    ,   _A       )
         self.assertEqual(_A    ,   ["a", "c"]       )
         self.assertEqual(_A    ,   [0, 2]       )

         # Out features selected from negative indices
         snake_case					,							snake_case								= get_aligned_output_features_output_indices(_A    ,   [-3, -1]    ,   _A       )
         self.assertEqual(_A    ,   ["a", "c"]       )
         self.assertEqual(_A    ,   [-3, -1]       )





     def 		UpperCAmelCase(self				:   Optional[int]       )						->						str:
         # Stage names must be set
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(["a", "b"]    ,   (0, 1)    ,   _A       )

         # Out features must be a list
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(("a", "b")    ,   (0, 1)    ,   ["a", "b"]       )

         # Out features must be a subset of stage names
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(["a", "b"]    ,   (0, 1)    ,   ["a"]       )

         # Out indices must be a list or tuple
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(_A    ,   0    ,   ["a", "b"]       )

         # Out indices must be a subset of stage names
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(_A    ,   (0, 1)    ,   ["a"]       )

         # Out features and out indices must be the same length
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(["a", "b"]    ,   (0,)    ,   ["a", "b", "c"]       )

         # Out features should match out indices
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(["a", "b"]    ,   (0, 2)    ,   ["a", "b", "c"]       )

         # Out features and out indices should be in order
         with self.assertRaises(_A       ):
             verify_out_features_out_indices(["b", "a"]    ,   (0, 1)    ,   ["a", "b"]       )

         # Check passes with valid inputs
         verify_out_features_out_indices(["a", "b", "d"]    ,   (0, 1, -1)    ,   ["a", "b", "c", "d"]       )





     def 		UpperCAmelCase(self				:   List[str]       )						->						str:
         snake_case								= BackboneMixin()

         snake_case								= ["a", "b", "c"]
         snake_case								= ["a", "c"]
         snake_case								= [0, 2]

         # Check that the output features and indices are set correctly
         self.assertEqual(backbone.out_features    ,   ["a", "c"]       )
         self.assertEqual(backbone.out_indices    ,   [0, 2]       )

         # Check out features and indices are updated correctly
         snake_case								= ["a", "b"]
         self.assertEqual(backbone.out_features    ,   ["a", "b"]       )
         self.assertEqual(backbone.out_indices    ,   [0, 1]       )

         snake_case								= [-3, -1]
         self.assertEqual(backbone.out_features    ,   ["a", "c"]       )
         self.assertEqual(backbone.out_indices    ,   [-3, -1]       )

