




from typing import List, Optional

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


_lowerCamelCase     :		List[str]								=       logging.get_logger(__name__)

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


class     UpperCamelCase_   (			UpperCAmelCase__					):

    '''simple docstring'''






    UpperCAmelCase__							  =				'''autoformer'''
    UpperCAmelCase__							  =				{
        '''hidden_size''': '''d_model''',
        '''num_attention_heads''': '''encoder_attention_heads''',
        '''num_hidden_layers''': '''encoder_layers''',
    }


    def __init__(      self				:     Union[str, Any] ,			UpperCAmelCase__				:     Optional[int] = None ,			UpperCAmelCase__				:     Optional[int] = None ,			UpperCAmelCase__				:     str = "student_t" ,			UpperCAmelCase__				:     str = "nll" ,			UpperCAmelCase__				:     int = 1 ,			UpperCAmelCase__				:     List[int] = [1, 2, 3, 4, 5, 6, 7] ,			UpperCAmelCase__				:     bool = True ,			UpperCAmelCase__				:     int = 0 ,			UpperCAmelCase__				:     int = 0 ,			UpperCAmelCase__				:     int = 0 ,			UpperCAmelCase__				:     int = 0 ,			UpperCAmelCase__				:     Optional[List[int]] = None ,			UpperCAmelCase__				:     Optional[List[int]] = None ,			UpperCAmelCase__				:     int = 64 ,			UpperCAmelCase__				:     int = 2 ,			UpperCAmelCase__				:     int = 2 ,			UpperCAmelCase__				:     int = 2 ,			UpperCAmelCase__				:     int = 2 ,			UpperCAmelCase__				:     int = 32 ,			UpperCAmelCase__				:     int = 32 ,			UpperCAmelCase__				:     str = "gelu" ,			UpperCAmelCase__				:     float = 0.1 ,			UpperCAmelCase__				:     float = 0.1 ,			UpperCAmelCase__				:     float = 0.1 ,			UpperCAmelCase__				:     float = 0.1 ,			UpperCAmelCase__				:     float = 0.1 ,			UpperCAmelCase__				:     int = 100 ,			UpperCAmelCase__				:     float = 0.02 ,			UpperCAmelCase__				:     bool = True ,			UpperCAmelCase__				:     Dict=True ,			UpperCAmelCase__				:     int = 10 ,			UpperCAmelCase__				:     int = 25 ,			UpperCAmelCase__				:     int = 3 ,			**UpperCAmelCase__				:     Tuple ,			)						->str:





           '''simple docstring'''

           A__							=   prediction_length
           A__							=   context_length if context_length is not None else prediction_length
           A__							=   distribution_output
           A__							=   loss
           A__							=   input_size
           A__							=   num_time_features
           A__							=   lags_sequence
           A__							=   scaling
           A__							=   num_dynamic_real_features
           A__							=   num_static_real_features
           A__							=   num_static_categorical_features
           if cardinality is not None and num_static_categorical_features > 0:
                  if len(UpperCAmelCase__) != num_static_categorical_features:
                         raise ValueError(
                             '''The cardinality should be a list of the same length as `num_static_categorical_features`''')
                  A__							=   cardinality
           else:
                  A__							=   [0]
           if embedding_dimension is not None and num_static_categorical_features > 0:
                  if len(UpperCAmelCase__) != num_static_categorical_features:
                         raise ValueError(
                             '''The embedding dimension should be a list of the same length as `num_static_categorical_features`''')
                  A__							=   embedding_dimension
           else:
                  A__							=   [min(50 ,			(cat + 1) // 2) for cat in self.cardinality]
           A__							=   num_parallel_samples

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

           A__							=   dropout
           A__							=   attention_dropout
           A__							=   activation_dropout
           A__							=   encoder_layerdrop
           A__							=   decoder_layerdrop

           A__							=   activation_function
           A__							=   init_std

           A__							=   use_cache

           # Autoformer
           A__							=   label_length
           A__							=   moving_average
           A__							=   autocorrelation_factor

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





    @property
    def 	SCREAMING_SNAKE_CASE							(      self				:     Any)						->int:





           '''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
           )











import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
  import torch

  from transformers.generation import DisjunctiveConstraint


@require_torch
class     UpperCamelCase_   (			unittest.TestCase					):

    '''simple docstring'''






    def 	SCREAMING_SNAKE_CASE							(      self				:     Dict)						->Tuple:





           '''simple docstring'''

           A__							=   [[1, 2, 4], [1, 2, 3, 4]]
           A__							=   DisjunctiveConstraint(UpperCAmelCase__)
           self.assertTrue(isinstance(dc.token_ids ,			UpperCAmelCase__))

           with self.assertRaises(UpperCAmelCase__):
                  DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]))

           with self.assertRaises(UpperCAmelCase__):
                  DisjunctiveConstraint([torch.LongTensor([1, 2, 4]), torch.LongTensor([1, 2, 3, 4, 5])])


    def 	SCREAMING_SNAKE_CASE							(      self				:     int)						->str:





           '''simple docstring'''

           A__							=   [[1, 2], [1, 2, 3, 4]]

           with self.assertRaises(UpperCAmelCase__):
                  DisjunctiveConstraint(UpperCAmelCase__)  # fails here


    def 	SCREAMING_SNAKE_CASE							(      self				:     Any)						->str:





           '''simple docstring'''

           A__							=   [[1, 2, 3], [1, 2, 4]]

           A__							=   DisjunctiveConstraint(UpperCAmelCase__)

           A__			,							A__			,							A__							=   dc.update(1)
           A__							=   stepped is True and completed is False and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1])

           A__			,							A__			,							A__							=   dc.update(2)
           A__							=   stepped is True and completed is False and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1, 2])

           A__			,							A__			,							A__							=   dc.update(3)
           A__							=   stepped is True and completed is True and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(dc.completed)  # Completed!
           self.assertTrue(dc.current_seq == [1, 2, 3])





    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any])						->Tuple:





           '''simple docstring'''

           A__							=   [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

           A__							=   DisjunctiveConstraint(UpperCAmelCase__)

           A__			,							A__			,							A__							=   dc.update(1)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1])

           A__			,							A__			,							A__							=   dc.update(2)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1, 2])

           A__			,							A__			,							A__							=   dc.update(4)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1, 2, 4])

           A__			,							A__			,							A__							=   dc.update(5)
           self.assertTrue(dc.completed)  # Completed!
           self.assertTrue(dc.current_seq == [1, 2, 4, 5])

           dc.reset()

           A__			,							A__			,							A__							=   dc.update(1)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.remaining() == 3)
           self.assertTrue(dc.current_seq == [1])

           A__			,							A__			,							A__							=   dc.update(2)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.remaining() == 2)
           self.assertTrue(dc.current_seq == [1, 2])

           A__			,							A__			,							A__							=   dc.update(5)
           self.assertTrue(dc.completed)  # Completed!
           self.assertTrue(dc.remaining() == 0)
           self.assertTrue(dc.current_seq == [1, 2, 5])


