无需训练,通过跳过模型层实现大模型推理加速
SWIFT: On-the-Fly Self-Speculative Decoding for LLM Inference Acceleration
- 利用目标模型自身层跳过机制生成草稿
- 实测速度提升1.3倍至1.6倍,输出质量不变
- 即插即用,适配多种模型和任务
推测解码(SD)已成为一种广泛使用的加速大语言模型(LLM)推理的技术,能在不牺牲质量的前提下显著提升速度。其核心思路是先用小型模型高效生成多个词元,再由目标大模型并行验证。然而,现有方法大多需要额外参数或大量训练来构建有效的草稿模型,限制了其在不同模型和任务间的通用性。为此,我们提出一种全新的即插即用式推测解码方案——SWIFT,通过跳过目标模型的中间层作为紧凑草稿模型。分析表明,大模型具备通过层稀疏性实现自加速的潜力,且这种稀疏性具有任务特异性。基于此,SWIFT在推理过程中动态选择可跳过的中间层,无需辅助模型或额外训练,可直接部署于多种输入数据流。大规模实验覆盖多种模型与下游任务,结果表明SWIFT在保持生成文本原始分布的前提下,实现了超过1.3倍至1.6倍的加速。代码已开源:https://github.com/hemingkx/SWIFT。
原文摘要 · Abstract (English)
Speculative decoding (SD) has emerged as a widely used paradigm to accelerate LLM inference without compromising quality. It works by first employing a compact model to draft multiple tokens efficiently and then using the target LLM to verify them in parallel. While this technique has achieved notable speedups, most existing approaches necessitate either additional parameters or extensive training to construct effective draft models, thereby restricting their applicability across different LLMs and tasks. To address this limitation, we explore a novel plug-and-play SD solution with layer-skipping, which skips intermediate layers of the target LLM as the compact draft model. Our analysis reveals that LLMs exhibit great potential for self-acceleration through layer sparsity and the task-specific nature of this sparsity. Building on these insights, we introduce SWIFT, an on-the-fly self-speculative decoding algorithm that adaptively selects intermediate layers of LLMs to skip during inference. SWIFT does not require auxiliary models or additional training, making it a plug-and-play solution for accelerating LLM inference across diverse input data streams. Our extensive experiments across a wide range of models and downstream tasks demonstrate that SWIFT can achieve over a 1.3x-1.6x speedup while preserving the original distribution of the generated text. We release our code in https://github.com/hemingkx/SWIFT.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。