FlagRot: Selective Rotation for Low-Bit KV Caches

Kunming Shao, Xijie Huang, Jierun Chen, Jiaqi Shao, Yanli Wang, Jiangnan Yu, Qiwei Li, Wei Zhang, Kwang-Ting Cheng, Chi Ying TsuiarXiv 2026 · arXiv

TL;DR

FlagRot is a selective rotation strategy for low-bit KV cache quantization that decides whether to rotate sub-vectors of keys based on a calibrated error estimate. By hiding these 1-bit decisions in existing quantization metadata, it achieves state-of-the-art accuracy at just 2.5 bits per value, significantly outperforming "one-size-fits-all" rotation methods.

What Problem Does This Paper Address?

As Large Language Models (LLMs) handle increasingly long contexts, the Key-Value (KV) cache becomes a massive memory bottleneck. Quantizing this cache to 2 bits can shrink its footprint sixfold, but standard "round-to-nearest" quantization often destroys model accuracy due to "spiky" outliers in the data.

The common remedy is to apply a rotation (like a Hadamard transform) to the keys before quantization. The theory is that rotation spreads out large entries, flattening the distribution and making it easier to quantize. However, the authors of FlagRot discovered a critical flaw: rotation is a double-edged sword. While it flattens spiky data, it can actually introduce new peaks in data that was already flat. In a single key, some parts might benefit from rotation while others are harmed by it.

Methods

FlagRot (Selective Flagged Rotation) treats the transform as a dynamic decision rather than a fixed preprocessing step.

  1. Selective Transform: The encoder splits each key head into 32-channel pieces. For each piece, it calculates the error for two candidates: keeping it plain ($I$) or rotating it ($H_{32}$). It can also choose to rotate the entire head ($H_{128}$).
  2. Calibrated Error Criterion: Instead of simple reconstruction error, FlagRot uses a "query-weighted" error. It estimates how much the quantization error will actually shift the attention logits, weighted by how queries typically "look" at those channels (derived from a small calibration set).
  3. Zero-Overhead Metadata: The 1-bit decision (the "flag") for each piece is stored in the sign bit of the quantization scales. Since scales are always positive, this bit is usually wasted; FlagRot repurposes it to signal whether a block is rotated or not, keeping the memory layout identical to standard 2-bit caches.
  4. Dual-Basis Attention: To avoid the cost of rotating keys back during inference, FlagRot rotates the query into both bases once per decoding step. The attention kernel then selects the correct partial dot products based on the stored flags.
Figure 2: FlagRot. (a) At cache write, each 32-dim key sub-vector keeps I or H32, or the whole head takes H128, whichever has the lower query-weighted error; the per-token branch first subtracts the calibrated key mean, and the per-channel branch decides once per completed 32-token key group. (b) INT2 pages of 80 and 97 bytes per token and KV head (D=128), with the flags in the sign bits of the scales and 4 sink and 128 recent tokens in BF16. (c) Attention rotates the query into each basis once per step; the flags select the partial dot products, and keys are never rotated back.

Datasets

The authors evaluated FlagRot across a diverse set of models and benchmarks:

  • Models: 12 to 15 decoder-only models ranging from 3B to 32B parameters, including Llama-3.1, Qwen3, Mistral, and Phi-4.
  • Fidelity: Next-token KL divergence measured on the WikiText-2 test set.
  • Long-Context Tasks: LongBench v1 (21 tasks) and RULER (tested at 128k tokens).
  • Agentic/Reasoning Tasks: $\tau^2$-bench, SWE-bench Verified, and AIME 2024/2025.

Key Insights and Ideas

  • The Crest Factor Trap: Rotation pulls every data group toward the "crest factor" (peak-to-RMS ratio) of a Gaussian vector (~2.3). If a sub-vector is already very flat (crest factor near 1), rotation will almost certainly make it spikier and harder to quantize.
  • Quantization Axis Dictates Decision Frequency: The authors found that for per-channel caches (like KIVI), a single decision per head is often sufficient. For per-token caches, deciding for every individual key provides a much larger accuracy boost.
  • Compositionality: FlagRot isn't just a standalone method; it can be applied on top of other specialized transforms (like those in WUSH-KV), further reducing error by allowing the model to "opt-out" of the transform where it fails.
Figure 1: On real cached keys, rotation helps spiky sub-vectors and hurts many flat ones. (a) Two 32-dim key sub-vectors of Llama-3.1-8B before and after H32, with crest factor and change of the query-weighted INT4 error. (b) Share of sub-vectors whose error rises under H32, by decile of the crest factor. (c) The selections of FlagRot within one key and their shares. (d) Whole-head rotation of NVFP4 caches, per model.

Key Results

  • Lower Error: At 2.5 bits per value, FlagRot-KIVI lowers the geometric mean KL divergence across twelve models from 18.7 to 12.4 $\times 10^{-3}$, outperforming the previous state-of-the-art, RotateKV, on 9 of 12 models.
  • Benchmark Gains: When integrated into vLLM, FlagRot improves the RULER score at 128k tokens by +2.9 points and the LongBench v1 mean by up to +1.9 points compared to standard 2-bit KIVI.
  • Efficiency: The "fixed mode" (one decision per head) achieves 78% of the error reduction with zero extra work at write time.
  • 4-Bit Performance: The method also scales to 4-bit caches (INT4, FP4, MXFP4), reducing KL divergence by 13–89% relative to standard round-to-nearest quantization.
Figure 3: Simulated KL×103 with S4W128. (a) Geometric mean over the four development models against nominal bits per value; RTN-auto: RTN with the centering of FlagRot-auto. (b, c) Context length; 8k, 16k and 32k use 8, 6 and 4 windows. (d) WUSH-KV’s fitted transform at 32k, without and with selection and RoPE-shifted calibration.

Limitations and Future Work

  • Model Scale: While tested up to 32B parameters, the paper does not evaluate ultra-large models (70B+) or Mixture-of-Experts (MoE) architectures in the primary 2-bit study.
  • Prefill Overhead: The "per-key" mode, which offers the best accuracy, adds a roughly 5% overhead to prefill throughput due to the need to quantize and measure multiple candidates.
  • Hardware Specifics: The serving measurements were conducted on NVIDIA H20 and H200 GPUs; performance characteristics might vary on different hardware generations or non-NVIDIA accelerators.

Summary updated

Abstract

Long-context inference is bound by the KV cache, which 2-bit codes could shrink about sixfold if their error stays in check. The usual remedy rotates keys before quantizing, assuming rotation always helps. However, we observe that it does not: rotation flattens a spiky piece of a key but can give a flat one a new peak, and both coexist within one key. We therefore propose FlagRot, which stores each 32-channel piece rotated or as is, whichever has the smaller calibrated attention error, and rotates the query instead when reading. We further show that how often to decide follows the quantization axis: per-channel caches such as KIVI need one decision per head, at no write cost, while per-token caches decide per key, with the choice stored in existing sign bits. At 2.5 bits per value, FlagRot lowers the twelve-model KL divergence of KIVI from 18.7 to 12.4 x 10^-3, below RotateKV on 9 of 12 models. Served as a vLLM plugin, it raises RULER at 128k tokens by +2.9 points and the LongBench v1 mean by +0.4 to +1.9 points on the three of four models where 2-bit KIVI loses accuracy. It also lowers the error of 4-bit integer and FP4 caches.
BibTeX
@misc{shao2026flagrot,
  author = {Kunming Shao and Xijie Huang and Jierun Chen and Jiaqi Shao and Yanli Wang and Jiangnan Yu and Qiwei Li and Wei Zhang and Kwang-Ting Cheng and Chi Ying Tsui},
  title = {{FlagRot: Selective Rotation for Low-Bit KV Caches}},
  year = {2026},
  eprint = {2611.03992},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.03992},
}
Figure