Exploring Attention Map Reuse for Efficient Transformer Neural Networks

Kyuhong Shim, Jungwook Choi, Wonyong SungarXiv 2023 · DOI

Introduction: The Transformer Bottleneck

Transformers have become the gold standard for sequence modeling across various domains, including Natural Language Processing (NLP) and Automatic Speech Recognition (ASR). However, their core mechanism—self-attention (SA)—suffers from a significant computational hurdle: quadratic complexity. As input sequences grow longer, the cost of comparing every token to every other token ($O(T^2)$) increases exponentially.

This bottleneck is particularly acute in speech recognition. A standard 30-second audio clip can translate into over 750 frames or tokens. In such scenarios, the SA module is no longer just a component; it becomes the primary source of latency, often accounting for over 67% of total inference time. While techniques like sparsification exist, they frequently require specialized hardware or complex indexing that fails to deliver real-world speedups on standard CPUs and GPUs. This paper explores a more structured alternative: Attention Map Reuse.

Methodology: Reusing Attention Maps

The researchers propose a straightforward yet effective strategy to mitigate the quadratic cost of self-attention. Instead of calculating a unique attention map for every layer in a deep network, the model computes it once for a "lead" layer and reuses that map for a subsequent group of layers.

The Core Architecture

The approach was integrated into the Conformer architecture, a popular Transformer variant for speech that interleaves self-attention with convolutional modules to capture both global and local audio patterns.

Architecture of the proposed Attention Map Reuse mechanism, where a lead MHSA layer provides attention maps to subsequent reuse layers.

As shown in the architecture diagram, the lead layer performs standard Multi-Head Self-Attention (MHSA). The resulting attention map ($A_h^l$) is then passed to "Reuse SA" layers. Because these layers do not need to compute new maps, the Query ($Q$) and Key ($K$) linear projections are removed entirely. To compensate for the potential loss in expressive capacity, the authors double the dimension of the Value ($V$) projection and the output projection ($W_O$). This ensures the total parameter count remains comparable to the baseline while significantly reducing matrix multiplications and softmax operations.

Key Insights: Parameters vs. Latency

A critical observation made by the authors is the disconnect between parameter count and execution time. In a standard Conformer, Feed-Forward (FF) modules contain approximately 66% of the model's parameters but are computationally "cheap" because they scale linearly. Conversely, Self-Attention modules hold only about 21% of the parameters but dominate latency due to their quadratic nature.

This redundancy is especially prevalent in speech data. Because audio features change slowly over time, neighboring layers in a speech model often perform highly similar roles, resulting in redundant attention patterns. By exploiting this temporal and hierarchical stability, the model can skip expensive calculations without losing critical information.

Experimental Results

The researchers evaluated their approach using the LibriSpeech dataset, a 1,000-hour benchmark for English speech recognition. They tested configurations denoted as $A \times B$, where $A$ represents the group size (layers sharing a map) and $B$ represents the number of groups.

Inference Speedup

The performance gains were most notable on long sequences. For a 16-layer model, the $4 \times 4$ configuration (sharing one map across 4 layers) achieved a GPU latency reduction of 38% to 52% and a CPU latency reduction of 33% to 61%.

Inference time comparison across sequence lengths, highlighting the quadratic growth of standard self-attention (SA) versus the reduced latency of ReuseSA.

As illustrated in the inference time chart, the "ReuseSA" module maintains a much flatter growth curve compared to standard SA as sequence length increases. This makes the technique particularly valuable for long-form audio processing.

Accuracy and Limits

Remarkably, the $2 \times 8$ and $4 \times 4$ configurations maintained a Word Error Rate (WER) almost identical to the baseline. For instance, on the test-clean subset, the $4 \times 4$ model achieved a 3.3% WER compared to the baseline's 3.2%. Performance only began to degrade significantly at the $8 \times 2$ configuration, suggesting that while redundancy is high, there is a limit to how many layers can share a single attention perspective.

Conclusion and Future Directions

Attention Map Reuse offers a hardware-friendly path to efficient Transformers. Unlike sparse attention, it skips entire blocks of computation in a structured way, making it immediately effective on standard hardware without specialized libraries.

While highly effective for speech, the authors note that the speedups are more modest in NLP tasks where sequence lengths are typically shorter relative to the hidden dimension. Future work may explore heterogeneous reuse, where critical layers compute their own maps while others reuse them more aggressively, or combining this method with other efficiency techniques like local windowing or time-striding.

Summary updated

BibTeX
@misc{shim2023exploring,
  author = {Kyuhong Shim and Jungwook Choi and Wonyong Sung},
  title = {{Exploring Attention Map Reuse for Efficient Transformer Neural Networks}},
  year = {2023},
  eprint = {2301.12444},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2301.12444},
}
Figure