Dynamic layer selection in decoder-only transformers

Theodore Glavas, Joud Chataoui, Florence Regol, Wassim Jabbour, Antonios Valkanas, Boris N. Oreshkin, Mark CoatesarXiv 2024 · DOI

TL;DR

This paper investigates dynamic inference strategies for large language models (LLMs), specifically focusing on layer skipping and early exiting. They find that layer skipping is more effective for decoder-only models in natural language generation, and importantly, that sequence-level dynamic computation allocation can lead to significant efficiency gains, achieving comparable performance to full models with a fraction of the layers.

What Problem Does This Paper Address?

The massive size of modern Large Language Models (LLMs) makes their inference computationally expensive. This is a significant bottleneck for deployment and widespread use. While techniques like quantization and pruning exist, the auto-regressive nature of natural language generation (NLG) presents unique challenges for dynamic inference methods that adapt computation based on the input. Specifically, errors can compound easily in NLG, and the large output vocabulary makes intermediate layer predictions costly. This paper aims to explore and compare different dynamic inference strategies to reduce LLM inference costs without sacrificing performance.

Methods

The authors compare two primary dynamic inference methods:

  • Early Exiting: The model decides to stop processing at an intermediate layer and output a prediction.
  • Layer Skipping: For each layer, a decision is made whether to execute it or bypass it.

They investigate two types of layer skipping controllers:

  • Per-token controllers: These controllers make a decision for each token based on its hidden state.
  • Sequence-level controllers: These controllers make a single decision for the entire sequence.

A key aspect of their work is the comparison of using token hidden states versus a fixed input for the per-token controllers, and the introduction of an "oracle controller" to demonstrate the theoretical potential of sequence-level dynamic allocation.

Datasets

The paper uses the following datasets:

  • Alpaca: A common NLG benchmark for instruction-following and long-form question answering. It has a median prompt length of 43 tokens and a median label length of 42 tokens.
  • CNN-DM (CNN-Daily Mail): Used to further validate findings. It consists of news articles and summaries, with a median prompt length of 788 tokens and a median label length of 66 tokens.

Key Insights and Ideas

  • Layer Skipping > Early Exiting for NLG: For decoder-only models in NLG tasks, layer skipping proves to be a more robust strategy than early exiting for minimizing accumulated hidden state error.
  • Hidden States are Tricky for Per-Token Controllers: Using token hidden states to inform per-token layer skipping decisions did not yield significant performance benefits over using a simple, fixed input for the controller. This suggests that the complexity of hidden states might be too much for simple controllers, or that training the backbone jointly with the controllers introduces a distribution shift.
  • Sequence-Level Control is Promising: Dynamic computation allocation at the sequence level, rather than per-token, holds significant promise for efficiency. An oracle controller demonstrated that it's possible to match full model performance using a much smaller average number of layers.
  • Uniform Layer Skipping is Effective: Even a simple, uniform layer skipping strategy (evenly spacing skipped layers) performed well, especially when compared to early exiting.

Key Results

  • Efficiency Gains: The most striking result is from the sequence-level oracle experiment. It showed that it's possible to achieve performance comparable to the full model using, on average, only 23.3% of its layers (5.6 out of 24 layers for the OPT-1.3B model on the Alpaca dataset).
  • Layer Skipping vs. Early Exiting: Layer skipping consistently preserved the final hidden state better than early exiting, leading to better next-token prediction, even though early exiting showed higher cosine similarity for intermediate hidden states.
  • Per-Token Controller Performance: When comparing controllers that used hidden states versus fixed inputs, the performance was statistically similar, suggesting that for simple controllers, the hidden state information was not leveraged effectively.

Limitations and Future Work

  • Limited Scope: The authors acknowledge that their experiments were constrained by computational resources, limiting the scope of architectures and datasets. Their findings might not generalize to all LLMs or tasks.
  • Controller Design: The performance of controllers is design-dependent. While they used a simple linear layer controller, a more sophisticated design might better utilize hidden state information. However, they argue that computational constraints often necessitate simple controllers.
  • Oracle's "Hindsight": The oracle controller used to demonstrate sequence-level potential benefits from knowing the test set ROUGE scores, which is not feasible in practice. Future work should focus on developing techniques that can make these sequence-level decisions based on the prompt alone, without hindsight.
  • Future Directions: The paper strongly motivates further research into sequence-level dynamic computation allocation, aiming to develop practical methods that can achieve the impressive efficiency gains demonstrated by the oracle.

Summary updated

BibTeX
@misc{glavas2024dynamic,
  author = {Theodore Glavas and Joud Chataoui and Florence Regol and Wassim Jabbour and Antonios Valkanas and Boris N. Oreshkin and Mark Coates},
  title = {{Dynamic layer selection in decoder-only transformers}},
  year = {2024},
  eprint = {2410.20022},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.20022},
}
Figure