[论文解读] Attention Is All You Need But You Don't Need All Of It For Inference of Large Language Models
本文研究在推理过程中剪枝 Llama-v2 模型的深层注意力模块以降低延迟,发现跳过注意力子层可实现更优的加速效果,且性能损失极小——例如,在 13B 模型中移除 33% 的注意力层,可在 ARC、HellaSwag、TruthfulQA 和 MMLU 的平均基准性能仅下降 1.8% 的情况下,实现 18% 的推理加速。
The inference demand for LLMs has skyrocketed in recent months, and serving models with low latencies remains challenging due to the quadratic input length complexity of the attention layers. In this work, we investigate the effect of dropping MLP and attention layers at inference time on the performance of Llama-v2 models. We find that dropping dreeper attention layers only marginally decreases performance but leads to the best speedups alongside dropping entire layers. For example, removing 33\% of attention layers in a 13B Llama2 model results in a 1.8\% drop in average performance over the OpenLLM benchmark. We also observe that skipping layers except the latter layers reduces performances for more layers skipped, except for skipping the attention layers.
研究动机与目标
- 通过在推理过程中跳过层而不造成显著性能下降,来减少大语言模型(LLMs)的推理延迟。
- 探究 Llama-v2 模型中的深层是否冗余,是否可在推理时安全移除。
- 比较跳过注意力子层、MLP 子层或整个 Transformer 块对模型性能和推理速度的影响。
- 评估在 7B 和 13B Llama-v2 模型中剪枝深层时,计算效率与准确率之间的权衡。
提出的方法
- 作者通过在最后 k 层中跳过注意力子层、MLP 子层或整个 Transformer 块,构建修改后的 Llama-v2 模型。
- 在 OpenLLM 基准上评估这些变体,测量其在 ARC、HellaSwag、TruthfulQA 和 MMLU 上的准确率。
- 通过记录 1000 条长度为 50 和 100 的序列生成一个 token 所需的时间,来测量推理速度。
- 计算层特征与前一层之间的余弦相似度,以评估深层的冗余性。
- 通过比较保留最后一层与不保留最后一层的模型,评估其在性能稳定性中的作用。
- 实验在 7B 和 13B Llama-v2 模型上进行,保留的层比例分别为 66%、75%、90% 和 100%。

实验结果
研究问题
- RQ1在 Llama-v2 模型中跳过深层注意力子层是否会导致显著的性能下降?
- RQ2与跳过注意力子层相比,跳过 MLP 子层在性能和加速效果上有何差异?
- RQ3在跳过深层时,保留最后一层会产生什么影响?
- RQ4深层与浅层相比是否更具冗余性?这可通过特征相似度来判断。
- RQ5在大语言模型中,剪枝注意力层是否能实现显著加速,同时仅造成极小的准确率损失?
主要发现
- 在 13B Llama-v2 模型中跳过 33% 的注意力层,可在 OpenLLM 基准的平均性能仅下降 1.8% 的情况下,实现 18% 的推理加速。
- 移除 33% 的 MLP 子层可实现 14% 的加速,但平均性能下降 4.2%,表明 MLP 剪枝对性能更敏感。
- 最后一层始终与前一层具有最低的余弦相似度,表明其冗余性最低,应予以保留。
- 与跳过 MLP 层相比,跳过注意力层可带来更大的加速效果;在 7B 模型中,跳过注意力子层在保留 66% 层时可实现 21.47% 的时间减少。
- 跳过注意力层的模型在所有基准上均保持较强性能,仅在 MMLU 和 TruthfulQA 上出现微小下降。
- 加速效果在不同输入长度下保持一致,100 长度的序列与 50 长度的序列表现出相似的相对提升。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。