Do Efficient Transformers Really Save Computation?

Kai Yang, Jan Ackermann, Zhenyu He, Guhao Feng, Bohang Zhang, Yunzhen Feng, Qiwei Ye, Di He, Liwei Wang

Abstract

While "efficient" Transformer variants, such as Sparse and Linear Transformers, are designed to circumvent the quadratic scaling of standard self-attention, their practical computational benefits are often misunderstood. This paper investigates whether these architectures can maintain reasoning capabilities as sequence lengths increase. We demonstrate a "hidden cost" to efficiency: for general reasoning tasks, the model size (hidden dimension) of efficient Transformers must grow with the problem length to maintain accuracy. This growth causes their total computational complexity to revert to $O(L^2)$, matching standard Transformers. Our findings suggest that efficient Transformers only provide true computational savings when tasks exhibit "locality," where each reasoning step depends only on a fixed window of recent information.

Introduction

The standard Transformer architecture has become the backbone of modern AI, yet its self-attention mechanism scales quadratically ($O(L^2)$) with the sequence length $L$. This scaling makes processing long documents or complex multi-step reasoning tasks prohibitively expensive. In response, researchers have developed "efficient" alternatives. Sparse Transformers reduce complexity by attending only to specific blocks of tokens, while Linear Transformers use kernel-based approximations to achieve linear scaling.

However, the theoretical limits of these efficient models remain under-explored. Specifically, it is unclear if they can handle complex reasoning as effectively as the original architecture. This paper addresses this gap by evaluating whether efficient Transformers can solve Dynamic Programming (DP) problems—a standard proxy for multi-step reasoning—without a proportional increase in model parameters.

Theoretical Framework: Reasoning as Dynamic Programming

To rigorously compare architectures, the authors model reasoning as a Dynamic Programming process. In this framework, a problem is decomposed into sub-problems (states) that are solved sequentially, often facilitated by Chain-of-Thought (CoT) prompting.

The study focuses on the relationship between sequence length ($L$) and the required hidden dimension ($D$). A key contribution is the introduction of the $m$-locality assumption. A reasoning task is considered $m$-local if a specific reasoning step only requires information from the $m$ most recent steps. This distinction allows the authors to identify the specific conditions under which efficient models actually deliver on their promise of reduced computation.

The Information Bottleneck Paradox

The core finding of the paper is a theoretical lower bound on the hidden dimension required for efficient Transformers. For general (non-local) reasoning tasks, the authors prove that Sparse and Linear Transformers suffer from an information bottleneck. To successfully solve a problem of length $L$, these models require a hidden dimension $D$ that scales as $\Omega(\sqrt{L})$.

Because the total computational complexity of these models is roughly $O(L \cdot D^2)$, substituting $D \approx \sqrt{L}$ results in a total complexity of $O(L^2)$. This reveals a paradox: the very models designed to avoid quadratic scaling end up requiring quadratic total computation to maintain reasoning performance.

In contrast, standard Transformers are shown to be size-invariant. They can solve these same reasoning tasks using a constant hidden dimension, regardless of the problem's length. While the attention mechanism itself is $O(L^2)$, the model size does not need to grow, often making the standard Transformer more efficient in practice for complex tasks.

Experimental Validation

The authors tested these theoretical bounds across several representative DP tasks:

  1. Arithmetic Evaluation: Solving nested expressions (e.g., 2 × (1 + 5) ÷ 4). This task contains inherent structure and partial locality.
  2. Edit Distance (ED): A classic DP problem that satisfies the locality assumption.
  3. Longest Increasing Subsequence (LIS): A "global" DP problem where each step may depend on any previous element in the sequence, serving as a stress test for architectures.

The empirical results mirrored the theoretical proofs. As sequence lengths increased, the accuracy of Sparse and Linear Transformers plummeted unless their embedding dimensions were significantly increased. Standard Transformers, however, maintained near 100% accuracy with a fixed, small dimension.

Furthermore, when measuring actual efficiency in GFLOPs, the standard Transformer was often the most efficient. For example, on the Arithmetic task at a length of 505, the standard model required only ~0.6 GFLOPs to reach 90% accuracy, whereas the Linear variant required ~9.5 GFLOPs to achieve the same performance level.

Conclusion and Future Work

The study concludes that locality is the "secret sauce" for efficient Transformers. These architectures only truly save computation when the problem allows for a restricted look-back window. For general reasoning that requires accessing arbitrary past states, the standard Transformer remains the more computationally efficient choice because it avoids the need for an ever-expanding hidden dimension.

While this work focuses on Sparse and Linear Transformers, it opens the door for future analysis of newer architectures, such as State Space Models (SSMs) like Mamba. Understanding whether these newer designs can overcome the information bottleneck without reverting to quadratic complexity remains a critical question for the field of efficient deep learning.

Summary updated

BibTeX
@inproceedings{yang2024do,
  author = {Kai Yang and Jan Ackermann and Zhenyu He and Guhao Feng and Bohang Zhang and Yunzhen Feng and Qiwei Ye and Di He and Liwei Wang},
  title = {{Do Efficient Transformers Really Save Computation?}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=xLikRS9OhW},
}
Figure