MagicDec:通过Speculative Decoding打破长上下文生成的延迟-吞吐量权衡
MagicDec: Breaking the Latency-Throughput Tradeoff for Long Context Generation with Speculative Decoding
AI总结:
MagicDec提出利用Speculative Decoding和稀疏KV缓存的draft模型,打破长上下文生成中延迟与吞吐量的权衡,在保持准确性的同时实现高达2.51倍加速。
摘要:
大型语言模型(LLMs)在交互式聊天机器人、文档分析和智能体工作流等长上下文应用中变得越来越普遍,但以低延迟和高吞吐量服务长上下文请求具有挑战性。Speculative Decoding(SD)是一种广泛使用的无损降低延迟的技术,但传统观点认为其有效性仅限于小批量大小。在MagicDec中,我们令人惊讶地发现,对于中长序列,SD即使在极高吞吐量的推理场景下也能实现加速。更有趣的是,基于我们严格的分析,智能的drafting策略能够在批量大小增加时实现更好的加速。MagicDec首先识别了随批量大小和序列长度增加而发生的瓶颈转移,并利用这些洞察更有效地将SD部署于高吞吐量推理中。我们利用带有稀疏KV缓存的draft模型来解决KV瓶颈问题,该瓶颈随序列长度和批量大小同时扩展。此外,我们提出了一个理论模型来选择最优的drafting策略以实现最大加速。我们的工作突出了Speculative Decoding在长上下文服务中的广泛适用性,因为它可以在不牺牲准确性的前提下同时提升吞吐量并降低延迟。对于中长序列,我们在多种硬件和任务上为Llama3.1-8B模型实现了高达2.51倍的加速,服务批量大小范围为32到256。
英文摘要:
Large Language Models (LLMs) have become more prevalent in long-context applications such as interactive chatbots, document analysis, and agent workflows, but it is challenging to serve long-context requests with low latency and high throughput. Speculative decoding (SD) is a widely used technique to reduce latency losslessly, but the conventional wisdom suggests that its efficacy is limited to small batch sizes. In MagicDec, we show that surprisingly SD can achieve speedup even for a high throughput inference regime for moderate to long sequences. More interestingly, an intelligent drafting strategy can achieve better speedup with increasing batch size based on our rigorous analysis. MagicDec first identifies the bottleneck shifts with increasing batch size and sequence length, and uses these insights to deploy SD more effectively for high throughput inference. We leverage draft model with sparse KV cache to address the KV bottleneck, which scales with both sequence length and batch size. Additionally, we propose a theoretical model to select the optimal drafting strategy for maximum speedup. Our work highlights the broad applicability of speculative decoding in long-context serving, as it can enhance throughput and reduce latency without compromising accuracy. For moderate to long sequences, we demonstrate up to 2.51x speedup for Llama3.1-8B when serving batch sizes ranging from 32 to 256 on various types of hardware and tasks.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。