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

Romain Ilbert, Ambroise Odonnat, Vasilii Feofanov, Aladin Virmaux, Giuseppe Paolo, Themis Palpanas, Ievgen Redko

TL;DR

Transformers, despite their success in NLP and vision, have struggled with long-term time series forecasting. This paper introduces SAMformer, a lightweight transformer that leverages Sharpness-Aware Minimization (SAM) and channel-wise attention to achieve state-of-the-art performance, outperforming existing methods and even large foundation models while using significantly fewer parameters.

What Problem Does This Paper Address?

Multivariate time series forecasting, the task of predicting future trends from historical data, is crucial for many real-world applications. While transformers have revolutionized other domains, they've lagged behind simpler models in long-term forecasting. This paper investigates why, showing that transformers often converge to poor local minima, leading to a lack of generalization. The authors identify the attention mechanism as a key culprit and propose a solution that addresses both the inherent limitations of transformers in this domain and their training instability.

Methods

The core of SAMformer lies in two key innovations:

  • Channel-Wise Attention: Instead of the typical temporal attention, SAMformer uses attention that operates across channels (features) of the time series. This is argued to be more suitable for time series where feature interactions are more critical than temporal ones, and it also reduces computational complexity.
  • Sharpness-Aware Minimization (SAM): This optimization technique, borrowed from computer vision, aims to find flatter minima in the loss landscape. By minimizing not just the training loss but also its "sharpness" (how quickly the loss changes with small parameter perturbations), SAM encourages models to generalize better. SAMformer applies SAM to a shallow transformer architecture.

The paper also incorporates Reversible Instance Normalization (RevIN), a standard technique in time series forecasting for handling distribution shifts between training and testing data.

Datasets

The authors evaluate SAMformer on 8 publicly available multivariate time series datasets:

  • 4 Electricity Transformer Temperature (ETT) datasets (ETTh1, ETTh2, ETTm1, ETTm2)
  • Electricity (UCI)
  • Exchange
  • Traffic
  • Weather

Key Insights and Ideas

  • Transformers' Achilles' Heel in Forecasting: The paper convincingly demonstrates that even a simple transformer, when applied to a toy linear forecasting problem, struggles to generalize and converges to sharp local minima. This is attributed to the attention mechanism itself.
  • Sharpness Matters: The study highlights that the sharpness of the loss landscape is a critical factor in transformer performance for time series. SAM, by smoothing this landscape, is shown to be highly effective.
  • Channel-Wise Attention is Key: The authors argue that for time series, focusing on inter-feature relationships (channel-wise attention) is more beneficial than traditional temporal attention, leading to better performance and efficiency.
  • Simplicity Can Be Powerful: SAMformer is a shallow, single-layer transformer. This simplicity, combined with SAM and channel-wise attention, allows it to outperform much larger and more complex models.

Key Results

  • State-of-the-Art Performance: SAMformer consistently outperforms existing state-of-the-art methods on 7 out of 8 datasets. It improves over TSMixer+SAM by 5.25% and TSMixer by 14.33%.
  • Competitive with Foundation Models: SAMformer is on par with MOIRAI, a large foundation model for time series forecasting, despite having significantly fewer parameters.
  • Parameter Efficiency: SAMformer uses approximately 4 times fewer parameters than TSMixer, making it a more computationally efficient solution.
  • Robustness: SAMformer shows stable performance across different random initializations, unlike standard transformers which exhibit high variance.
  • Improved Attention: Visualizations show that SAMformer's attention matrices preserve feature self-correlation, unlike standard transformers which can lose this information.

Limitations and Future Work

  • Optimizer Sensitivity: While Adam is used and performs well, the paper notes that other optimizers like SGD can lead to divergence, and AdamW's performance is highly sensitive to hyperparameters.
  • Reparam's Failure: The paper shows that Reparam, a technique aimed at improving attention entropy, does not benefit SAMformer and can even degrade performance while increasing training time.
  • Future Work: The authors believe their simple, yet effective, SAMformer architecture can serve as a strong baseline for future research in time series forecasting. They suggest further exploration of channel-wise attention and its potential in other transformer-based models.

Summary updated

BibTeX
@inproceedings{ilbert2024samformer,
  author = {Romain Ilbert and Ambroise Odonnat and Vasilii Feofanov and Aladin Virmaux and Giuseppe Paolo and Themis Palpanas and Ievgen Redko},
  title = {{SAMformer: Unlocking the Potential of Transformers in Time Series Forecasting with Sharpness-Aware Minimization and Channel-Wise Attention}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=8kLzL5QBh2},
}
Figure