IntactKV: Improving Large Language Model Quantization by Keeping Pivot Tokens Intact

Ruikang Liu, Haoli Bai, Haokun Lin, Yuening Li, Han Gao, Zhengzhuo Xu, Lu Hou, Jun Yao, Chun Yuan

Abstract

Large language models (LLMs) excel in natural language processing but demand intensive computation. To mitigate this, various quantization methods have been explored, yet they compromise LLM performance. This paper unveils a previously overlooked type of outliers in LLMs. Such outliers are found to allocate most of the attention scores on initial tokens of input, termed as pivot tokens, which are crucial to the performance of quantized LLMs. Given that, we propose IntactKV to generate the KV cache of pivot tokens losslessly from the full-precision model. The approach is simple and easy to combine with existing quantization solutions with no extra inference overhead. Besides, IntactKV can be calibrated as additional LLM parameters to boost the quantized LLMs further with minimal training costs. Mathematical analysis also proves that IntactKV effectively reduces the upper bound of quantization error. Empirical results show that IntactKV brings consistent improvement over various quantization methods across different LLMs and downstream tasks, leading to the new state-of-the-art for LLM quantization.

Introduction: The Discovery of Pivot Tokens

As Large Language Models (LLMs) scale, quantization—the process of converting high-precision weights and activations (FP16) to low-bit integers (e.g., INT4)—has become essential for deployment on consumer hardware. While previous research focused on protecting specific neural channels prone to outliers, this work identifies a critical, overlooked phenomenon: token-specific outliers.

The researchers discovered that initial tokens in a sequence, such as the [BOS] (Beginning of Sentence) token or early punctuation, generate activations hundreds of times larger than subsequent tokens. These "pivot tokens" act as attention sinks, where the model concentrates its attention scores to maintain stability. When these tokens are quantized, the resulting errors propagate and amplify, severely degrading model performance.

Visualizing activation outliers and attention sinks in LLaMA models.

Methodology: The IntactKV Approach

To address this, the authors propose IntactKV, a strategy designed to protect these fragile attention sinks with zero additional inference overhead.

  1. Lossless KV Cache Prefix: IntactKV uses a full-precision model offline to generate the Key-Value (KV) cache for a small number of pivot tokens (e.g., the [BOS] token). During inference, the quantized model loads this high-precision "prefix" and concatenates it with the rest of the quantized KV cache.
  2. Trainable Calibration: The saved pivot KV cache can be treated as additional trainable parameters. By minimizing the mean squared error (MSE) between the outputs of the full-precision and quantized models, the pivot tokens are "calibrated" to compensate for quantization errors introduced in later layers.

This method is highly practical because pivot tokens like [BOS] are input-agnostic and prepended to nearly every prompt, allowing the prefix to be generated once and reused.

Empirical Results

The effectiveness of IntactKV was evaluated across diverse benchmarks, including language generation (C4, WikiText2), multi-task understanding (MMLU), and commonsense reasoning.

Impact of IntactKV size on Transformer layer and attention loss for LLaMA-2-7B.

As shown in the figure above, keeping even a single pivot token intact leads to a dramatic drop in both Transformer layer loss and attention loss. Key performance highlights include:

  • Weight-Only Quantization: On LLaMA-3-8B (INT3), IntactKV improved WikiText2 perplexity from 8.15 to 7.97.
  • Human Alignment: For Vicuna-v1.3-13B, INT4 quantization with calibrated IntactKV nearly matched the full-precision model on MT-bench (5.50 vs 5.52).
  • Efficiency: The calibration process is extremely lightweight, requiring only ~10 minutes on a single GPU for a 7B model.

Conclusion and Future Work

IntactKV establishes a new state-of-the-art for LLM quantization by recognizing the foundational role of pivot tokens. While highly effective for standard sequence lengths, future research will explore its impact on extremely long contexts (32k+ tokens) and its applicability to non-Transformer architectures like Mixture-of-Experts (MoE). Additionally, automating the selection of pivot tokens for specialized domains remains a promising direction.

Summary updated

BibTeX
@inproceedings{liu2024intactkv,
  author = {Ruikang Liu and Haoli Bai and Haokun Lin and Yuening Li and Han Gao and Zhengzhuo Xu and Lu Hou and Jun Yao and Chun Yuan},
  title = {{IntactKV: Improving Large Language Model Quantization by Keeping Pivot Tokens Intact}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=m7GsDPupaL},
}
Figure