dKV-Cache: The Cache for Diffusion Language Models
该论文提出了一种名为dKV-Cache的新机制,用于加速扩散语言模型(DLMs)的解码过程,通过延迟和条件缓存策略显著提高了解码速度,同时保持了性能。
更新于 2025-05-22。作者:Xinyin Ma、Runpeng Yu、Gongfan Fang、Xinchao Wang。
中文摘要
扩散语言模型(DLMs)被视为自回归语言模型的潜在竞争对手。然而,扩散语言模型长期以来一直受到慢速推理的限制。一个核心挑战是,它们的非自回归架构和双向注意力阻止了加速解码的关键值缓存。我们通过提出一种类似于KV缓存的机制,即延迟KV-Cache,来解决这一瓶颈,用于DLMs的降噪过程。我们的方法源于观察,不同的标记在整个扩散过程中具有不同的表示动态。因此,我们提出了一种延迟和条件化的缓存策略,用于键和值状态。我们设计了两种互补的变体来逐步缓存键和值:(1)dKV-Cache-Decode,它提供了几乎无损的加速,甚至在长序列上提高了性能,这表明现有的DLMs可能在推理过程中未充分利用上下文信息。(2)dKV-Cache-Greedy,它具有积极的缓存策略,但生命周期较短,以二次时间复杂度的代价实现了更高的加速,但牺牲了一些性能。最终,dKV-Cache在推理中实现了2-10倍的加速,大大缩小了自回归模型和DLMs之间的差距。我们在几个基准测试上评估了我们的dKV-Cache,在通用语言理解、数学和代码生成基准测试中实现了加速。实验表明,缓存也可以用于DLMs,甚至可以在不进行训练的情况下从当前的DLMs中实现。
英文摘要
Diffusion Language Models (DLMs) have been seen as a promising competitor for autoregressive language models. However, diffusion language models have long been constrained by slow inference. A core challenge is that their non-autoregressive architecture and bidirectional attention preclude the key-value cache that accelerates decoding. We address this bottleneck by proposing a KV-cache-like mechanism, delayed KV-Cache, for the denoising process of DLMs. Our approach is motivated by the observation that different tokens have distinct representation dynamics throughout the diffusion process. Accordingly, we propose a delayed and conditioned caching strategy for key and value states. We design two complementary variants to cache key and value step-by-step: (1) dKV-Cache-Decode, which provides almost lossless acceleration, and even improves performance on long sequences, suggesting that existing DLMs may under-utilise contextual information during inference. (2) dKV-Cache-Greedy, which has aggressive caching with reduced lifespan, achieving higher speed-ups with quadratic time complexity at the cost of some performance degradation. dKV-Cache, in final, achieves from 2-10x speedup in inference, largely narrowing the gap between ARs and DLMs. We evaluate our dKV-Cache on several benchmarks, delivering acceleration across general language understanding, mathematical, and code-generation benchmarks. Experiments demonstrate that cache can also be used in DLMs, even in a training-free manner from current DLMs.
解读
一句话总结
该论文提出了一种名为dKV-Cache的新机制,用于加速扩散语言模型(DLMs)的解码过程,通过延迟和条件缓存策略显著提高了解码速度,同时保持了性能。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:扩散语言模型(DLMs)虽然在理论上具有解码效率高的优势,但实际解码速度远低于自回归语言模型(ARs)。
- 现有方案不足:DLMs的非自回归架构和双向注意力机制使得无法直接使用KV-Cache机制,而KV-Cache是ARs中加速解码的关键技术。
- 研究目标:提出一种适用于DLMs的KV-Cache机制,以加速解码过程,同时保持或提高性能。
问题2:论文的核心创新点是什么?
- 技术创新:提出了延迟KV-Cache(dKV-Cache)机制,该机制通过延迟缓存策略和条件缓存策略,解决了DLMs中KV-Cache的使用难题。
- 方法改进:设计了两种dKV-Cache的变体:dKV-Cache-Decode和dKV-Cache-Greedy,分别用于长期缓存重用和更快的解码。
- 优势:与现有方法相比,dKV-Cache在解码速度上实现了2-10倍的提升,同时性能损失极小。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在LLaDA和Dream等多个基准测试上进行了实验,包括通用语言理解、数学推理和代码生成等。
- 性能提升:dKV-Cache在多个基准测试中实现了2-10倍的解码速度提升,同时性能损失极小。
- 对比结果:与基线方法相比,dKV-Cache在速度和性能上均取得了显著优势。
问题4:这个研究的实际应用价值是什么?
- 应用场景:可用于加速DLMs的解码过程,提高DLMs在各种应用场景中的效率,如文本生成、代码生成和数学问题求解等。
- 实施建议:可根据具体应用场景选择合适的dKV-Cache变体,并在实际部署时考虑内存管理和并行计算等因素。
- 局限与展望:目前该方法主要针对DLMs,未来可将其扩展到其他类型的语言模型,并进一步优化算法以降低内存占用。