Per-Head Residual Vector Quantization
- Per-head residual vector quantization is a compression technique that decomposes transformer KV caches into independent attention-head or latent-group blocks, enabling additive residual encoding.
- It employs spectral denoising to extract low-rank shared structures before quantizing full-rank residuals with methods like TurboQuant for near-lossless reconstruction.
- Empirical results demonstrate reduced bits-per-entry and preserved model performance while simplifying training stability and codebook management.
Searching arXiv for the cited papers to ground the article in current literature. {"query":"(Su, 6 Apr 2026) eOptShrinkQ Near-Lossless KV Cache Compression Through Optimal Spectral Denoising and Quantization arXiv"} {"query":"(Kumar, 2024) Residual vector quantization for KV cache compression in LLM arXiv"} {"query":"(Zandieh et al., 28 Apr 2025) TurboQuant Online Vector Quantization with Near-optimal Distortion Rate arXiv"} {"query":"per-head residual vector quantization arXiv KV cache audio codecs"} Per-head residual vector quantization denotes a family of quantization schemes in which residual coding is organized around a head-structured decomposition. In transformer compression, the head is an attention head, and the quantizer operates on head-local key-value blocks or on groups derived from head slices. In neural codecs, the head is often a residual quantization stage or a grouped latent partition, and successive heads encode progressively finer residual information. The literature therefore uses the term across two closely related but not identical settings: stacked codebook-based residual vector quantization, and per-head residual compression pipelines that first isolate a structured component and then quantize the residual. A prominent recent formulation is eOptShrinkQ, which models each per-head KV block as a low-rank shared component plus a full-rank residual, removes the shared structure by optimal spectral shrinkage, and then quantizes the residual row-by-row with TurboQuant (Su, 6 Apr 2026).
1. Conceptual scope of “per-head”
In transformer KV-cache compression, per-head processing means that each attention head is handled independently. For a transformer layer with attention heads and head dimension , each head maintains key and value caches and . eOptShrinkQ processes each head independently, in blocks of consecutive tokens of size such as , forming per-head matrices and and compressing each block separately (Su, 6 Apr 2026).
In residual vector quantization for audio and related latent codecs, per-head has two common meanings. In the sequential interpretation, each residual codebook is itself a head, so stage is head . In the grouped interpretation, the latent vector is partitioned into groups, each group has its own RVQ stack, and each group’s codebook or codebooks form a head operating on a disjoint feature subspace (Zheng et al., 2024).
Transformer KV-cache RVQ introduces a third nuance. In "Residual vector quantization for KV cache compression in LLM," quantization is applied to the output of a key or value projection before RoPE; the projected vector is flattened, scaled by its standard deviation, partitioned into groups of size 0, and quantized groupwise with a residual quantizer shared across all groups for that matrix within a layer. Since 1 is smaller than a head dimension and non-contiguous grouping may mix channels from multiple heads, the method is only per-head in an indirect sense: it acts on a flattened per-layer vector whose groups may or may not align with head boundaries (Kumar, 2024).
This suggests that per-head residual vector quantization is best understood as a structural principle rather than a single implementation. The relevant invariant is that residual coding respects a head-like decomposition, but the head may be an attention head, a residual stage, a grouped latent partition, or an expert-selected branch.
2. Canonical residual quantization formalism
The standard residual vector quantization recursion is additive. Let 2 denote an input vector, let 3, and let stage 4 select an embedding 5 from codebook 6. The residual update is
7
The reconstructed vector is the sum of the selected codewords across stages. This coarse-to-fine recursion is the common backbone of classical RVQ, ERVQ, VRVQ, and PURE Codec (Zheng et al., 2024, Chae et al., 2024, Shi et al., 27 Nov 2025).
Generalized residual vector quantization formulates the same idea as an additive reconstruction problem over multiple codebooks. A vector 8 is approximated by
9
and the learning objective minimizes the total squared reconstruction error over the dataset. In the per-head setting, the feature space is partitioned into disjoint sub-vectors
0
with per-head reconstruction
1
Because heads act on disjoint dimensions, the global squared error decomposes additively, which permits independent optimization across heads and head-wise asymmetric distance computation without cross-head interaction (Liu et al., 2016).
This decomposition clarifies an important distinction. In classical codebook RVQ, the residual is represented by additional codewords. In eOptShrinkQ, by contrast, the residual is not recursively encoded by further codebooks. Instead, a low-rank shared component is first extracted, and the remaining full-dimensional residual is quantized directly. The method remains residual-centric, but the residual object is a denoised vector field rather than a sequence of codebook errors (Su, 6 Apr 2026).
3. Per-head RVQ for transformer KV caches
A direct codebook-based KV-cache instantiation is given in "Residual vector quantization for KV cache compression in LLM" (Kumar, 2024). The method quantizes the output of the key and value projection matrices before RoPE. Each projected vector 2 is scaled by its standard deviation 3, producing 4. The scaled vector is divided into 5 groups of dimension 6, and each group is quantized with an 7-stage residual quantizer:
8
The quantized group is 9, and the full vector is reconstructed by concatenating the groups and rescaling:
0
The reported default configuration uses 1 residual stages, codebook size 2, and group dimension 3. Each attention block learns two residual quantizers, one for keys and one for values. Within a layer, the same residual quantizer is shared across all channel groups and thus across all heads. Codebooks are not shared across layers. Codebooks are initialized by k-means on the first batch of inputs and updated by exponential moving average with decay 4; there are no encoder or decoder projection matrices and no commitment loss (Kumar, 2024).
Grouping strategy is asymmetric between keys and values. For keys, non-contiguous grouping works better than contiguous grouping. For values, contiguous grouping is preferred. The paper reports that a residual depth of 5 recovers most of the performance of the unquantized model, that 6 outperforms 7, and that the method is competitive with existing KV-cache quantization methods while remaining much simpler. The reported compression is roughly 8 compared to half precision (Kumar, 2024).
This formulation corrects a common misconception: per-head RVQ does not necessarily imply one learned codebook stack per attention head. In this KV-cache design, the quantizer is shared per matrix per layer, and head structure enters through grouping and through the downstream reshaping back to 9.
4. Spectral denoising and residual quantization in eOptShrinkQ
eOptShrinkQ defines per-head residual vector quantization through a low-rank-plus-residual model for each per-head KV block:
0
where 1 is a low-rank signal representing shared contextual structure across tokens in the block, and 2 is a full-rank residual capturing per-token idiosyncratic content. For keys, the decomposition arises from
3
and for values the same decomposition holds without RoPE:
4
The residual is modeled as colored noise with separable covariance, while 5 is low-rank and the detectable singular spikes are governed by a BBP phase transition (Su, 6 Apr 2026).
The spectral stage computes the SVD
6
and reconstructs only the detected outlier components with a nonlinear shrinker:
7
Automatic rank selection is obtained from the estimated bulk edge 8 and the BBP threshold
9
This differs from truncated SVD in two ways stated explicitly in the paper: eOptShrink corrects the inflation of each outlier singular value via optimal shrinkage, and it selects rank automatically from the spectrum (Su, 6 Apr 2026).
After shrinkage, the residual
0
is quantized row-by-row with TurboQuant. TurboQuant operates per vector by separating norm and direction, applying a random orthogonal rotation, quantizing each rotated coordinate with a Lloyd–Max codebook optimized for 1, and reconstructing by inverse rotation. The generic scalar mapping can be written as
2
although TurboQuant uses codebook bins rather than uniform steps (Zandieh et al., 28 Apr 2025). eOptShrinkQ uses TurboQuant-MSE rather than TurboQuant-prod because, after shrinkage, the residual becomes close to isotropic and delocalized:
3
The paper further gives a residual inner-product bias reduction bound
4
which is used to argue that outlier handling and dedicated inner-product bias correction are unnecessary after spectral denoising (Su, 6 Apr 2026).
The storage budget reflects this two-part decomposition. Residual entries use 5 bits per entry, with a small shared cost for one FP16 norm per row. Low-rank factors contribute an overhead
6
so the MSE-variant total is
7
Runtime decoding reconstructs 8 from stored singular vectors and singular values, dequantizes residual rows, and adds the two terms to form 9 (Su, 6 Apr 2026).
This architecture departs sharply from codebook-based RVQ. Traditional VQ or RVQ often relies on learned codebooks or sub-vector codebooks, coordinate subgrouping, and special treatment of outlier channels. eOptShrinkQ first removes low-rank shared structure, then applies scalar quantization to a residual whose geometry is deliberately restored to match the assumptions under which scalar quantization is near-optimal (Su, 6 Apr 2026).
5. Training-time refinements, adaptive heads, and anti-collapse strategies
A large part of the per-head RVQ literature concerns training stability and codebook utilization rather than inference-time KV-cache compression. ERVQ augments RVQ with intra-codebook and inter-codebook optimization. Intra-codebook optimization tracks exponentially decayed codeword usage,
0
refreshes underused entries by anchor blending, and regularizes the empirical assignment distribution toward the uniform prior with a balancing loss. Inter-codebook optimization minimizes SSIM between adjacent quantized outputs,
1
to reduce redundancy between successive heads. On APCodec with 2 VQs of size 3, ERVQ reports 4 utilization versus 5–6 without ERVQ, perplexity improvements from 7 to 8, and bitrate efficiency improvement from 9 to 0 (Zheng et al., 2024).
VRVQ makes the number of active residual heads variable across frames. It uses an importance network to produce a per-frame score 1, maps that score to a monotone top-2 binary mask, and applies only the first 3 heads on that frame. Training uses a straight-through estimator with a smooth surrogate
4
and a rate–distortion objective
5
In the DAC-based setup reported, 6, each codebook has size 7, frame rate is approximately 8 Hz, and signaling 9 costs 0 bits per frame, or approximately 1 kbps (Chae et al., 2024).
SwitchCodec replaces fixed residual stacks with a shared base quantizer and a pool of expert quantizers chosen by a router. The shared head is always active; routed experts are selected by TopK affinity scores and then applied in ascending expert index order to preserve a stable residual hierarchy. The paper reports a single model covering approximately 2 kbps to 3 kbps without retraining, and gives a routing-mask overhead example of less than 4 at 5 kbps when 6, 7, and the routing window is 8 seconds (Wang et al., 28 Jan 2026).
PURE Codec modifies the first residual head rather than the head count. The first stage is trained to approximate a denoised embedding 9, while later stages encode the residual relative to the original encoder output. The enhancement-guided loss is
0
The reported motivation is that the enhanced signal has lower perceptual entropy, empirically reduced by 1 on average compared to noisy inputs. PURE uses a DAC-style backbone with embedding dimension 2, 3 quantizers, and codebook size 4, and reports large gains over a DAC baseline on noisy corpora such as URGENT and CommonVoice (Shi et al., 27 Nov 2025).
Taken together, these papers show that per-head RVQ has evolved along three axes: codebook refresh and balancing, variable head activation, and semantically guided residual decomposition. The common problem is not merely compression efficiency but stable allocation of information across residual stages or head partitions.
6. Empirical behavior, practical guidance, and limitations
eOptShrinkQ provides the most explicit empirical characterization of per-head residual quantization in transformer KV caches. On Llama-3.1-8B-Instruct keys, eOptShrinkQ_MSE at 5 bpe achieves 6 L2 and near-zero IP bias/std, versus TurboQuant_MSE at 7 bpe with 8 L2; at approximately 9 bpe, eOptShrinkQ_MSE reaches 00 L2 versus TurboQuant_MSE at 01 bpe with 02 L2. On values, eOptShrinkQ_MSE at 03 bpe achieves 04 L2 versus TurboQuant_MSE at 05 bpe with 06 L2, and at 07 bpe achieves 08 versus 09. On LongBench, eOptShrinkQ_MSE at approximately 10 bpe achieves 11 average on Llama-3.1-8B and 12 on Ministral-8B, outperforming both TurboQuant_MSE and TurboQuant_prod at 13 bpe. On multi-needle retrieval, eOptShrinkQ_MSE at 14 bpe averages 15 recall on Llama-3.1-8B, exceeding FP16 at 16, and 17 on Ministral-8B, nearly matching FP16 at 18 (Su, 6 Apr 2026).
The eOptShrinkQ paper also provides explicit implementation guidance. A recommended starting point is 19 bits for the residual, with 20 and 21, giving a typical total of 22–23 bpe. Keys and values can use the same 24, because post-shrinkage isotropy is stated to suffice for both. Compression is integrated on-the-fly per chunk in prefill, new tokens are buffered until a block is formed, and the most recent at most 25 tokens remain FP16 (Su, 6 Apr 2026).
The codebook-based KV-cache RVQ paper identifies different practical trade-offs. Its guidance is to use non-contiguous grouping for keys, contiguous grouping for values, 26 stages, and 27. The paper notes that 28 codebooks per quantizer may introduce computational challenges, especially in compute-bound phases such as prefill and large-batch decoding, and recommends fused kernels to reduce the overhead (Kumar, 2024).
Several limitations recur across the literature. eOptShrinkQ assumes block-wise shared structure in KV caches and separable residual covariance; if the residual is highly structured or anisotropic, isotropy may not be fully restored and gains may reduce. Its BBP criterion can be conservative when 29 is very small or signals are extremely weak. The paper also states that tasks requiring global context integration, such as summarization, may benefit from some shared structure, so spectral denoising can slightly lower scores relative to FP16. Truly token-by-token streaming remains future work because the implementation compresses in blocks (Su, 6 Apr 2026).
Other limitations are modality-specific. TurboQuant’s theory becomes stronger as dimensionality increases, and the recommendations favor head dimension at least 30; very small head dimensions weaken the Beta-to-Gaussian approximation and may require slightly larger bit-widths or stronger mixing transforms (Zandieh et al., 28 Apr 2025). PURE explicitly depends on a speech enhancement model and is therefore speech-specific; the paper notes that severe domain mismatch between enhancement model and data can make the first-head anchor suboptimal (Shi et al., 27 Nov 2025).
A final source of confusion concerns the relationship between quality and regularization. In eOptShrinkQ, the claim that spectral denoising may improve retrieval-intensive tasks by acting as a regularizer is presented as a hypothesis rather than a theorem. The reported retrieval gains therefore support, but do not establish, a general principle (Su, 6 Apr 2026). More broadly, the literature indicates that per-head residual vector quantization should not be treated as a single fixed recipe. It is a design family whose members differ in whether heads are attention heads, residual stages, latent groups, or routed experts; whether residuals are represented by codewords or by denoise-then-quantize pipelines; and whether the primary objective is inference-time KV-cache compression, training-time codebook health, variable bitrate control, or structured decomposition of residual entropy.