TiRex Time Series Forecasting Model

repository·main·Indexed 43 days ago

https://github.com/nx-ai/tirex

A 35M parameter pre-trained time series forecasting model based on xLSTM, designed for zero-shot forecasting across long and short horizons. TiRex supports classification and regression tasks, providing both point and quantile estimates. It is available as the tirex-ts Python package (v1.4.2) and can be deployed via CPU and GPU Docker containers with an HTTP API for forecasting.

Tokens
30.5K
Snippets
94
Records
138
Agent score
54%

What's inside TiRex

  1. Overview of Time Series Forecasting with TiRex

    main

    TiRex provides zero-shot forecasting capabilities by leveraging the xLSTM architecture. It is designed to capture long-range dependencies and temporal dynamics, making it suitable for highly irregular or complex time series.

    To master forecasting with TiRex, follow these three pillars:

    1. Theory: Understand the xLSTM architecture, frequency-based resampling, patching, and how zero-shot generalization is achieved.
    2. Workflow: Follow the structured playbook for data preparation (scaling and adapters), configuring forecast parameters (quantiles, batching, devices), and using evaluation scripts (sMAPE, MASE, CRPS).
    3. Practice: Implement forecasting by preparing data, running models in zero-shot mode using load_model, and evaluating/visualizing results.
  2. Overview of TiRex

    main

    TiRex is a zero-shot forecasting model designed to handle both long and short horizons. It leverages enhanced in-context learning to provide forecasting capabilities without requiring task-specific fine-tuning. The project includes specialized models for both forecasting (regression) and time series classification, and is built upon the xLSTM (Extended Long Short-Term Memory) architecture.

    Key resources available:

    • Forecasting Playbook: Theory and hands-on guides for time series forecasting.
    • Benchmarks: Evaluation results using datasets and metrics such as sMAPE, MASE, and CRPS.
    • Deployment: Guidance on packaging, ONNX/TensorRT export, and edge deployment.
  3. Overview of Time Series Classification with TiRex

    main
    TiRex performs time series classification by leveraging the xLSTM architecture to extract features from time series data. It is designed to handle highly irregular or complex time series efficiently. The classification capability is built on a zero-shot protocol where a frozen TiRex forecasting model acts as a feature extractor.
  4. Overview of Time Series Regression with TiRex

    main

    TiRex performs time series regression by leveraging a frozen, pre-trained TiRex forecasting model as a feature extractor. The model uses xLSTM to extract embeddings from time series data (including highly irregular or complex series). These embeddings are then passed into a task-specific regression head that maps the features to continuous target values.

    Key architectural concepts:

    • Zero-shot feature extraction: The core forecasting model remains frozen.
    • Embedding extraction: Features are extracted and aggregated from the time series.
    • Regression head: A trainable layer added on top of the frozen embeddings to predict continuous values.
  5. What is the xLSTM architecture in TiRex?

    main

    TiRex is built on the xLSTM (Extended Long Short-Term Memory) architecture. xLSTM is a next-generation recurrent model that combines the efficiency and interpretability of classic RNNs with the long-range modeling capabilities of Transformers.

    Key architectural features include:

    • Expanded Memory Dynamics: Uses additional multiplicative interactions and normalization mechanisms to improve temporal credit assignment over long horizons.
    • Hierarchical Temporal Abstraction: Processes signals at multiple scales (daily, weekly, seasonal) using frequency-aware resampling based on FFT-derived periodicity.
    • Parameter Efficiency: Provides high accuracy with fewer parameters and lower latency than Transformers, making it suitable for Edge and industrial deployments.
    • Zero-Shot Capability: Trained on a broad mixture of domains to enable generalization to unseen datasets without fine-tuning.
  6. What is TiRex and how does it work?

    main

    TiRex is a 35M parameter pre-trained time series forecasting model built on the xLSTM (Extended Long Short-Term Memory) architecture.

    It is designed for Zero-Shot Forecasting, meaning it can perform time series forecasting on new datasets immediately after download without requiring any task-specific training or fine-tuning.

    Key capabilities include:

    • Quantile Predictions: It provides both point estimates and quantile estimates (useful for uncertainty quantification).
    • Multi-Horizon Performance: It is optimized for both long-term and short-term forecasting horizons.
    • Sequence Modeling: It leverages xLSTM's ability to capture long-range dependencies and complex patterns in time series data.
  7. The TiRex classification transformation pipeline

    main

    The classification process follows a specific sequence of transformations to convert raw time series into class predictions:

    1. Hidden States Extraction: Extract hidden states from all layers of the TiRex forecasting model.
    2. Sequence Aggregation: Apply mean pooling across the sequence dimension.
    3. Embedding Normalization: Normalize embeddings to account for different feature spaces across layers.
    4. Layer Aggregation: Concatenate the features from each layer.
    5. Optional Embedding Augmentations:
      • Differenced-series embeddings: To identify subtle patterns.
      • Absolute sample statistics: To restore scale information lost during normalization.
    6. Simple Classifier Prediction: A classification head (such as Random Forest, Linear Layer, or Gradient Boosting) is trained on the final embedding to map it to class labels.
  8. Use the Tirex Regression Model interface

    main

    TiRex provides three primary regressor implementations within the tirex.models.regression module. All regressor classes follow a consistent API pattern for training, inference, and persistence.

    Available models:

    • TirexLinearRegressor: Linear regression implementation.
    • TirexRFRegressor: Random Forest regression implementation.
    • TirexGBMRegressor: Gradient Boosting Machine regression implementation.

    Each model supports the following methods:

    • fit(X, y): Trains the model on the provided features X and targets y.
    • predict(X): Generates predictions for the input features X.
    • save_model(path): Serializes and saves the trained model to the specified path.
    • load_model(path): Loads a previously saved model from the specified path.
  9. How the TiRex classification model works

    main

    TiRex performs time series classification using a zero-shot approach where a pre-trained TiRex forecasting model acts as a frozen feature extractor. Instead of training on raw data, the model maps time series to latent representations which are then processed by a classification head.

    Core Architecture

    • Feature Extraction: The pre-trained forecasting model is used as a frozen backbone; no parameters are updated during classification.
    • Embedding Extraction: Hidden states from all xLSTM layers are extracted to capture information at multiple abstraction levels.
    • Sequence Aggregation: Mean pooling is applied across the sequence dimension to handle variable-length series.
    • Multivariate Handling: For multivariate series, each variate is treated independently, producing a dedicated embedding for each.

    Embedding Augmentations

    To improve accuracy, the base embeddings can be augmented with:

    1. Time Series Differencing: First-order differencing (difference between consecutive time steps) is used to isolate subtle patterns from dominant trends.
    2. Absolute Sample Statistics: To restore scale information, the raw series is split into 8 non-overlapping patches. For each patch, the mean, standard deviation, minimum, and maximum values are calculated and concatenated to the embedding.
  10. Use Tirex classification models

    main

    The tirex.models.classification module provides three main classifier implementations for time-series classification tasks:

    1. TirexLinearClassifier: A linear model implementation.
    2. TirexRFClassifier: A Random Forest implementation.
    3. TirexGBMClassifier: A Gradient Boosting Machine implementation.

    All classifiers share a common interface for training, inference, and persistence.

  11. How TiRex forecasting works

    main

    TiRex performs forecasting through a four-stage transformation pipeline designed to handle varying temporal resolutions and provide probabilistic outputs:

    1. Input normalization: Scales and aligns the input time series for consistency.
    2. Frequency-based resampling: Adjusts the temporal resolution to align the dominant frequencies of the signal with the model's patch size.
    3. xLSTM-based sequence modeling: Uses the xLSTM (Extended Long Short-Term Memory) architecture to encode both long-term and short-term dependencies into a compact representation.
    4. Probabilistic decoding: Generates multiple quantile forecasts to represent the predictive distribution rather than a single point estimate.

    This pipeline allows TiRex to achieve zero-shot forecasting, meaning it can generalize to unseen datasets across different domains (e.g., demand, energy, or environmental forecasting) without requiring fine-tuning.

  12. Understand the TiRex Classification Theory

    main

    To understand the underlying mechanics of how TiRex classifies time series, refer to the theoretical documentation. Key concepts include:

    • Zero-shot protocol: Using a frozen TiRex forecasting model as a feature extractor.
    • Embedding strategies: How embeddings are extracted and aggregated.
    • Multivariate handling: How the model processes multivariate time series.
    • Augmentation: Embedding augmentation techniques used to improve performance.
    • Transformation pipeline: The conceptual flow of the classification transformation.