在计算与复制之间取得平衡:在推测解码下改进大语言模型推理
Striking the Right Balance between Compute and Copy: Improving LLM Inferencing Under Speculative Decoding
AI总结:
针对CPU上LLM推理的KV缓存开销问题,提出BMC机制,通过周期性分配带冗余行的KV张量平衡计算与复制,结合推测解码实现最高3.2倍吞吐量加速,且在GPU上同样有效。
摘要:
随着GPU及其云虚拟实例成本的飙升,使用CPU进行大语言模型(LLM)推理的需求显著增加。KV缓存更新通常为每个生成的token执行分配、复制和原地跨步更新,带来显著开销。随着序列长度增加,分配和复制开销主导性能。替代方法可能预先分配大型KV张量以实现原地更新,但这些零填充行的矩阵会导致冗余计算。本工作提出一种名为平衡内存与计算(BMC)的KV缓存分配机制。BMC每r次迭代分配一次带r个冗余行的KV张量,允许这些迭代中无复制开销的原地更新,但代价是少量冗余计算。其次,我们发现KV张量中分配的额外行及由此产生的冗余计算可重新用于推测解码(SD),以提高token生成效率。最后,BMC代表不同r值的一系列设计点。为确定最佳性能设计点,我们推导BMC的简单分析模型。所提BMC方法相比基线HuggingFace(无SD)实现平均吞吐量加速高达3.2倍。重要的是,当BMC与SD结合时,相比SD单独提供的加速,额外获得高达1.39倍的加速。此外,BMC相比最先进的推理服务器vLLM和DeepSpeed,分别实现高达1.36倍和2.29倍的吞吐量加速。尽管BMC技术在不同类别的CPU(桌面和服务器级)上进行了广泛评估,但我们也评估了该方案对GPU的适用性,证明其对GPU同样有效。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。