> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/sdgm/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/sdgm/_mcp/server.

# Time Series Forecasting

> How Graph Transformers use relational context, temporal signals, and diffusion models for time series forecasting

**Source title:** Time Series Forecasting with Graph Transformers\

**Originally published:** June 17, 2025\

**Authors:** Jan Eric Lenssen and Matthias Fey

## Why graph structure matters for forecasting

Most time series forecasting treats every sequence in isolation.
For example, a model might use Store #42's daily sales history to predict that store's future sales.
Facebook Prophet, ARIMA, and many deep-learning forecasters use this one-sequence-in, one-forecast-out pattern.

Real-world time series rarely exist in a vacuum.
Store sales can depend on geography, stocked products, marketing campaigns, nearby competitors, and customer behavior.
That context lives in related database tables connected through foreign keys: stores, products, transactions, customers, and campaigns.

Time series in relational databases are therefore naturally graph-structured.
Each entity, such as a store, product, or customer, is a node.
Foreign-key relationships are edges.
The forecast target is an attribute of a particular node, while signals that influence it can propagate across the graph.

**Analogy:** Forecasting foot traffic at a shopping mall from the mall's history reveals trend and seasonality.
Knowing that a nearby competitor closed, new anchor tenants signed leases, or neighborhood demographics changed can produce a much better forecast.
That additional context is in related tables, not in the time series itself.

Graph Transformers encode this relational context directly in the forecasting pipeline.
Instead of hand-engineering features from related tables, the model learns which cross-table signals matter and how they affect future values.

Traditional forecasters discard relational context that may contain the strongest predictive signals.
Graph Transformers treat the entire relational database as a graph and learn cross-table patterns automatically.

## The four conditioning signals

![Five-stage forecasting pipeline: combine date-time encodings, calendar embeddings, a Graph Transformer entity encoding, and a past sequence encoding to produce a forecast.](https://fdr-prod-docs-files-public.s3.us-east-1.amazonaws.com/nvidia-sdgm.docs.buildwithfern.com/1e9733f2b872f1b22a044c1361e31f96d83b74ea95765399403f999b7094e303/img/research/time-series-conditioning-pipeline.svg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA6KXJSKKNFOCF7G4B%2F20260920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260920T164628Z&X-Amz-Expires=604800&X-Amz-Signature=fb188f081eb768062f01f0cd9c3ce50ccb2c80c6cc02cd27477147974bdd4460&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject)

The framework predicts a future value for entity *e* at time *t* by conditioning on four signal types:

`x_e(t) = f(rho(t), c, z_e, p_e)`

| Signal                                  | Role                                                                                 |
| --------------------------------------- | ------------------------------------------------------------------------------------ |
| Date-time frequency encodings, `rho(t)` | Encodes date, time of day, day of week, month, and other cyclical temporal features. |
| Calendar embeddings, `c`                | Uses 1D CNNs over holidays and events, including lead and lag context windows.       |
| Graph entity encodings, `z_e`           | Uses a Graph Transformer to summarize the entity's temporal relational neighborhood. |
| Past sequence encodings, `p_e`          | Uses a sequence model over the entity's historical values.                           |

The source reports that 1D temporal convolutions provided the best efficiency-to-accuracy tradeoff for past sequence encoding among the tested transformer, CNN, and MLP options.

Date-time and calendar signals capture when patterns occur.
Graph entity encodings capture related context.
Past-sequence encodings capture what happened before.
The model learns how to weight all four for each prediction.

## How Graph Transformers encode relational structure

The graph encoding step turns a local neighborhood of the relational graph into a dense vector that captures cross-table signals for the target entity.

### Temporal subgraph sampling

For each entity being forecast, the framework samples a subgraph from the relational database.
The sampling is temporally aware: it includes only nodes and edges with timestamps before the prediction time.
This prevents data leakage during training and inference.

For example, a forecast for Store #42's visits next Tuesday can include prior transactions, the associated products, customers who made those transactions, and their features, but not information from after the prediction date.

### Graph Transformer processing

A Graph Transformer processes the sampled subgraph with positional encodings that adapt the Transformer architecture to graph-structured inputs.
Rather than sequential position, it encodes each node's structural position in the graph so attention can use both node features and topology.

The resulting target-entity embedding is:

`z_e = T(G_e, X_e)`

Here, `G_e` is the sampled subgraph structure and `X_e` is its node-feature matrix.

Standard GNNs such as GCN and GraphSAGE aggregate neighbors through fixed message-passing rules.
Graph Transformers use attention across the sampled subgraph, allowing a model to assign high weight to a distant but relevant node and low weight to a nearby but irrelevant one.

**Analogy:** A Graph Transformer reads a relational neighborhood like an analyst reads a case file.
It considers the subject, their connections, the nature of those connections, and network-wide patterns, learning which evidence matters for the prediction.

Temporal subgraph sampling and Graph Transformer attention work together: sampling prevents leakage, while attention identifies the related entities that carry predictive signal.

## Regression versus generative forecasting

![Comparison of regression and generative diffusion forecasting. Regression is fast and produces point estimates, while diffusion forecasting produces distributions and uncertainty bands at a higher inference cost.](https://fdr-prod-docs-files-public.s3.us-east-1.amazonaws.com/nvidia-sdgm.docs.buildwithfern.com/a54609933a67e41dd2afe9ae46a9a4ba7c491efabbef86f602a7e255b6dd040b/img/research/time-series-forecasting-approaches.svg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA6KXJSKKNFOCF7G4B%2F20260920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260920T164628Z&X-Amz-Expires=604800&X-Amz-Signature=1750b5de3c86fe761715f136c3514c663c0a399c88e6c899b655497712c9b6ed&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject)

The framework supports two ways to produce forecasts.

### Regression approach

The predictive model uses MLPs trained with mean-squared error loss.
Given the four conditioning signals, it returns one point estimate for each future timestep.
For smooth, unimodal series, this works well.

For multimodal outcomes, MSE-trained point estimates can exhibit mean collapse.
If daily store visits are plausibly either 50 on a normal day or 200 on an event day, a point model may predict 125, even though that value is the least likely outcome.

### Generative approach

The generative model uses conditional denoising diffusion probabilistic models (DDPMs).
Starting from Gaussian noise, it iteratively refines a forecast conditioned on the same four signals.
Each run produces one sample from the learned distribution.

Multiple samples can yield quantile bands for confidence intervals, distinct plausible modes, and uncertainty estimates that change across the forecast horizon.

**Analogy:** A regression model answers, "What single value should I predict?"
A generative model answers, "What range of futures is plausible?"
For inventory planning, that difference can change the decision.

Diffusion forecasting can avoid mean collapse and retain high-frequency detail, but the source's DDPM schedule requires 1,000 denoising steps per sample rather than one forward pass.

## Training: temporal sampling and loss

Time series training must preserve temporal order to avoid leakage.
For each training iteration, the framework:

1. Samples a time point from the training period.
2. Builds a temporal subgraph from information before that point.
3. Computes the four conditioning signals at that point.
4. Predicts values for the forecast horizon.
5. Minimizes loss against the ground-truth future values.

For regression, the source uses MSE over entities and future timesteps.
For the generative model, it adds noise to the ground-truth future sequence at a random level in the DDPM schedule, then trains the denoising network to predict that noise.

Temporal sampling provides more than leakage prevention.
By sampling different points, the model sees entities at multiple stages of their histories and can learn how relational context changes over time.

## Forecasting results

The source evaluated 90-day daily store-visit forecasts using Facebook Prophet, a predictive Graph Transformer, and a generative Graph Transformer.

| Method                       |      MAE |     MAPE |
| ---------------------------- | -------: | -------: |
| Facebook Prophet             |     5.87 |     0.21 |
| Predictive Graph Transformer | **5.26** | **0.18** |
| Generative Graph Transformer |     5.29 | **0.18** |

The predictive Graph Transformer reduced MAE from 5.87 to 5.26, a reported 10.4% error reduction.
MAPE fell from 0.21 to 0.18, a reported 14.3% relative improvement.
The generative model matched the predictive model's MAPE with nearly identical MAE, while optimizing for distributional rather than point accuracy.

The source attributes the gain to relational context.
Prophet sees the store's historical visits alone, while the graph models can also use connected transaction patterns, product-level data, customer behavior, and other foreign-key-linked tables.

In the source evaluation, both graph-based models achieved 0.18 MAPE compared with Prophet's 0.21.
The generative model additionally provides distributional forecasts and uncertainty quantification.

## Practical implications and tools

This approach is most useful when a forecast target has meaningful relational context.

* **Multiple related tables:** Product catalogs, customer profiles, marketing campaigns, geography, and supplier data can provide additional signal through foreign-key relationships.
* **Entity-level forecasts:** Per-store, per-product, or per-customer forecasts can benefit more from a unique relational neighborhood than a company-wide aggregate forecast.
* **Uncertainty-sensitive decisions:** Inventory planning, capacity allocation, and risk management can benefit from a distribution rather than a single point estimate.

The framework builds on [PyTorch Geometric](https://github.com/pyg-team/pytorch_geometric) for Graph Transformer implementations, temporal sampling utilities, and graph data structures.
It also uses [RelBench](https://relbench.stanford.edu) for relational-data benchmarks, including the forecasting scenarios discussed in the source.
Relational deep learning supplies the broader pattern of turning multi-table databases into graphs without manual feature engineering.

Product demand forecasting, workforce scheduling, energy-load prediction, and financial-metric forecasting all contain time series embedded in relational data.
The key architectural choice is to treat that relational context as a first-class input rather than discard it or manually flatten it into features.

## Further reading

* [PyTorch Geometric](https://github.com/pyg-team/pytorch_geometric)
* [RelBench](https://relbench.stanford.edu)
* [Relational Deep Learning](/research/relational-deep-learning)
* [Relational Graph Transformers](/research/relational-graph-transformers)