"""simple docstring"""







from typing import List, Optional, Union

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


__SCREAMING_SNAKE_CASE    	=logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE    	={
    '''huggingface/time-series-transformer-tourism-monthly''': (
        '''https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json'''
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}







class        UpperCamelCase		(			lowercase_  ):
   lowercase							=  "time_series_transformer"
   lowercase							=  {
       "hidden_size": "d_model",
       "num_attention_heads": "encoder_attention_heads",
       "num_hidden_layers": "encoder_layers",
   }
   def __init__(			self     ,__UpperCamelCase = None     ,__UpperCamelCase = None     ,__UpperCamelCase = "student_t"     ,__UpperCamelCase = "nll"     ,__UpperCamelCase = 1     ,__UpperCamelCase = [1, 2, 3, 4, 5, 6, 7]     ,__UpperCamelCase = "mean"     ,__UpperCamelCase = 0     ,__UpperCamelCase = 0     ,__UpperCamelCase = 0     ,__UpperCamelCase = 0     ,__UpperCamelCase = None     ,__UpperCamelCase = None     ,__UpperCamelCase = 32     ,__UpperCamelCase = 32     ,__UpperCamelCase = 2     ,__UpperCamelCase = 2     ,__UpperCamelCase = 2     ,__UpperCamelCase = 2     ,__UpperCamelCase = True     ,__UpperCamelCase = "gelu"     ,__UpperCamelCase = 64     ,__UpperCamelCase = 0.1     ,__UpperCamelCase = 0.1     ,__UpperCamelCase = 0.1     ,__UpperCamelCase = 0.1     ,__UpperCamelCase = 0.1     ,__UpperCamelCase = 100     ,__UpperCamelCase = 0.02     ,__UpperCamelCase=True     ,**__UpperCamelCase     ,)	->      Dict:


        '''simple docstring'''


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

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

        lowercase_	:				Union[str, Any]													=	dropout
        lowercase_	:				Union[str, Any]													=	attention_dropout
        lowercase_	:				Optional[int]													=	activation_dropout
        lowercase_	:				str													=	encoder_layerdrop
        lowercase_	:				Any													=	decoder_layerdrop

        lowercase_	:				Optional[int]													=	activation_function
        lowercase_	:				Dict													=	init_std

        lowercase_	:				int													=	use_cache

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







   @property
   def 			_UpperCAmelCase   (			self			)	->      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
        )





"""simple docstring"""







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   UpperCAmelCase_      ( self			:				Optional[int]   )       ->	List[str]:
						# For consistency across different places the DisjunctiveConstraint is called,
						# dc.token_ids is a list of integers. It is also initialized only by integers.

						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 4], [1, 2, 3, 4]]
						__SCREAMING_SNAKE_CASE						   =				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   UpperCAmelCase_      ( self			:				Any   )       ->	int:
						# We can't have constraints that are complete subsets of another. This leads to a preverse
						# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
						# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
						# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
						# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
						__SCREAMING_SNAKE_CASE						   =				[[1, 2], [1, 2, 3, 4]]

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




	def   UpperCAmelCase_      ( self			:				List[Any]   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 3], [1, 2, 4]]

						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						__SCREAMING_SNAKE_CASE						   =				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]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						__SCREAMING_SNAKE_CASE						   =				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]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(3   )
						__SCREAMING_SNAKE_CASE						   =				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   UpperCAmelCase_      ( self			:				str   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )

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

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

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

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

						dc.reset()

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

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

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