
from typing import List, Optional, Union

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


_UpperCAmelCase :			int              =	logging.get_logger(__name__)

_UpperCAmelCase :			Any              =	{
    '''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     lowercase (		SCREAMING_SNAKE_CASE__       ):
  __lowercase	:	Tuple     					=    'time_series_transformer'
  __lowercase	:	List[Any]     					=    {
      '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_    ,				)  -> Optional[int]:
    """simple docstring"""
    # time series specific configuration
    UpperCamelCase          =					prediction_length
    UpperCamelCase          =					context_length or prediction_length
    UpperCamelCase          =					distribution_output
    UpperCamelCase          =					loss
    UpperCamelCase          =					input_size
    UpperCamelCase          =					num_time_features
    UpperCamelCase          =					lags_sequence
    UpperCamelCase          =					scaling
    UpperCamelCase          =					num_dynamic_real_features
    UpperCamelCase          =					num_static_real_features
    UpperCamelCase          =					num_static_categorical_features
    if cardinality 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`'	)
      UpperCamelCase          =					cardinality
    else:
      UpperCamelCase          =					[0]
    if embedding_dimension 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`'	)
      UpperCamelCase          =					embedding_dimension
    else:
      UpperCamelCase          =					[min(50    ,				(cat + 1) // 2	) for cat in self.cardinality]
    UpperCamelCase          =					num_parallel_samples

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

    UpperCamelCase          =					dropout
    UpperCamelCase          =					attention_dropout
    UpperCamelCase          =					activation_dropout
    UpperCamelCase          =					encoder_layerdrop
    UpperCamelCase          =					decoder_layerdrop

    UpperCamelCase          =					activation_function
    UpperCamelCase          =					init_std

    UpperCamelCase          =					use_cache

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



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


import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation


class     lowercase (		unittest.TestCase       ):



		def __UpperCamelCase			(			self	)  -> List[Any]:
				"""simple docstring"""
				UpperCamelCase          =					get_activation('swish'	)

				self.assertIsInstance(A_    ,				nn.SiLU	)

				self.assertEqual(act(torch.tensor(-100    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertNotEqual(act(torch.tensor(-1    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(0    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(20    ,				dtype=torch.floataa	)	).item()    ,				20	)



		def __UpperCamelCase			(			self	)  -> Optional[int]:
				"""simple docstring"""
				UpperCamelCase          =					get_activation('silu'	)

				self.assertIsInstance(A_    ,				nn.SiLU	)

				self.assertEqual(act(torch.tensor(-100    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertNotEqual(act(torch.tensor(-1    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(0    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(20    ,				dtype=torch.floataa	)	).item()    ,				20	)



		def __UpperCamelCase			(			self	)  -> str:
				"""simple docstring"""
				UpperCamelCase          =					get_activation('mish'	)

				self.assertIsInstance(A_    ,				nn.Mish	)

				self.assertEqual(act(torch.tensor(-200    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertNotEqual(act(torch.tensor(-1    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(0    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(20    ,				dtype=torch.floataa	)	).item()    ,				20	)



		def __UpperCamelCase			(			self	)  -> Union[str, Any]:
				"""simple docstring"""
				UpperCamelCase          =					get_activation('gelu'	)

				self.assertIsInstance(A_    ,				nn.GELU	)

				self.assertEqual(act(torch.tensor(-100    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertNotEqual(act(torch.tensor(-1    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(0    ,				dtype=torch.floataa	)	).item()    ,				0	)
				self.assertEqual(act(torch.tensor(20    ,				dtype=torch.floataa	)	).item()    ,				20	)
