Not All Layers of LLMs Are Necessary During Inference

Siqi Fan, Xin Jiang, Xiang Li, Xuying Meng, Peng Han, Shuo Shang, Aixin Sun, Yequan Wang

Abstract

Large Language Models (LLMs) typically process every input through their entire stack of Transformer layers, regardless of the prompt's complexity. This "one-size-fits-all" approach leads to significant computational waste during inference. We introduce AdaInfer, a lightweight, "plug-and-play" algorithm designed for instance-aware adaptive inference. By utilizing simple statistical classifiers to monitor logit confidence at intermediate layers, AdaInfer can terminate inference early when a stable prediction is reached. Our experiments demonstrate that AdaInfer achieves an average pruning ratio of 17.8%—reaching up to 43% on simpler tasks—while maintaining accuracy within 1% of the full model, all without modifying the underlying model parameters.

Introduction

The inference phase of Large Language Models (LLMs) is notoriously resource-intensive. Current standard architectures, such as Llama2-70B, process every input through all 80 layers, whether the task is a simple sentiment classification or a complex mathematical proof. This uniformity is computationally inefficient. While techniques like model pruning or weight quantization can reduce costs, they often require parameter modification, which can compromise the model's generalizability or in-context learning capabilities.

AdaInfer addresses this by implementing adaptive inference, allowing the model to "early exit" once it has reached a confident conclusion. This approach is orthogonal to other acceleration techniques and preserves the model's original weights.

Methodology

AdaInfer operates as an instance-aware algorithm with two primary components: feature selection and classifier-based decision making.

Feature Selection

The authors analyzed various internal signals, including hidden states, attention values, and MLP outputs. They discovered that logits provide the most consistent "stop" signals. Two primary features are extracted at each layer:

  • Top Prob: The probability of the most likely next token.
  • Gap: The difference in probability between the top-ranked and second-ranked tokens.

Classifier-Based Decision

At each decoding layer, AdaInfer passes these features to a classical classifier, such as a Support Vector Machine (SVM). The classifier predicts whether the current layer's prediction is identical to the final layer's output. If the prediction is "yes," inference terminates early.

Figure 2: Conceptual overview of AdaInfer applying different stopping points for Sentiment vs. MMLU tasks.

Experimental Setup

AdaInfer was evaluated across a diverse range of benchmarks, including MMLU (general knowledge), CommonsenseQA, SQuAD (reading comprehension), SST-2 (sentiment analysis), and AG News (topic classification). The models tested included the Llama2 series (7B, 13B, 70B), OPT-13B, and GPT-J-6B.

Results and Discussion

The "Logit Lens" analysis revealed that "Gap" and "Top Prob" features gradually increase and stabilize as inference progresses, serving as universal signals across different tasks.

Efficiency and Accuracy

AdaInfer achieved an average pruning ratio of 17.8%. On simpler tasks like sentiment analysis, it skipped up to 43% of layers. Despite this reduction in computation, the performance drop remained negligible, consistently staying below 1%. In real-world testing on V100 GPUs, this translated to a 1.30x speedup for Llama2-13B on sentiment tasks.

Figure 3: Comparison of average layers used and FLOPs reduction for different tasks on Llama2-13B.

Task-Dependent Depth

A key insight is that "easy" tasks often activate correctly at very shallow layers, while "hard" tasks like MMLU require deeper processing. Interestingly, in some instances, AdaInfer exceeded the accuracy of the full model, suggesting that final layers can sometimes introduce noise or "over-think" simple problems.

Conclusion and Future Work

AdaInfer provides a robust, parameter-free method for accelerating LLM inference. While highly effective for 7B and 13B models, scaling to 70B models in few-shot settings remains a challenge, potentially requiring more sophisticated feature engineering. Future research will also focus on extending adaptive inference to long-form text generation, where task difficulty may fluctuate per token.

Summary updated

BibTeX
@inproceedings{fan2025not,
  author = {Siqi Fan and Xin Jiang and Xiang Li and Xuying Meng and Peng Han and Shuo Shang and Aixin Sun and Yequan Wang},
  title = {{Not All Layers of LLMs Are Necessary During Inference}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.24963/ijcai.2025/566},
}
Figure