Accelerating Attention through Gradient-Based Learned Runtime Pruning

Zheng Li, Soroush Ghodrati, Amir Yazdanbakhsh, Hadi Esmaeilzadeh, Mingu Kang

TL;DR

This paper introduces a novel hardware-software co-design that accelerates Transformer models by dynamically pruning low-value attention scores at runtime. By formulating layer-wise pruning thresholds as a differentiable regularizer, the authors enable standard backpropagation to co-optimize thresholds and model weights simultaneously. Paired with a custom bit-serial hardware architecture (LeOPArd), this approach delivers up to a 2.4× speedup and 4.0× energy reduction with virtually zero loss in model accuracy.

What Problem Does This Paper Address?

The self-attention mechanism is the backbone of modern Transformer models, enabling state-of-the-art accuracy across natural language processing (NLP) and computer vision tasks. However, this power comes with a massive computational bottleneck: computing attention scores scales quadratically ($O(s^2d)$) with sequence length.

In practice, a word only strongly correlates with a small subset of other words in a sentence, meaning a vast majority of attention computations are inconsequential. While we can theoretically prune these low-value scores at runtime, finding the exact "cutoff" threshold for each layer without destroying model accuracy is incredibly difficult. Prior hardware accelerators relied on manual heuristics, static human input, or statistical sampling to guess these thresholds, frequently leading to unpredictable accuracy drops.

Methods

The authors tackle this challenge using a unified hardware-software co-design approach:

  1. Pruning with a Soft Threshold: To overcome the fact that discrete thresholding is non-differentiable (and thus breaks gradient descent), the authors approximate ideal pruning using a continuous, smooth $\tanh$-based function during a brief fine-tuning phase. This allows gradients to flow normally, letting the training algorithm automatically discover optimal layer-wise thresholds alongside weight updates.
Figure 1: Pruning operation on attention 𝑆𝑐𝑜𝑟𝑒: (a) ideal magnitude-based pruning, (b) proposed differentiable pruning operation with soft threshold.
  1. Differentiable Surrogate $L_0$ Regularization: They introduce a sigmoid-based mathematical surrogate for $L_0$ regularization to explicitly penalize the number of unpruned attention scores in the loss function, safely driving up network sparsity.
  2. LeOPArd Hardware Architecture: To exploit these learned thresholds, the authors design LeOPArd (Learning thrEsholds for On-the-fly Pruning Acceleration of tRansformer moDels). LeOPArd processes matrix multiplications bit-by-bit (bit-serial processing) and dynamically calculates a "conservative margin" at each cycle. If a partial sum plus its maximum possible remaining bit-contribution falls below the learned threshold, the hardware safely terminates the computation early without introducing any approximation errors.
Figure 3: High-level overview of early-compute termination for dot-product operation Q × K𝑇. In this example, K is represented in bit-serial format, whereas Q is in full-precision fixed-point format. In Figure (a-d) each column illustrate one element of K vector and each row represents its corresponding bits (MSB →LSB). K𝑠indicates the sign bit. For simplicity, K elements are scaled to be between -1.0 and +1.0. The table shows the partial sum values after each cycle.

Datasets

The authors rigorously evaluated their approach across 43 distinct backend tasks spanning five major benchmarks:

  • Facebook bAbI: 20 tasks evaluating Memory Networks (MemN2N).
  • GLUE: 9 language understanding tasks evaluating BERT-Base and BERT-Large.
  • SQuAD: Question-answering datasets evaluating BERT and ALBERT-XX-Large.
  • WikiText-2: Language modeling dataset evaluating GPT-2-Large.
  • CIFAR-10: Image classification evaluating the Vision Transformer (ViT-Base).

Key Insights and Ideas

  • Differentiability Bridges the Gap: The core "aha moment" is realizing that hardware threshold selection doesn't have to be a post-training guessing game. Transforming a discrete hardware constraint into a continuous, differentiable optimization problem allows the network to organically learn where it can afford to skip work.
  • Guaranteed Mathematical Correctness: Unlike prior pruning accelerators that accept accuracy trade-offs via lossy approximations, LeOPArd's early termination is exact. The hardware's conservative margin calculation ensures a calculation is only killed if it is mathematically impossible for it to ever cross the pruning threshold.
  • Content-Dependent Sparsity: Because the thresholding is applied dynamically to runtime attention scores, the induced sparsity changes on the fly based on the complexity of the input text or image, maximizing efficiency for simpler inputs.

Key Results

  • Virtually Intact Accuracy: Across all 43 tasks, the average accuracy degradation was kept under 0.2% (e.g., a mere 0.07% drop for MemN2N and 0.07% for ALBERT).
  • High Sparsity Realized: LeOPArd successfully pruned an average of 91.7% of attention scores for MemN2N, 75.5%–78.6% for BERT models, and 73.9% for GPT-2-Large.
  • Substantial Hardware Gains: Compared to a conventional baseline accelerator without pruning, the Highly-Parallel LeOPArd configuration (HP-LeOPArd) achieved an average 2.4× speedup and a 4.0× reduction in total energy consumption.
  • Outperforming the State-of-the-Art: When scaled to a fair 40 nm comparison, HP-LeOPArd delivered up to 3× better energy efficiency (GOPs/J) than SpAtten and significantly better area efficiency than the $A^3$ accelerator, all while maintaining superior accuracy control.

Limitations and Future Work

  • Diminishing Returns on Vision Tasks: The pruning rate for the Vision Transformer (ViT-B) was notably lower (60.3%) than its NLP counterparts. The authors note that visual information in images is inherently more local and less redundant than language tokens, meaning there are fewer safe pruning opportunities in vision layers.
  • Broader Optimization Potential: While this paper focuses strictly on self-attention layers, the authors highlight that their mathematical framework for embedding threshold discovery directly into training loss is highly generalizable. Future work could extend this method to prune other heavy neural network operations, such as standard convolutional or fully connected layers.

Summary updated

BibTeX
@inproceedings{li2022accelerating,
  author = {Zheng Li and Soroush Ghodrati and Amir Yazdanbakhsh and Hadi Esmaeilzadeh and Mingu Kang},
  title = {{Accelerating Attention through Gradient-Based Learned Runtime Pruning}},
  booktitle = {ISCA},
  year = {2022},
  doi = {10.1145/3470496.3527423},
}
Figure