Saved in:
Bibliographic Details
Main Authors: Fan, Siqi, Jiang, Xin, Li, Xiang, Meng, Xuying, Han, Peng, Shang, Shuo, Sun, Aixin, Wang, Yequan, Wang, Zhongyuan
Format: Preprint
Published: 2024
Subjects:
Online Access:https://arxiv.org/abs/2403.02181
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909247785140224
author Fan, Siqi
Jiang, Xin
Li, Xiang
Meng, Xuying
Han, Peng
Shang, Shuo
Sun, Aixin
Wang, Yequan
Wang, Zhongyuan
author_facet Fan, Siqi
Jiang, Xin
Li, Xiang
Meng, Xuying
Han, Peng
Shang, Shuo
Sun, Aixin
Wang, Yequan
Wang, Zhongyuan
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2403_02181
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Not All Layers of LLMs Are Necessary During Inference
Fan, Siqi
Jiang, Xin
Li, Xiang
Meng, Xuying
Han, Peng
Shang, Shuo
Sun, Aixin
Wang, Yequan
Wang, Zhongyuan
Computation and Language
Artificial Intelligence
Machine Learning
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.
title Not All Layers of LLMs Are Necessary During Inference
topic Computation and Language
Artificial Intelligence
Machine Learning
url https://arxiv.org/abs/2403.02181