Not All Layers of LLMs Are Necessary During Inference

Siqi Fan, Xin Jiang, Xiang Li, Xuying Meng, Peng Han +4 more
3/4/2024
cs.CLcs.AIcs.LG

No confident code implementation found for this paper. 8 possible matches can be shown below.

Abstract

Due to the large number of parameters, the inference phase of Large Language Models (LLMs) is resource-intensive. However, not all requests posed to LLMs are equally difficult to handle. Through analysis, we show that for some tasks, LLMs can achieve results comparable to the final output at some intermediate layers. That is, not all layers of LLMs are necessary during inference. If we can predict at which layer the inferred results match the final results (produced by evaluating all layers), we could significantly reduce the inference cost. To this end, we propose a simple yet effective algorithm named AdaInfer to adaptively terminate the inference process for an input instance. AdaInfer relies on easily obtainable statistical features and classic classifiers like SVM. Experiments on well-known LLMs like the Llama2 series and OPT, show that AdaInfer can achieve an average of 17.8% pruning ratio, and up to 43% on sentiment tasks, with nearly no performance drop (<1%). Because AdaInfer does not alter LLM parameters, the LLMs incorporated with AdaInfer maintain generalizability across tasks.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 8 weaker matches are hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{fan2024layers,
  title  = {Not All Layers of LLMs Are Necessary During Inference},
  author = {Siqi Fan and Xin Jiang and Xiang Li and Xuying Meng and Peng Han and Shuo Shang and Aixin Sun and Yequan Wang and Zhongyuan Wang},
  year   = {2024},
  eprint = {2403.02181},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2403.02181v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2403.02181.svg)](https://codeofpaper.com/paper/2403.02181)

Discussion