


"""simple docstring"""


from typing import List, Optional, Union

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


A  :     str    					=    logging.get_logger(__name__)

A  :     Tuple    					=    {
    "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						(     lowerCAmelCase__	):
							'''simple docstring'''







							__UpperCAmelCase		:					Optional[Any]          ="""time_series_transformer"""
							__UpperCAmelCase		:					Optional[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 = 1_00					,     __a = 0.0_2					,     __a=True					,     **__a					,     ):
										# time series specific configuration
										__lowerCAmelCase       					=    prediction_length
										__lowerCAmelCase       					=    context_length or prediction_length
										__lowerCAmelCase       					=    distribution_output
										__lowerCAmelCase       					=    loss
										__lowerCAmelCase       					=    input_size
										__lowerCAmelCase       					=    num_time_features
										__lowerCAmelCase       					=    lags_sequence
										__lowerCAmelCase       					=    scaling
										__lowerCAmelCase       					=    num_dynamic_real_features
										__lowerCAmelCase       					=    num_static_real_features
										__lowerCAmelCase       					=    num_static_categorical_features
										if cardinality and num_static_categorical_features > 0:
													if len(__a			) != num_static_categorical_features:
																raise ValueError(
																    "The cardinality should be a list of the same length as `num_static_categorical_features`"			)
													__lowerCAmelCase       					=    cardinality
										else:
													__lowerCAmelCase       					=    [0]
										if embedding_dimension and num_static_categorical_features > 0:
													if len(__a			) != num_static_categorical_features:
																raise ValueError(
																    "The embedding dimension should be a list of the same length as `num_static_categorical_features`"			)
													__lowerCAmelCase       					=    embedding_dimension
										else:
													__lowerCAmelCase       					=    [min(50					,     (cat + 1) // 2			) for cat in self.cardinality]
										__lowerCAmelCase       					=    num_parallel_samples

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

										__lowerCAmelCase       					=    dropout
										__lowerCAmelCase       					=    attention_dropout
										__lowerCAmelCase       					=    activation_dropout
										__lowerCAmelCase       					=    encoder_layerdrop
										__lowerCAmelCase       					=    decoder_layerdrop

										__lowerCAmelCase       					=    activation_function
										__lowerCAmelCase       					=    init_std

										__lowerCAmelCase       					=    use_cache

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



							@property
							def     snake_case       (  self			):
										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 flax.linen as nn
import jax
import jax.numpy as jnp
class 						_UpperCamelCase						(     nn.Module	):
							'''simple docstring'''







							__UpperCAmelCase		:					int
							__UpperCAmelCase		:					jnp.dtype          =jnp.floataa

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    nn.Conv(
										    self.out_channels					,     kernel_size=(3, 3)					,     strides=(1, 1)					,     padding=((1, 1), (1, 1))					,     dtype=self.dtype					,     )



							def __call__(  self					,     __a			):
										__lowerCAmelCase					,			__lowerCAmelCase					,			__lowerCAmelCase					,			__lowerCAmelCase       					=    hidden_states.shape
										__lowerCAmelCase       					=    jax.image.resize(
										    __a					,     shape=(batch, height * 2, width * 2, channels)					,     method="nearest"					,     )
										__lowerCAmelCase       					=    self.conv(__a			)
										return hidden_states
class 						_UpperCamelCase						(     nn.Module	):
							'''simple docstring'''







							__UpperCAmelCase		:					int
							__UpperCAmelCase		:					jnp.dtype          =jnp.floataa

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    nn.Conv(
										    self.out_channels					,     kernel_size=(3, 3)					,     strides=(2, 2)					,     padding=((1, 1), (1, 1))					,     dtype=self.dtype					,     )



							def __call__(  self					,     __a			):
										# pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
										# hidden_states = jnp.pad(hidden_states, pad_width=pad)
										__lowerCAmelCase       					=    self.conv(__a			)
										return hidden_states
class 						_UpperCamelCase						(     nn.Module	):
							'''simple docstring'''







							__UpperCAmelCase		:					int
							__UpperCAmelCase		:					int          =None
							__UpperCAmelCase		:					float          =0.0
							__UpperCAmelCase		:					bool          =None
							__UpperCAmelCase		:					jnp.dtype          =jnp.floataa

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.in_channels if self.out_channels is None else self.out_channels

										__lowerCAmelCase       					=    nn.GroupNorm(num_groups=32					,     epsilon=1e-5			)
										__lowerCAmelCase       					=    nn.Conv(
										    __a					,     kernel_size=(3, 3)					,     strides=(1, 1)					,     padding=((1, 1), (1, 1))					,     dtype=self.dtype					,     )

										__lowerCAmelCase       					=    nn.Dense(__a					,     dtype=self.dtype			)

										__lowerCAmelCase       					=    nn.GroupNorm(num_groups=32					,     epsilon=1e-5			)
										__lowerCAmelCase       					=    nn.Dropout(self.dropout_prob			)
										__lowerCAmelCase       					=    nn.Conv(
										    __a					,     kernel_size=(3, 3)					,     strides=(1, 1)					,     padding=((1, 1), (1, 1))					,     dtype=self.dtype					,     )

										__lowerCAmelCase       					=    self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

										__lowerCAmelCase       					=    None
										if use_nin_shortcut:
													__lowerCAmelCase       					=    nn.Conv(
													    __a					,     kernel_size=(1, 1)					,     strides=(1, 1)					,     padding="VALID"					,     dtype=self.dtype					,     )



							def __call__(  self					,     __a					,     __a					,     __a=True			):
										__lowerCAmelCase       					=    hidden_states
										__lowerCAmelCase       					=    self.norma(__a			)
										__lowerCAmelCase       					=    nn.swish(__a			)
										__lowerCAmelCase       					=    self.conva(__a			)

										__lowerCAmelCase       					=    self.time_emb_proj(nn.swish(__a			)			)
										__lowerCAmelCase       					=    jnp.expand_dims(jnp.expand_dims(__a					,     1			)					,     1			)
										__lowerCAmelCase       					=    hidden_states + temb

										__lowerCAmelCase       					=    self.norma(__a			)
										__lowerCAmelCase       					=    nn.swish(__a			)
										__lowerCAmelCase       					=    self.dropout(__a					,     __a			)
										__lowerCAmelCase       					=    self.conva(__a			)

										if self.conv_shortcut is not None:
													__lowerCAmelCase       					=    self.conv_shortcut(__a			)

										return hidden_states + residual




