Quadratic Attention Bottleneck › The Bottleneck Visualization

Michael BrenndoerferUpdated June 21, 20254 min read
Language AI HandbookAll chapters
Part 17 of 67Efficient Attention
Chapter 117Quadratic Attention Bottleneck › The Bottleneck Visualization
Reading section 7 of 13 · The Bottleneck Visualization · 4 minSection 7 of 13 · 4 min

Book contents

Section 7 of 13 · 4 min read

Quadratic Attention Bottleneck › The Bottleneck VisualizationOne section · Sections in this chapter7 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

To fully appreciate the quadratic bottleneck, we can visualize how attention costs compare to other transformer components as sequence length grows. The transformer is not only attention: it also includes feed-forward networks (FFN), layer normalization, and QKV linear projections. At short sequences, these other components can dominate. At long sequences, the quadratic attention core takes over.

The key conceptual point is that every other component in a transformer scales linearly with sequence length. The feed-forward network processes each token independently, so its cost grows as O(nd2)O(nd^2). The QKV projection matrices each perform an (n×d)×(d×d)(n \times d) \times (d \times d) matrix multiplication, costing O(nd2)O(nd^2). Layer normalization costs O(nd)O(nd). None of these touch the n2n^2 term.

This means the bottleneck is not a static property of the model architecture but a dynamic one that emerges as sequences grow. For short sequences, attention is just another cheap operation. The crossover point, where attention becomes the dominant cost, depends on the ratio of nn to dd.

Out[16]:
Visualization
Stacked area chart showing feed-forward network costs staying linear while attention costs grow quadratically to dominate at long sequence lengths.
Proportion of total transformer FLOPs consumed by each component as sequence length increases, for a model with d=768. At short sequences (128-256 tokens), the feed-forward network and projection matrices dominate, and attention contributes less than 10 percent. As sequences grow past the crossover region (1K-2K tokens), the quadratic attention core takes an ever-increasing share. By 16K tokens, attention accounts for over 80 percent of all transformer operations.

At short sequence lengths (128-256 tokens), the feed-forward network and projections dominate, and attention contributes less than 10% of total computation. As sequences grow, the quadratic term takes over. By 4K tokens, attention accounts for nearly half of all operations. At 16K tokens and beyond, attention consumes the vast majority of the compute budget, squeezing out everything else.

This is the attention bottleneck in visual form. Optimizing transformers for long sequences means addressing the red region in this chart. The feed-forward and projection components (orange and blue) scale linearly, which is theoretically optimal for per-token processing. It is attention's all-pairs structure that breaks linear scaling and creates the growing red region.

The crossover region around 1K-2K tokens is particularly important for practical system design. Models that process sequences mostly below this threshold can be optimized for the FFN and projection costs. Models that routinely process longer sequences must prioritize attention efficiency. This is one reason why code models and document models have driven much of the efficient attention research: they deal with long inputs by nature.