Accelerating Inference in Large Language Models with a Unified Layer Skipping Strategy

Yijin Liu, Fandong Meng, Jie ZhouarXiv 2024

Abstract

Recently, dynamic computation methods have shown notable acceleration for Large Language Models (LLMs) by skipping several layers of computations through elaborate heuristics or additional predictors. However, in the decoding process of existing approaches, different samples are assigned different computational budgets, which cannot guarantee a stable and precise acceleration effect. Furthermore, existing approaches generally skip multiple contiguous layers at the bottom or top of the layers, leading to a drastic change in the model's layer-wise representations, and thus a consequent performance degeneration. Therefore, we propose a Unified Layer Skipping strategy, which selects the number of layers to skip computation based solely on the target speedup ratio, and then skips the corresponding number of intermediate layer computations in a balanced manner. Since the Unified Layer Skipping strategy is independent of input samples, it naturally supports popular acceleration techniques such as batch decoding and KV caching, thus demonstrating more practicality for real-world applications. Experimental results on two common tasks, i.e., machine translation and text summarization, indicate that given a target speedup ratio, the Unified Layer Skipping strategy significantly enhances both the inference performance and the actual model throughput over existing dynamic approaches.

Introduction

Large Language Models (LLMs) are computationally expensive due to their autoregressive nature, requiring a full pass through dozens of transformer layers for every token generated. While "dynamic computation" methods attempt to skip layers for "easy" tokens, they face significant practical hurdles. Specifically, they are often incompatible with batching (as different tokens exit at different layers), offer unstable throughput that complicates Service Level Agreements (SLAs), and suffer from "representation collapse" when contiguous blocks of layers are skipped.

Methodology

The proposed Unified Layer Skipping strategy decouples the skipping decision from input content. Instead of per-token heuristics, it uses a global target speedup ratio ($r$).

Comparison of layer skipping strategies: (a) Early Exit, (b) SkipDecode, and (c) the proposed Unified Layer Skipping.

The Core Algorithm

  1. Targeted Retainment: For a model with $N$ layers and a target speedup $r$, the system retains $M = N/r$ layers.
  2. Balanced Distribution: The strategy always preserves the first (bottom) and last (top) layers to maintain initial feature extraction and final prediction capabilities.
  3. Uniform Skipping: Intermediate layers are selected for retention based on a uniform modulo operation ($i \mod r == 0$).

By spreading active layers throughout the model's depth, the sub-network maintains a representational hierarchy similar to the original model. Because the pattern is fixed for a given $r$, it seamlessly supports KV caching and batch decoding.

Experimental Evaluation

The researchers evaluated the strategy using BLOOMZ-7B and LLaMA-13B backbones, fine-tuned on the Alpaca dataset. Performance was measured across:

  • Machine Translation: WMT-2022 test sets (multiple language pairs).
  • Text Summarization: CNN/DailyMail dataset.

Results and Discussion

Unified Layer Skipping consistently outperformed baselines like Early Exit and Skip Decoding. At a 4x speedup, it achieved an average improvement of 4.3 BLEU points in translation and 5.2 ROUGE-L points in summarization over Skip Decoding.

Cross entropy loss vs. speedup rate on the Alpaca dataset, comparing various skipping strategies.

Key Insights

  • Stability as a Feature: By making skipping input-independent, the method achieves 30% to 70% higher actual throughput on NVIDIA A100 GPUs compared to dynamic methods, as it fully utilizes hardware-efficient batching.
  • Representational Integrity: Skipping intermediate layers in a dispersed fashion prevents the drastic feature space shifts seen in Early Exit methods. Surprisingly, this simple uniform strategy performs nearly as well as computationally expensive "greedy search" optimizations for layer selection.

Conclusion

Unified Layer Skipping provides a practical, hardware-friendly path to accelerating LLM inference without the performance degradation typical of contiguous layer skipping. Future work will explore elastic ratios for variable workloads and validate the approach across a broader range of architectures and tasks.

Summary updated

BibTeX
@misc{liu2024accelerating,
  author = {Yijin Liu and Fandong Meng and Jie Zhou},
  title = {{Accelerating Inference in Large Language Models with a Unified Layer Skipping Strategy}},
  year = {2024},
  eprint = {2404.06954},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.06954},
}
Figure