Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Sktime Pytorch forecasting TiDE V2

From Leeroopedia


Knowledge Sources
Domains Time_Series, Forecasting, Deep_Learning
Last Updated 2026-02-08 08:00 GMT

Overview

TiDE V2 is a V2 implementation of the Time-series Dense Encoder (TiDE) model built on the BaseModel V2 data pipeline with support for categorical embeddings and residual block architecture.

Description

The TIDE class extends BaseModel (from the V2 base model pipeline) and implements the TiDE architecture as described in "Long-term Forecasting with TiDE: Time-series Dense Encoder" (arXiv:2304.08424). The model uses ResidualBlock sub-networks composed of skip connections with activation and dropout for all encoder and decoder heads, feature projections, and the temporal decoder. It processes past and future numerical variables through individual linear embedding layers, categorical variables through a dedicated embedding module, and combines all projected features for dense encoding and decoding. A linear skip connection from historical targets provides a direct autoregressive path. This V2 implementation supports the DSIPTS-style data pipeline with separate handling of categorical embeddings.

Usage

Use TiDE V2 when working with the V2 data pipeline (EncoderDecoderDataModule) and you need an efficient MLP-based encoder-decoder model for long-term forecasting. It supports categorical embeddings, numerical covariates for both past and future, and a persistence (autoregressive) component.

Code Reference

Source Location

Signature

class TIDE(BaseModel):
    def __init__(
        self,
        metadata: dict,
        loss: nn.Module,
        hidden_size: int,
        d_model: int,
        n_add_enc: int,
        n_add_dec: int,
        dropout_rate: float,
        activation: str = "",
        embs: list[int] = [],
        persistence_weight: float = 0.0,
        optim: str | None = None,
        optim_config: dict | None = None,
        scheduler_config: dict | None = None,
        **kwargs,
    ) -> None:

Import

from pytorch_forecasting.models.tide._tide_dsipts._tide_v2 import TIDE

I/O Contract

Inputs

Name Type Required Description
metadata dict Yes Dataset metadata containing max_encoder_length, max_prediction_length, encoder_cont, decoder_cont, and target dimensions.
loss nn.Module Yes Loss function module (e.g. MSELoss, QuantileLoss).
hidden_size int Yes Dimensionality of hidden layers in projections (R).
d_model int Yes Dimensionality of model projections after feature projection (R-tilde).
n_add_enc int Yes Number of additional encoder residual blocks after the first.
n_add_dec int Yes Number of additional decoder residual blocks after the first.
dropout_rate float Yes Dropout probability in residual blocks.
activation str No Activation function name (e.g. "relu"). Defaults to "".
embs list[int] No Embedding sizes for categorical variables. Defaults to [].
persistence_weight float No Weight for persistence (autoregressive) component. Defaults to 0.0.
optim None No Optimizer name. Defaults to None.
optim_config None No Optimizer configuration. Defaults to None.
scheduler_config None No Scheduler configuration. Defaults to None.

Forward Input Dictionary

Name Type Required Description
target_past torch.Tensor Yes Historical target values of shape (batch, past_steps, output_channels).
encoder_cont torch.Tensor No Past continuous covariates of shape (batch, past_steps, n_past_vars).
decoder_cont torch.Tensor No Future continuous covariates of shape (batch, future_steps, n_fut_vars).
encoder_cat torch.Tensor No Past categorical features of shape (batch, past_steps, n_cat).
decoder_cat torch.Tensor No Future categorical features of shape (batch, future_steps, n_cat).

Outputs

Name Type Description
prediction torch.Tensor Forecast output of shape (batch_size, future_steps, output_channels).

Usage Examples

from pytorch_forecasting.models.tide._tide_dsipts._tide_v2 import TIDE
import torch.nn as nn

metadata = {
    "max_encoder_length": 96,
    "max_prediction_length": 24,
    "encoder_cont": 5,
    "decoder_cont": 3,
    "target": 1,
}

model = TIDE(
    metadata=metadata,
    loss=nn.MSELoss(),
    hidden_size=128,
    d_model=64,
    n_add_enc=2,
    n_add_dec=2,
    dropout_rate=0.1,
    activation="relu",
    embs=[],
    persistence_weight=0.0,
)

# Forward pass
output = model(x_batch)
predictions = output["prediction"]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment