Manuscript Offprint

arXiv:2611.03992

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 Tsui

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×10⁻³, 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.¹

1 Introduction

Every decoding step of a long-context model reads the whole KV cache, so the bytes per cached value bound both the number of sequences that fit in memory and the time of each step. At 32,768 tokens the BF16 cache of Qwen3-8B takes 4.8 GB per sequence. A cache with 2-bit codes and their scales needs 2.5 to 3 bits per value instead of 16. The price is accuracy: with 2-bit round-to-nearest (RTN) codes, the LongBench v1 mean of Qwen3-8B falls by 11.0 points in our served 2.5-bit per-token setting (Table 22). Range is one source of

this error: a few large entries widen the range of their quantization group and leave few code levels for the rest (Liu et al., 2024b; Hooper et al., 2024).

Rotations attack the range problem by spreading large entries over many coordinates (Ashkboos et al., 2024; Su et al., 2025b; Zandieh et al., 2026), but we find that they spread small entries as well. The error of a uniform quantizer grows with the crest factor of a group, and a Hadamard transform pulls every group toward the crest factor of a Gaussian vector: it flattens a spike but can give a flat piece a peak. On the cached keys of Llama-3.1-8B, we measure that it makes most of the flattest pieces harder to quantize (Figure 1). Which transform is better changes from one piece to the next, from token to token and from model to model, so a single rotation for all keys leaves error behind even when it helps on average.

We therefore treat the transform as a decision of the encoder rather than a fixed preprocessing step. Our method, FlagRot, tries both versions of each 32-channel piece, plain and rotated, and selects by a calibration estimate of attention error: a key error ee shifts the logit of a query qq by q⋅eq \cdot e, and queries concentrate on a few channels, so the decision weighs errors by calibration queries. One bit per piece records it in the sign bit of a positive quantization scale in the packed layout, so its page size does not grow; attention rotates the query into both bases instead of rotating keys back.

Selection applies to several quantizers, and we find that how often to decide depends on the quantization axis. The encoder can decide once per head from calibration data (fixed mode) or anew for every key (per-key mode). Our main system, FlagRot-KIVI, adds selection to KIVI, which quantizes keys along channels; KIVI-only is the same cache with selection off. There one decision already covers 32 tokens, and the fixed mode keeps 78% of the KL reduction with no work at write time. A second instance, FlagRot-auto, adds selec-

*All the work was done within HKUST and Xijie Huang served an advisory role.

¹Code: github.com/KunmingSHAO/FlagRot_releaser

Figure

(a) Real key sub-vectors

(b) Error increase vs. crest

(c) Choices within one key

(d) Whole-head rotation, NVFP4

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 H32H_{32}, with crest factor and change of the query-weighted INT4 error. (b) Share of sub-vectors whose error rises under H32H_{32}, 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.

tion to a cache that quantizes each key on its own after centering, that is, subtracting a calibrated key mean. On such per-token caches the per-key mode lowers the error by a further 35%, against 10% on KIVI. One principle covers both: the transform is a decision of the encoder, judged by the error attention sees and renewed only as often as the statistics the quantizer pools change.

This paper makes three contributions. First, we explain when a rotation helps a low-bit key, through the crest factor of each piece and the queries that read it (Section 2). Second, we introduce FlagRot, which selects the transform of each piece by the error attention sees, records the decision in existing sign bits, and runs in vLLM as a per-channel and a per-token cache (Section 3). Third, we show that selection lowers the error of the encoders we test: at 2.5 bits per value it lowers the twelve-model KL of KIVI from 18.718.7 to 12.4×10−312.4 \times 10^{-3}, below RotateKV (clip 1.0) on 9 of the models (Table 1). Served at that size, it adds +2.9 points to the RULER score at 128k tokens and +0.4 to +1.9 points to the Long-Bench v1 mean on the three of four models where KIVI loses accuracy (Table 2), and FlagRot-KIVI outscores the per-token cache of equal size on the three shared endpoints. At 4 bits our selection lowers the KL of INT4, MXFP4 and NVFP4 caches by 13–89% relative to RTN.

References (71)