跳到主内容
@wquguru
精选88Avi Chawla技巧与观点

新压缩技术将KV缓存内存降低6倍并提升解码吞吐3.4倍

A new technique cuts KV cache memory by 6x!

原文
发到 X
推荐理由

做推理部署的同学必看,给出了具体的KV Cache压缩方案和实测吞吐数据,直接优化显存瓶颈。

A new technique cuts KV cache memory by 6x!

一种新技术将 KV 缓存内存减少了 6 倍!

And it also improves decoding throughput by 3-4x.

同时,它还将解码吞吐量提高了 3-4 倍。

During LLM inference, quantizing the model weights only addresses part of the memory cost.

在 LLM 推理过程中,仅对模型权重进行量化只能解决部分内存成本问题。

The model also stores keys and values for the tokens it processes, so it can reuse them when generating subsequent tokens.

模型还会存储其处理的 token 的键(keys)和值(values),以便在生成后续 token 时复用它们。

Longer conversations inherently lead to more entries in the cache, and serving concurrent requests multiplies the memory requirement.

更长的对话必然导致缓存中的条目增多,而服务并发请求会使内存需求成倍增加。

During decoding, attention repeatedly reads these cached entries. So as context grows, both the space occupied by the cache and the bandwidth needed to read it become constraints.

在解码过程中,注意力机制会反复读取这些缓存条目。因此,随着上下文的增长,缓存占用的空间以及读取它所需的带宽都成为瓶颈。

This is why a model fitting in GPU memory doesn't tell you how many requests you can actually serve.

这就是为什么一个能放入 GPU 显存的模型并不能告诉你实际能处理多少请求的原因。

KV quantization helps by storing those entries with fewer bits.

KV 量化通过用更少的比特位存储这些条目来帮助缓解这一问题。

But the GPU also has to compress new entries and reconstruct older ones during attention. That additional work can consume the time saved by reading fewer bytes.

但 GPU 还必须在注意力计算期间压缩新条目并重建旧条目。这项额外工作可能会消耗掉因读取更少字节所节省的时间。

The main idea in this new technique is to compress older cache entries in groups, then reconstruct them as attention uses them.

这种新技术的主要思想是分组压缩旧的缓存条目,然后在注意力机制使用它们时进行重建。

More specifically, the researchers keep the earliest and most recent cache entries at higher precision and compress older entries in blocks.

更具体地说,研究人员以较高精度保留最早和最晚的缓存条目,并以块为单位压缩较旧的条目。

Grouping entries lets them remove a shared component before compression.

对条目进行分组允许它们在压缩前移除共享组件。

For a simplified example, imagine the same position in three cached vectors contains 100, 101, and 102.

为了简化示例,假设三个缓存向量中相同位置的值分别为 100、101 和 102。

They can store the average, 101, once, and represent the differences as -1, 0, and 1.

它们可以只存储一次平均值 101,并将差异表示为 -1、0 和 1。

Those smaller differences are easier to represent accurately with fewer bits. They then encode the values together to reduce compression error further.

这些较小的差异可以用更少的比特位更准确地表示。然后它们将这些值一起编码,以进一步减少压缩误差。

The second change is how attention uses this compressed data.

第二个改变是注意力机制如何使用这些数据。

Normally, decompressing the cache into GPU memory and then reading it for attention would add more memory traffic.

通常,将缓存解压到 GPU 内存中然后再供注意力机制读取会增加更多的内存流量。

Instead, their attention kernel reconstructs the values in GPU registers and uses them immediately.

相反,他们的注意力内核在 GPU 寄存器中重建值并立即使用它们。

This saves cache memory while avoiding the extra memory traffic that could cancel out the speed benefit.

这节省了缓存内存,同时避免了可能抵消速度优势的额外内存流量。

In vLLM tests with Qwen3-8B at 64K context on one H100, the 2-bit configuration achieved:

在 vLLM 中使用 Qwen3-8B 模型在单个 H100 上进行 64K 上下文的测试中,2-bit 配置实现了:

↳ 6x less total KV cache memory. ↳ 3.4x peak decoding throughput compared with BF16.

↳ 总 KV 缓存内存减少 6 倍。 ↳ 与 BF16 相比,峰值解码吞吐量提高 3.4 倍。

The throughput gain includes fitting larger batches into the freed memory. It doesn't mean a single request generates tokens 3x faster.

吞吐量的提升包括将更大的批次放入释放出的内存中。这并不意味着单个请求生成 token 的速度快了 3 倍。

Quality also depends on the precision setting. At 3 and 4 bits, results stayed close to BF16 across the evaluated Qwen3 models. At 2 bits, accuracy dropped more.

质量也取决于精度设置。在 3 位和 4 位时,在被评估的 Qwen3 模型上结果与 BF16 保持接近。在 2 位时,准确率下降更多。

Here's the paper covering this technique: https://arxiv.org/pdf/2612.02036

以下是涵盖该技术的论文:https://arxiv.org/pdf/2612.02036

Quantization is one of several ways to reduce KV cache costs.

量化是降低 KV 缓存成本的多种方法之一。

I covered 12 techniques in my KV Cache Engineering article, explaining what each one saves, how it works, and the trade-offs to consider for your workload.

我在《KV Cache 工程》一文中介绍了 12 种技术,解释了每种技术节省的内容、工作原理以及针对你的工作负载需要考虑的权衡。

Read it below.

请阅读下文。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件