arXiv:2511.12031cs.DCcs.AI2025-11

通过平衡内存与计算,显著提升大模型推理速度。

Striking the Right Balance between Compute and Copy: Improving LLM Inferencing Under Speculative Decoding

  • 每r步分配带冗余行的KV缓存,避免拷贝开销。
  • 在不同r值下实现最高3.2倍的吞吐加速。
  • 适合追求高效推理的云端与边缘部署场景。

随着云GPU及其虚拟实例成本飙升,使用CPU进行大语言模型(LLM)推理的需求日益增长。传统的KV缓存更新方式(逐个生成词元时进行分配、拷贝和就地步进更新)带来显著开销,序列长度增加时,分配与拷贝开销主导性能瓶颈。现有方法虽可预先分配大容量KV张量以支持就地更新,但零填充行导致冗余计算。本文提出一种新型KV缓存分配机制——平衡内存与计算(BMC),每r步分配一次带r个冗余行的KV张量,实现无拷贝的就地更新,仅付出少量冗余计算代价。同时发现,这些冗余行可被重用于推测解码(Speculative Decoding, SD),进一步提升生成效率。BMC构成一系列设计点,我们建立简单分析模型以确定最优配置。实验表明,相比基线HuggingFace(无SD),BMC平均提速达3.2倍;结合SD后,额外获得1.39倍加速;相较vLLM与DeepSpeed,分别提速1.36倍与2.29倍。BMC在桌面与服务器级CPU上表现优异,亦适用于GPU。

原文摘要 · Abstract (English)

With the skyrocketing costs of GPUs and their virtual instances in the cloud, there is a significant desire to use CPUs for large language model (LLM) inference. KV cache update, often implemented as allocation, copying, and in-place strided update for each generated token, incurs significant overhead. As the sequence length increases, the allocation and copy overheads dominate the performance. Alternate approaches may allocate large KV tensors upfront to enable in-place updates, but these matrices (with zero-padded rows) cause redundant computations. In this work, we propose a new KV cache allocation mechanism called Balancing Memory and Compute (BMC). BMC allocates, once every r iterations, KV tensors with r redundant rows, allowing in-place update without copy overhead for those iterations, but at the expense of a small amount of redundant computation. Second, we make an interesting observation that the extra rows allocated in the KV tensors and the resulting redundant computation can be repurposed for Speculative Decoding (SD) that improves token generation efficiency. Last, BMC represents a spectrum of design points with different values of r. To identify the best-performing design point(s), we derive a simple analytical model for BMC. The proposed BMC method achieves an average throughput acceleration of up to 3.2x over baseline HuggingFace (without SD). Importantly when we apply BMC with SD, it results in an additional speedup of up to 1.39x, over and above the speedup offered by SD. Further, BMC achieves a throughput acceleration of up to 1.36x and 2.29x over state-of-the-art inference servers vLLM and DeepSpeed, respectively. Although the BMC technique is evaluated extensively across different classes of CPUs (desktop and server class), we also evaluate the scheme with GPUs and demonstrate that it works well for GPUs.

大模型推理KV缓存推测解码性能优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。