KVQuant: Towards 10 Million Context Length LLM Inference with KV Cache Quantization

LLMs are seeing growing use for applications which require large context windows, and with these large context windows KV cache activations surface as the dominant contributor to memory consumption during inference. Quantization is a promising approach for compressing KV cache activations; however, existing solutions fail to represent activations accurately in sub-4-bit precision. Our work, KVQuant, facilitates low precision KV cache quantization by incorporating several novel methods: (i) Per-Channel Key Quantization, where we adjust the dimension along which we quantize the Key activations to better match the distribution; (ii) Pre-RoPE Key Quantization, where we quantize Key activations before the rotary positional embedding to mitigate its impact on quantization; (iii) Non-Uniform KV Cache Quantization, where we derive per-layer sensitivity-weighted non-uniform datatypes that better represent the distributions; and (iv) Per-Vector Dense-and-Sparse Quantization, where we isolate outliers separately for each vector to minimize skews in quantization ranges. By applying our method to the LLaMA, Llama-2, Llama-3, and Mistral models, we achieve < 0.1 perplexity degradation with 3-bit quantization on both Wikitext-2 and C4, outperforming existing approaches. Our method enables serving LLaMA-7B with a context length of up to 1 million on a single A100-80GB GPU and up to 10 million on an 8-GPU system. We develop custom CUDA kernels for KVQuant, showing that we can achieve up to ~1.7x speedups, compared to baseline fp16 matrix-vector multiplications, for the LLaMA-7B model.

Paper

References (51)

Scroll for more · 38 remaining

Similar papers

Peer review

Reviewer TbGM7/10 · confidence 4/52024-07-10

Summary

KVQuant presents a method for applying low-bit activation quantization to the Key-Value Cache, a major bottleneck in long context LLM's generation inference. The authors propose strategies (per-channel, per-token, pre-RoPE) tailored to the distribution characteristics of keys and values, as well as the distribution shift introduced by RoPE. They effectively mitigate the overhead introduced by their approach through kernel optimization. For the quantization process, they draw inspiration from SqueezeLLM, employing a non-uniform, dense-and-sparse method to handle outliers efficiently. They also use offline calibration to manage dynamically induced quantization scale and outliers from KV activations. The proposed KVQuant method demonstrates the least perplexity degradation in low-bit kv-cache quantization compared to FP16. Additionally, it outperforms the latest KV Quantization baseline (KIVI) based on group-wise quantization in terms of retrieval accuracy and LongBench performance.

Strengths

- Paper's writing is clear and easy to follow. It clearly explains why the kv-cache is the main bottleneck in long context scenario and highlights the need for quantization in memory-bound situations during LLM generation inference, making the importance of the paper easily understandable for the reader. - Beyond merely presenting performance, the paper minimizes the overhead of the proposed methods (Per-Channel Key Quantization, applying RoPE on-the-fly, offline calibration) through kernel optimization. - The strengths of this paper are clearly highlighted through comparisons with recent KV quantization baseline, KIVI. - The paper shows evaluation results not only with generation style (PPL) but also in long context prefill processing results (longbench, longeval).

Weaknesses

Since this paper is very solid, I don't see any major weakness in this paper. However, it is more focused on technical strategies for effectively applying quantization to the KV cache rather than presenting innovative or novel ideas. However, such efforts are crucial for making LLMs more accessible, so it is not considered a major weakness of the paper. As a minor weakness, due to the extensive experimental results and content, there are many appendices linked in the main text and frequent parenthetical explanations, which can make the paper somewhat challenging to follow. There is room to improve readability by filtering out and emphasizing key points in the main text.

Questions

- Do you have any insights into the cause of the disparate characteristics in the distributions of keys and values? - Can the distribution characteristics of Key and Value be generalized to widely used popularized LLMs? (e.g., Mistral, Gemma-2, Phi-3, …) - I am curious about the specific method used to measure PPL. I might have missed it, but when measuring generation PPL on wikitext and C4, did the authors use a teacher forcing style by providing all input tokens at once, applying quantization to the KV embeddings, and measuring loss with the final logits for all tokens? It would be helpful to have a detailed explanation of how PPL was measured.

Rating

7

Confidence

4

Soundness

4

Presentation

4

Contribution

3

Limitations

Limitation section in Appendix

Reviewer gDca6/10 · confidence 4/52024-07-11

Summary

This paper proposes KVQuant, which consists of 4 techniques for improving the performance of low-bit KV cache quantization. By observing the distribution of Key and Value cache, it proposes to use channel-wise quantization for Key cache before RoPE and token-wise quantization for Value cache. It also adopts non-uniform quantization instead of uniform quantization to improve performance. It also leverages per-vector dense-and-sparse quantization and attention sink-aware quantization to isolate outliers. Experiments on Wikitext-2 and C4 are conducted to evaluate the proposed method.

Strengths

1. The analysis of the KV cache distributions provide some insights to KV cache quantization. 2. Based on the observation, the proposed techniques are reasonable for KV cache quantization. 3. Latency of the implemented kernels is reported.

Weaknesses

1. The paper seems to be a combination of several existing quantization methods (or minor revision of existing methods), e.g. choosing to use per-channel quantization for Key cache, using non-uniform quantization, and dense-and-sparse quantization to improve performance. It is more like a technical report. 2. Based on the previous point, the paper writing is not clear enough. The paper proposes too many techniques and details are not fully presented in the main text of the paper. For instance, how is the non-uniform quantization used in this paper specifically implemented? 3. The evaluation section lacks detailed comparisons of the existing KV cache compression methods (like H2O, GEAR, KIVI). 4. The experiments are only conducted on Wikitext-2 and C4 datasets and reported the PPL. The effectiveness is not very well proven. Other challenging tasks such as reading comprehension, math problem solving, or code generation should be evaluated.

Questions

1. Quantization signposts appear multiple times in the article, what exactly is this? 2. The paper uses a calibration set to optimize the quantization parameters. Will this lead to overfitting of the model? Will calibrating a quantized model on one dataset affect its performance on other datasets?

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

2

Limitations

None

Reviewer j7z67/10 · confidence 2/52024-07-13

Summary

This paper proposes KVQuant, a quantization framework for enabling long context window inference through compressing KV cache activations. Specifically, the KVQuant framework incorporates several techniques including per-channel key quantification, per-RoPE key quantification, non-uniform KV cache quantification, and per-vector dense-and-sparse quantification. Experiments on several datasets and LLMs show that KVQuant can achieve low precision (3-bit) quantization with a relatively low impact on model performance.

Strengths

- Addressing memory constraints on context window length by compressing KV cache activations is a timely and important research area. - Handling outliers before RePE and non-uniform quantization by considering sensitivity are good insights. - Extensive experiments were conducted, covering prominent models such as Llama, Llama-2, Llama-3, and Mistral, on both Wikitext-2 and C4, which verified that KVQuant can achieve 3-bit quantization with < 0.1 perplexity degradation. - Custom CUDA kernels are developed to accelerate inference.

Weaknesses

In the per-vector dense-and-sparse quantization step, the numerical outliers are stored as high precision in a separate sparse matrix. It is not quite clear how to achieve this in practice in a hardware-friendly way without affecting inference speed. Additionally, the offline calibration step makes the implicit assumption on the access to data samples that are from a similar distribution as data from inference time.

Questions

Please refer to weaknesses.

Rating

7

Confidence

2

Soundness

4

Presentation

3

Contribution

3

Limitations

The authors discussed the limitations in Appendix T.

Reviewer MBTK5/10 · confidence 3/52024-07-14

Summary

The paper presents KVQuant, a low precision quantization method for KV cache activations in LLMs to reduce memory consumption during inference with large context windows. KVQuant applies per-channel pre-RoPE quantization on Key cache, exploits non-uniform datatype for quantization, and keeps the per-vector outliers in full precision. KVQuant achieves neligible perplexity degradation with 3-bit quantization on Wikitext-2 and C4, outperforming existing methods, and allows serving LLaMA-7B with up to 1 million context length on a single A100-80GB GPU.

Strengths

+ The paper addresses a crucial issue in the use of LLMs for long-context applications, where memory capacity is a significant limitation. + The paper is well-written and easy to follow. + The observation regarding the distribution of Key activations and its impact on quantization is particularly insightful, contributing valuable knowledge to KV cache quantization. + The paper includes practical, real-world measurements of speedup using specialized CUDA kernels, demonstrating the tangible benefits of their approach. + A thorough ablation study is presented, which helps in understanding the design choices made in KVQuant.

Weaknesses

- The paper does not sufficiently clarify the baseline methods and implementations used for comparison.

Questions

- What is the FP16 baseline implementation when evaluating speedup of the KVQuant kernel? - Compared to Post-RoPE quantization where post-RoPE Keys are stored, why does recalculating the RoPE in the KVQuant implementation can achieve faster speeds?

Rating

5

Confidence

3

Soundness

3

Presentation

3

Contribution

3

Limitations

The authors have adequately addressed the limitations.

Reviewer gDca2024-08-09

Thank you for your response.

Most of my concerns are addressed. So I'm willing to raise the score.

Reviewer TbGM2024-08-09

Thank you for the detailed response. Hope that the revised version of the paper will better emphasize the core content in the main part. Additionally, it would be beneficial if the experimental section could further highlight the effectiveness of KVQuant in long context scenarios where KV cache compression becomes particularly important (e.g., retrieval, longbench, RAG). That said, I find this paper to be solid and insightful, and I will maintain my recommendation to accept.

Reviewer j7z62024-08-10

Thanks for the rebuttal and the additional results. I have no further comments and will keep my score in support of this paper.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC