让大模型复制之前内容,提速超2倍还保质。
CopySpec: Accelerating LLMs with Speculative Copy-and-Paste Without Compromising Quality
- 发现重复内容时直接复制,不重新生成。
- 实测速度最高提升3.08倍,第三轮自纠错任务快2.66倍。
- 适合需要频繁修改回复的场景,如对话系统优化。
我们提出CopySpec,一种简单有效的技术,解决大语言模型在生成与历史输出高度相似或可直接从上下文提取的内容时的效率瓶颈。该方法检测聊天历史或上下文中的重复序列,并推测后续将出现相同标记,从而实现无损复制。实验使用七种LLM和五个数据集:MT-Bench、CNN/DM、GSM8K、HumanEval,以及本文新构建的MT-Redundant。MT-Redundant将MT-Bench第二轮对话改为请求对第一轮答案的变体,模拟真实用户修改需求。结果表明,复制策略带来显著加速:在CNN/DM上达2.35倍,在部分MT-Redundant类别第二轮达3.08倍,在GSM8K第三轮自纠正任务中达2.66倍。更重要的是,该方法可无缝集成至推测解码,使第二轮MT-Redundant任务平均再提速49%。尽管传统方法随上下文增长而变慢,但CopySpec反而利用更大上下文加速推理,成为高效互补方案。代码与数据集已开源。
原文摘要 · Abstract (English)
We introduce CopySpec, a simple yet effective technique to tackle the inefficiencies LLMs face when generating responses that closely resemble previous outputs or responses that can be verbatim extracted from context. CopySpec identifies repeated sequences in the model's chat history or context and speculates that the same tokens will follow, enabling seamless copying without compromising output quality and without requiring additional GPU memory. To evaluate the effectiveness of our approach, we conducted experiments using seven LLMs and five datasets: MT-Bench, CNN/DM, GSM8K, HumanEval, and our newly created dataset, MT-Redundant. MT-Redundant, introduced in this paper, transforms the second turn of MT-Bench into a request for variations of the first turn's answer, simulating real-world scenarios where users request modifications to prior responses. Our results demonstrate significant speed-ups: up to 2.35x on CNN/DM, 3.08x on the second turn of select MT-Redundant categories, and 2.66x on the third turn of GSM8K's self-correction tasks. Importantly, we show that CopySpec integrates seamlessly with speculative decoding, yielding an average 49% additional speed-up over speculative decoding for the second turn of MT-Redundant across all eight categories. While LLMs, even with speculative decoding, suffer from slower inference as context size grows, CopySpec leverages larger contexts to accelerate inference, making it a faster complementary solution. Our code and dataset are publicly available at https://github.com/RazvanDu/CopySpec.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。