Efficient Large-Scale Traffic Forecasting with Transformers: A Spatial Data Management Perspective

Yuchen Fang, Yuxuan Liang, Bo Hui, Zezhi Shao, Liwei Deng, Xu Liu, Xinke Jiang, Kai Zheng

Abstract

Large-scale traffic forecasting presents a significant computational challenge due to the quadratic complexity of modern Spatio-Temporal Graph Neural Networks (STGNNs). This paper introduces PatchSTG, a framework that leverages spatial data management techniques to optimize Transformer-based forecasting. By employing a specialized KDTree for irregular spatial patching and a dual attention mechanism, PatchSTG achieves state-of-the-art accuracy while providing a 10× training speedup and 4× memory reduction compared to existing dynamic modeling approaches.

Introduction

Predicting traffic flow across an entire city is essential for urban planning and navigation. While modern STGNNs, particularly those utilizing dynamic spatial modeling via Transformers, excel at capturing complex spatial dependencies, they suffer from $O(N^2)$ complexity. This "quadratic bottleneck" makes them impractical for large-scale datasets containing thousands of sensors, such as the 8,600-sensor California dataset. Existing efficient alternatives often compromise on accuracy or interpretability. PatchSTG addresses this by integrating spatial indexing with deep learning to maintain high-fidelity attention without the prohibitive overhead.

Methodology

PatchSTG rethinks traffic forecasting through the lens of spatial data management, introducing three core innovations:

Irregular Spatial Patching

Unlike grid-based image data, traffic sensors are irregularly distributed. PatchSTG utilizes a Leaf KDTree to recursively partition sensors based on GPS coordinates. This modified binary search tree ensures that all sensors are allocated to leaf nodes, which are then merged into non-overlapping, equal-sized "patches." This balanced partitioning is critical for maximizing GPU efficiency.

Similarity-Based Padding

To maintain uniform patch sizes for batch processing, unfull patches are padded. Rather than using zero-padding, PatchSTG identifies and pads these patches with the most "temporally similar" points from other patches, calculated via Cosine similarity. This preserves the integrity of the spatial signals.

Dual Attention Encoder

The framework employs a dual attention strategy to capture multi-scale correlations:

  • Depth Attention: Focuses on local correlations within a single spatial patch.
  • Breadth Attention: Captures global correlations by attending to points with the same index across different patches.
The PatchSTG framework: (a) Partitioning sensors using a KDTree, (b) Similarity-based patching and padding, and (c) the Dual Attention mechanism for depth and breadth correlations.

Experimental Evaluation

The model was rigorously tested on the LargeST benchmark, featuring four real-world datasets: San Diego (716 sensors), Greater Bay Area (2,352 sensors), Greater Los Angeles (3,834 sensors), and California (8,600 sensors).

Key Results

  • Accuracy: PatchSTG consistently outperformed 10 major baselines (including D2STGNN and BigST) across all error metrics (MAE, RMSE, MAPE).
  • Efficiency: On the GLA dataset, PatchSTG demonstrated a 10× training speedup over previous state-of-the-art dynamic models.
  • Scalability: The model achieved a 4× reduction in GPU memory consumption, enabling large-scale forecasting on standard hardware.
  • Interpretability: The KDTree-based patches allow learned attention weights to be mapped back to physical city streets, providing actionable insights for urban planners.

Conclusion

PatchSTG demonstrates that efficiency in deep learning can be achieved through intelligent data indexing rather than just mathematical approximations. By treating spatial management as an optimizer, the framework maintains high-fidelity modeling at a fraction of the computational cost. Future work will explore extending this approach to other spatio-temporal domains like air quality and weather forecasting, as well as investigating dynamic patching for evolving network topologies.

Summary updated

BibTeX
@inproceedings{fang2024efficient,
  author = {Yuchen Fang and Yuxuan Liang and Bo Hui and Zezhi Shao and Liwei Deng and Xu Liu and Xinke Jiang and Kai Zheng},
  title = {{Efficient Large-Scale Traffic Forecasting with Transformers: A Spatial Data Management Perspective}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2024},
}
Figure