SpAtten: Efficient Sparse Attention Architecture with Cascade Token and Head Pruning

Hanrui Wang, Zhekai Zhang, Song Han

TL;DR

SpAtten is an algorithm-architecture co-design that slashes the heavy computational and memory costs of Transformer models by pruning redundant tokens and attention heads on the fly. By leveraging a novel high-parallelism top-k engine and progressive quantization, it achieves up to 162x speedup and 10x DRAM access reduction over server-grade GPUs without sacrificing accuracy.

What Problem Does This Paper Address?

The attention mechanism has revolutionized Natural Language Processing (NLP), powering models like BERT and GPT. However, this dominance comes at a steep price: quadratic computational complexity relative to input length.

For modern Large Language Models (LLMs), the bottleneck isn't just raw math; it's data movement. Generative models like GPT-2 are often memory-bounded, spending more time moving data (like the KV cache) than actually computing. Existing hardware accelerators designed for CNNs or RNNs struggle with the unique, irregular data patterns of attention. The authors aim to bridge this gap by making attention "spartan"—simple and frugal—through a tight coupling of algorithmic pruning and specialized hardware.

Methods

SpAtten introduces three primary algorithmic optimizations supported by a custom hardware architecture:

  1. Cascade Token Pruning: Inspired by the redundancy of human language, this technique identifies and removes "unimportant" tokens (like prepositions or articles) as data flows through the model layers. Unlike static weight pruning, this happens on the fly based on cumulative importance scores. Once a token is pruned, it is skipped in all subsequent layers, including the Feed-Forward Network (FFN) layers.
  2. Cascade Head Pruning: Similarly, it identifies redundant attention heads. If a head's influence on the output is negligible, it is pruned globally for all following layers.
  3. Progressive Quantization: This is a "fetch-on-demand" strategy for memory. The hardware first fetches only the Most Significant Bits (MSBs) of the data. If the resulting attention probability distribution is "flat" (indicating low confidence), it fetches the Least Significant Bits (LSBs) to refine the result. This trades a bit of extra computation for a massive reduction in DRAM traffic.
Cascade pruning removes redundant tokens and heads globally across layers.

To make these algorithms work in real-time, the authors designed a specialized hardware architecture featuring:

  • A High-Parallelism Top-k Engine: A custom module using quick-select and "zero eliminators" to rank and select tokens/heads in $O(n)$ time, preventing the pruning logic itself from becoming a bottleneck.
  • Reconfigurable Adder Trees: To handle varying query dimensions and pruning ratios efficiently.
  • Bitwidth Converters: To manage the mixed-precision data coming from progressive quantization.

Datasets

The authors evaluated SpAtten across a massive suite of 30 benchmarks, including:

  • GLUE Benchmark: 9 tasks for general natural language understanding.
  • SQuAD (V1.1 and V2.0): For question answering.
  • Language Modeling: Wikitext-2, Wikitext-103, Penn Tree Bank (PTB), and Google One-Billion Word.
  • Models: The system was tested using BERT-Base, BERT-Large, GPT-2-Small, and GPT-2-Medium.

Key Insights and Ideas

  • Input-Dependent Sparsity: Traditional pruning is static. SpAtten realizes that what is "important" changes based on the specific sentence being processed.
  • The "Cascade" Effect: By pruning globally across layers, the savings compound. Pruning a token in Layer 2 means you don't just save on attention in Layer 3; you save on the entire FFN block for that token for the rest of the model.
  • Softmax as an Error Buffer: A key mathematical insight is that the Softmax function naturally reduces quantization errors. This allows for much more aggressive quantization (down to 4 bits) than previously thought possible for attention inputs.
  • Redundancy Visualization: The pruning process is highly interpretable. Visualizing which tokens survive (e.g., "remember", "admire") vs. which are pruned ("it", "is") provides a clear look at how the model focuses on semantic meaning.
Attention probabilities for BERT are summed over each column to get importance scores.

Key Results

SpAtten demonstrates dramatic improvements over both general-purpose hardware and prior state-of-the-art accelerators:

  • Memory Efficiency: Reduces DRAM access by an average of 10.0x.
  • Speedup: Achieves 162x speedup over a TITAN Xp GPU and 347x over a Xeon CPU. Even compared to specialized accelerators like A3 and MNNFast, it is 1.6x to 3.0x faster.
  • Energy Savings: Delivers staggering energy reductions—1193x over GPUs and 4059x over CPUs.
  • Accuracy: These gains come with zero accuracy loss on most benchmarks. Even on the most challenging tasks (BERT-Large on SQuAD), the accuracy drop was limited to ~2%.

Limitations and Future Work

While SpAtten is highly effective, the authors note a few areas for further exploration:

  • Model Specificity: Progressive quantization is highly effective for memory-bounded models like GPT-2 but provides less benefit for computation-bounded models like BERT, where the authors opted for static quantization instead.
  • FFN Bottlenecks: While token pruning helps, the FFN layers still represent a significant portion of the remaining workload. The authors extended the architecture (SpAtten-e2e) to support these, but further optimization of non-attention layers is a clear next step.
  • Generalization: The authors suggest that the "cascade pruning" concept could be generalized to other architectures, such as Memory-Augmented Networks.

Summary updated

BibTeX
@inproceedings{wang2021spatten,
  author = {Hanrui Wang and Zhekai Zhang and Song Han},
  title = {{SpAtten: Efficient Sparse Attention Architecture with Cascade Token and Head Pruning}},
  booktitle = {HPCA},
  year = {2021},
  url = {https://openreview.net/forum?id=EE2TY3fQFK},
}
Figure