.2.3 KV Cache QuantizationWith the increasing number of input tokens supported by LLMs, the memory usage of the KV cache also increases. Recent efforts begin to focus on kv cache quantization to reduce the memory footprint of LLMs and accelerate their inference. For example, KVQuant (Hooper et al., 2024) proposes several KV Cache Quantization methods, such as Per-Channel Key Quantization, PreRoPE Key Quantization, and Non-Uniform kv cache quantization, to implement 10 million context length LLM inference. Through an in-depth analysis of the element distribution within the KV cache, KIVI (Liu et al., 2024) finds that key caches should be quantized per-channel, while value caches should be quantized per-token. Finally, KIVI succeeds in quantizing the KV cache to 2 bits without fine-tuning. WKVQuant (Yue et al., 2024) presents an innovative approach for quantizing large language models (LLMs) by integrating past-only quantization to refine attention computations, employing a two-dimensional quantization strategy to manage the distribution of key/value (KV) caches effectively, and utilizing cross-block reconstruction regularization for optimizing parameters. This method enables the quantization of both weights and KV caches, resulting in memory savings that rival those of weightactivation quantization, while nearly matching the performance levels of weight-only quantization.
这段话讨论了KV 缓存量化(KV Cache Quantization),这是一种在大模型(LLMs)中减少内存占用和加速推理的技术。随着大模型支持的输入 token 数量增加,KV 缓存的内存使用也在增加,因此最近的研究集中在如何通过 KV 缓存量化来降低内存消耗。以下是翻译和讲解:
翻译:
3.2.3 KV 缓存量化
随着大模型支持的输入 token 数量不断增加,KV 缓存的内存使用也在增加。近期的研究开始关注 KV 缓存量化,以减少大模型的内存占用并加速推理过程。例如,KVQuant(Hooper 等人,2024)提出了几种 KV 缓存量化方法,如按通道键量化(Per-Channel Key Quantization)、预 RoPE 键量化(PreRoPE Key Quantization)和非均匀 KV 缓存量化(Non-Uniform KV Cache Quantization),用于实现 1000 万上下文长度的大模型推理。
通过对 KV 缓存内元素分布的深入分析,KIVI(Liu 等人,2024)发现键缓存应按通道进行量化,而值缓存应按 token 进行量化。最终,KIVI 在无需微调的情况下成功将 KV 缓存量化到 2 位。
WKVQuant(Yue 等人,2024)提出了一种创新的量化大模型的方法,通过整合仅过去量化(past-only quantization)来优化注意力计算,采用二维量化策略来有效管理键/值(KV)缓存的分布,并利用跨块重构正则化来优化参数。该方法实现了对权重和 KV 缓存的量化,带来了与权重-激活量化相媲美的内存节省效果,同时性能几乎达到权重量化的水平。
讲解:
这段话介绍了几种用于优化大模型的 KV 缓存量化技术,以及它们如何通过减少内存消耗来加速推理。KV 缓存是用于存储自注意力机制中键和值的缓存数据,随着输入序列长度的增加,KV 缓存的大小也会显著增加,从而导致内存使用量迅速增长。因此,量化 KV 缓存可以显著降低内存占用。
-
KV 缓存量化的背景:
- KV 缓存(Key-Value Cache)在自注意力机制中存储键和值,这些缓存会随着输入序列长度的增加而增长。
- 随着大模型的上下文长度增至几百万甚至上千万,KV 缓存的内存需求也急剧增加,因此需要通过量化技术来降低其内存占用。
-
不同的 KV 缓存量化方法:
- KVQuant:提出了多种量化方法,包括:
- 按通道键量化(Per-Channel Key Quantization):对键缓存进行按通道的量化处理。
- 预 RoPE 键量化(PreRoPE Key Quantization):在应用 RoPE(旋转位置编码)之前对键进行量化。
- 非均匀 KV 缓存量化(Non-Uniform KV Cache Quantization):采用非均匀量化策略来处理 KV 缓存。
- 这些方法可以实现高达 1000 万长度的上下文推理,同时减少内存使用。
- KVQuant:提出了多种量化方法,包括:
-
KIVI 方法:
- KIVI 通过对 KV 缓存的深入分析,发现键缓存应该按通道进行量化,而值缓存应该按 token 进行量化。这种方法能够在无需对模型进行微调的情况下,将 KV 缓存量化至 2 位,显著降低内存占用。
-
WKVQuant 方法:
- 采用了一种创新的量化策略,包括:
- 仅过去量化(past-only quantization):针对过去的输入进行量化,优化注意力计算的效率。
- 二维量化策略:对 KV 缓存采用二维量化方法,以更好地处理其分布特性。
- 跨块重构正则化:用于进一步优化参数,确保量化后的性能。
- 这种方法不仅对权重进行量化,还对 KV 缓存进行量化,带来了与权重-激活量化相当的内存节省效果,并且几乎达到了权重量化的性能水平。
- 采用了一种创新的量化策略,包括:
这些方法展示了在不显著影响模型性能的情况下,通过量化技术大幅减少 KV 缓存的内存占用,从而为更长的上下文长度提供支持,并加速推理过程。