Attention Is All You Need But You Don't Need All Of It For Inference of Large Language Models

Georgy Tyukin, Gbètondji J.-s. Dovonon, Jean Kaddour, Pasquale Minervini

TL;DR

This paper explores the impact of removing parts of Large Language Models (LLMs) during inference to speed them up without significantly hurting performance. They found that dropping deeper attention layers is surprisingly effective, offering substantial speedups with minimal accuracy loss, and is more beneficial than dropping MLP layers.

What Problem Does This Paper Address?

The inference phase of Large Language Models (LLMs) is becoming a major bottleneck. As LLMs grow larger and are deployed more widely, the computational cost and latency associated with generating responses become significant challenges. A key culprit is the self-attention mechanism, which has a quadratic complexity with respect to input sequence length. This paper investigates whether parts of these complex models, specifically attention or MLP (Multi-Layer Perceptron) layers, can be removed during inference to achieve faster speeds without a drastic drop in performance.

Methods

The researchers experimented with different strategies for "layer skipping" on Llama-v2 models (7B and 13B parameters). They defined three main methods:

  1. Skipping MLP Layers: Removing the MLP sub-layer from the last k layers.
  2. Skipping Attention Layers: Removing the attention sub-layer from the last k layers.
  3. Skipping Transformer Blocks: Removing entire blocks (both attention and MLP) from the last k layers.

They also explored variations where the very last layer was preserved, hypothesizing that deeper layers might be less critical. The performance was evaluated on the OpenLLM benchmark, and inference speed was measured by timing sequence generation.

Datasets

The models were evaluated on the OpenLLM benchmark, which includes datasets such as:

  • ARC (AI2 Reasoning Challenge)
  • HellaSwag
  • TruthfulQA
  • MMLU (Massive Multitask Language Understanding)

The paper does not mention new datasets being introduced or used for training.

Key Insights and Ideas

  • Deeper Attention Layers are Surprisingly Expendable: The most striking finding is that removing deeper attention layers has a much smaller impact on performance than removing MLP layers. This suggests that the information processed by these later attention layers might be redundant or less critical for overall task performance.
  • Attention Layers Offer Better Speedups: Skipping attention layers not only leads to smaller performance drops but also provides better inference speedups compared to skipping MLP layers.
  • The Last Layer Matters (Sometimes): While generally deeper layers are less important, preserving the very last layer in some skipping configurations yielded interesting results, particularly for TruthfulQA performance.
  • MLP Layers are More Crucial: The results indicate that MLP layers are more integral to the model's performance, as dropping them leads to more significant accuracy degradation.

Key Results

  • Significant Speedups with Minimal Performance Loss: Removing 33% of attention layers in a 13B Llama2 model resulted in an 18% speedup with only a 1.8% drop in average performance on the OpenLLM benchmark.
  • Full Layer Skipping is Fastest but Costly: Skipping entire Transformer blocks (both attention and MLP) provided the best speed improvements, but at a higher performance cost compared to selectively dropping attention layers.
  • TruthfulQA Anomaly: Performance on the TruthfulQA dataset showed an unexpected increase or smaller drop when layers were skipped, suggesting that model reduction might sometimes improve truthfulness.
  • Quantitative Comparisons: Tables in the paper provide detailed breakdowns of performance (accuracy across different benchmarks) and inference time for various percentages of skipped layers (66%, 75%, 90%, 100% of the network remaining). For instance, skipping full layers on Llama-v2 7B (keeping 66%) resulted in a significant speedup (e.g., ~43% faster for 50-length sequences) but a drop in average accuracy from 54.3% to 42.1%.

Limitations and Future Work

  • Focus on Llama-v2: The study is limited to Llama-v2 models. Future work could explore these techniques on other LLM architectures.
  • Inference Only: The research focuses solely on inference-time optimizations. The authors suggest that exploring layer dropping/growing during training could be a fruitful avenue.
  • Fine-tuning for Compensation: The paper mentions that fine-tuning might help compensate for performance drops incurred by layer skipping, which could be an area for future investigation.
  • Understanding the "Why": While the paper shows what happens when layers are dropped, further research could delve deeper into why certain layers are more redundant than others, potentially through more detailed analysis of attention patterns and feature representations.

Summary updated

BibTeX
@inproceedings{tyukin2024attention,
  author = {Georgy Tyukin and Gbètondji J.-S. Dovonon and Jean Kaddour and Pasquale Minervini},
  title = {{Attention Is All You Need But You Don't Need All Of It For Inference of Large Language Models}},
  booktitle = {TF2M @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=QSCU5YFqbM},
}
Figure