M Layer v2#

Warning

Please note that the v2 modules are currently in active-development and is in beta right now, so please use this API with caution. See complete documentation for v2 API here and stable v1 documentation here.

The forecasting models in the V2 ecosystem are designed with a strict emphasis on modularity and separation of concerns. The architecture decouples algorithmic logic from data processing, ensuring that models act as pure, data-agnostic PyTorch Lightning instances.

Available Models#

Below is a summary of the forecasting models currently implemented and supported in the new API.

Name

Compatible Data Modules

Authors

Covariates

Multiple targets

Regression

Classification

Probabilistic

Prediction intervals

Flexible History Length

Cold Start

Compute (1-5)

DLinear_v2

TslibDataModule

PranavBhatP

x

x

x

x

x

2

Samformer_v2

EncoderDecoderTimeSeriesDataModule

fbk_dsipts, PranavBhatP

x

x

x

2

TFT_v2

EncoderDecoderTimeSeriesDataModule

phoeenniixx

x

x

x

x

3

TIDE_v2

EncoderDecoderTimeSeriesDataModule

fbk_dsipts, phoeenniixx

x

x

x

3

TimeXer_v2

TslibDataModule

PranavBhatP

x

x

x

x

3

Implementing new architectures#

Please see the Extension Templates to understand the process and design of the implementations.

Every model should inherit from a base model in _base_model_v2.

class pytorch_forecasting.models.base._base_model_v2.BaseModel(loss: Metric, logging_metrics: list[Module] | None = None, optimizer: Optimizer | str | None = 'adam', optimizer_params: dict | None = None, lr_scheduler: str | None = None, lr_scheduler_params: dict | None = None)[source]

Base model for time series forecasting.

Parameters:
  • loss (Descendants of pytorch_forecasting.metrics.Metric class) – Loss function to use for training.

  • logging_metrics (Optional[List[nn.Module]], optional) – List of metrics to log during training, validation, and testing.

  • optimizer (Optional[Union[Optimizer, str, callable]], optional) – Optimizer to use for training. Can be a string (“adam”, “adamw”, “adagrad”, “sgd”, or any torch.optim class name), a callable returning an optimizer, or an instance of torch.optim.Optimizer.

  • optimizer_params (Optional[Dict], optional) – Parameters for the optimizer.

  • lr_scheduler (Optional[str], optional) – Learning rate scheduler to use. Supported values: “reduce_lr_on_plateau”, “step_lr”, “cosine_annealing”, “cosine_annealing_warm_restarts”.

  • lr_scheduler_params (Optional[Dict], optional) – Parameters for the learning rate scheduler.

API Reference#

See the detailed API documentation for the V2 base classes and specific model implementations below:

models.base._base_model_v2.BaseModel(loss[, ...])

Base model for time series forecasting.

models.base._tslib_base_model_v2.TslibBaseModel(loss)

Base class for tslib models.

models.temporal_fusion_transformer._tft_v2.TFT(loss)

models.dlinear._dlinear_v2.DLinear(loss[, ...])

DLinear: Decomposition Linear Model for Long-Term Time Series Forecasting.

models.samformer._samformer_v2.Samformer(...)

Samformer: Unlocking the Potential of Transformers in Time Series Forecasting with Sharpness-Aware Minimization and Channel-Wise Attention.

models.tide._tide_dsipts._tide_v2.TIDE(...)

Long-term Forecasting with TiDE: Time-series Dense Encoder https://arxiv.org/abs/2304.08424

models.timexer._timexer_v2.TimeXer(loss[, ...])

An implementation of TimeXer model for v2 of pytorch-forecasting.