



from typing import List, Optional, Union

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


_snake_case						=    logging.get_logger(__name__)

_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_       (			a_):
							lowerCamelCase__       =						'time_series_transformer'
							lowerCamelCase__       =						{
							    '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 = "mean",     __a = 0,     __a = 0,     __a = 0,     __a = 0,     __a = None,     __a = None,     __a = 32,     __a = 32,     __a = 2,     __a = 2,     __a = 2,     __a = 2,     __a = True,     __a = "gelu",     __a = 64,     __a = 0.1,     __a = 0.1,     __a = 0.1,     __a = 0.1,     __a = 0.1,     __a = 100,     __a = 0.02,     __a=True,     **__a,     ):

														'''simple docstring'''

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

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

														_lowerCAmelCase	:				List[str]					  =       dropout
														_lowerCAmelCase	:				Union[str, Any]					  =       attention_dropout
														_lowerCAmelCase	:				str					  =       activation_dropout
														_lowerCAmelCase	:				Tuple					  =       encoder_layerdrop
														_lowerCAmelCase	:				int					  =       decoder_layerdrop

														_lowerCAmelCase	:				Tuple					  =       activation_function
														_lowerCAmelCase	:				List[Any]					  =       init_std

														_lowerCAmelCase	:				Union[str, Any]					  =       use_cache

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







							@property
							def   snake_case__ (  self):

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


      def 			__UpperCAmelCase		(						self						)->						List[Any]:
           # For consistency across different places the DisjunctiveConstraint is called,
           # dc.token_ids is a list of integers. It is also initialized only by integers.

           __lowerCAmelCase             =       [[1, 2, 4], [1, 2, 3, 4]]
           __lowerCAmelCase             =       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						)->						Tuple:
           # 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).
           __lowerCAmelCase             =       [[1, 2], [1, 2, 3, 4]]

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


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

           __lowerCAmelCase             =       DisjunctiveConstraint(__UpperCamelCase						)

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

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

           __lowerCAmelCase      ,			__lowerCAmelCase      ,			__lowerCAmelCase             =       dc.update(3						)
           __lowerCAmelCase             =       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						)->						int:
           __lowerCAmelCase             =       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

           __lowerCAmelCase             =       DisjunctiveConstraint(__UpperCamelCase						)

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

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

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

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

           dc.reset()

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

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

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






