Implementation:Sktime Pytorch forecasting xLSTMTime
| Knowledge Sources | |
|---|---|
| Domains | Time_Series, Forecasting, Deep_Learning |
| Last Updated | 2026-02-08 08:00 GMT |
Overview
xLSTMTime is an extended LSTM model for long-term time series forecasting, extending AutoRegressiveBaseModel with series decomposition, batch normalization, and either sLSTM (scalar-memory stabilized) or mLSTM (matrix-memory) recurrent variants.
Description
xLSTMTime implements the architecture from the paper "xLSTMTime: Long-term Time Series Forecasting With xLSTM" (arXiv:2407.10240). The model first decomposes the input into trend and seasonal components using a moving-average kernel, concatenates both components, projects them through a linear layer, applies batch normalization, and feeds the result through the selected xLSTM variant (sLSTM or mLSTM). The output is then projected to the forecast horizon and normalized with instance normalization. This design combines classical time series decomposition with enhanced LSTM architectures featuring exponential gating and richer memory dynamics.
Usage
Use xLSTMTime when you need a recurrent architecture for long-horizon time series forecasting that goes beyond standard LSTMs. It is particularly effective when the time series exhibits clear trend and seasonal patterns that benefit from explicit decomposition, and when matrix-memory (mLSTM) or stabilized scalar-memory (sLSTM) variants can capture complex temporal dependencies.
Code Reference
Source Location
- Repository: Sktime_Pytorch_forecasting
- File: pytorch_forecasting/models/xlstm/_xlstm.py
- Lines: 1-179
Signature
class xLSTMTime(AutoRegressiveBaseModel):
def __init__(
self,
input_size: int,
hidden_size: int,
output_size: int,
xlstm_type: Literal["slstm", "mlstm"] = "slstm",
num_layers: int = 1,
decomposition_kernel: int = 25,
input_projection_size: int | None = None,
dropout: float = 0.1,
loss: Metric = SMAPE(),
**kwargs,
):
Import
from pytorch_forecasting.models.xlstm import xLSTMTime
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input_size | int | Yes | Number of input continuous features per time step |
| hidden_size | int | Yes | Hidden size of the xLSTM network; also used by batch normalization and LSTM internals |
| output_size | int | Yes | Number of output features per time step (forecast horizon) |
| xlstm_type | Literal["slstm", "mlstm"] | No | Which xLSTM variant to use: "slstm" for stabilized scalar-memory LSTM, "mlstm" for matrix-memory variant; defaults to "slstm" |
| num_layers | int | No | Number of recurrent layers in the sLSTM or mLSTM network; defaults to 1 |
| decomposition_kernel | int | No | Kernel size for series decomposition into trend and seasonal components; defaults to 25 |
| input_projection_size | int or None | No | If specified, projects the encoded input to this size before feeding to xLSTM; otherwise equals hidden_size |
| dropout | float | No | Dropout rate applied within the recurrent layers; defaults to 0.1 |
| loss | Metric | No | Loss and evaluation metric used during training; defaults to SMAPE() |
Outputs
| Name | Type | Description |
|---|---|---|
| forward(x) | dict[str, torch.Tensor] | Network output dictionary with key "prediction" containing a tensor of shape (batch_size, output_size, 1) |
Usage Examples
from pytorch_forecasting.models.xlstm import xLSTMTime
from pytorch_forecasting.metrics import SMAPE
# Create an xLSTMTime model with the sLSTM variant
model = xLSTMTime(
input_size=7,
hidden_size=128,
output_size=24,
xlstm_type="slstm",
num_layers=2,
decomposition_kernel=25,
dropout=0.1,
loss=SMAPE(),
)
# Alternatively, create from a TimeSeriesDataSet
model = xLSTMTime.from_dataset(
dataset,
input_size=7,
hidden_size=128,
output_size=24,
xlstm_type="mlstm",
num_layers=1,
)