---
title: Per-Head Residual Vector Quantization
url: https://www.emergentmind.com/topics/per-head-residual-vector-quantization
type: topic
---

# Per-Head Residual Vector Quantization

Searching arXiv for the cited papers to ground the article in current literature.
{"query":"2605.02905 eOptShrinkQ Near-Lossless KV Cache Compression Through Optimal Spectral Denoising and Quantization arXiv"}
{"query":"2410.15704 Residual vector quantization for KV cache compression in large language model arXiv"}
{"query":"2504.19874 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 [2605.02905].

## 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 $h$ attention heads and head dimension $d$, each head maintains key and value caches $K \in \mathbb{R}^{T \times d}$ and $V \in \mathbb{R}^{T \times d}$. eOptShrinkQ processes each head independently, in blocks of consecutive tokens of size $n \approx d$ such as $n=d=128$, forming per-head matrices $X_K \in \mathbb{R}^{n \times d}$ and $X_V \in \mathbb{R}^{n \times d}$ and compressing each block separately [2605.02905].

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 $k$ is head $k$. 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 [2410.12359].

Transformer KV-cache RVQ introduces a third nuance. In "Residual vector quantization for KV cache compression in large language model," 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 $\hat{d}=32$, and quantized groupwise with a residual quantizer shared across all groups for that matrix within a layer. Since $\hat{d}$ 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 [2410.15704].

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 $x$ denote an input vector, let $r^{(0)}=x$, and let stage $k$ select an embedding $e^{(k)}_{i_k}$ from codebook $k$. The residual update is

$$
r^{(0)} = x,\quad
q_k\bigl(r^{(k-1)}\bigr) = e^{(k)}_{i_k},\quad
r^{(k)} = r^{(k-1)} - e^{(k)}_{i_k},\quad
k=1,\dots,M.
$$

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 [2410.12359][2410.06016][2511.22687].

Generalized residual vector quantization formulates the same idea as an additive reconstruction problem over multiple codebooks. A vector $x$ is approximated by
$$
\hat{x} = \sum_{m=1}^{M} c^{(m)}_{a_m(x)},
$$
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
$$
x = [x_{(1)}, \dots, x_{(H)}],
$$
with per-head reconstruction
$$
x_{(h)} \approx \sum_{m=1}^{M} c^{(m,h)}_{a_{m,h}(x_{(h)})}.
$$
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 [1609.05345].

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 [2605.02905].

## 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 large language model" [2410.15704]. The method quantizes the output of the key and value projection matrices before RoPE. Each projected vector $x \in \mathbb{R}^{d}$ is scaled by its standard deviation $\sigma(x)=\mathrm{std}(x)$, producing $\hat{x}=x/\sigma(x)$. The scaled vector is divided into $G=d/\hat{d}$ groups of dimension $\hat{d}$, and each group is quantized with an $L$-stage residual quantizer:
$$
e_i = \arg\min_k \|r^{(i-1)} - c_{i,k}\|_2^2,\quad
q_i = c_{i,e_i},\quad
r^{(i)} = r^{(i-1)} - q_i.
$$
The quantized group is $q(z)=\sum_{i=1}^{L} q_i$, and the full vector is reconstructed by concatenating the groups and rescaling:
$$
\tilde{x} = \sigma(x)\cdot q(\hat{x}).
$$

The reported default configuration uses $L=8$ residual stages, codebook size $C=2048$, and group dimension $\hat{d}=32$. 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 $0.99$; there are no encoder or decoder projection matrices and no commitment loss [2410.15704].

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 $8$ recovers most of the performance of the unquantized model, that $C=2048$ outperforms $C=1024$, and that the method is competitive with existing KV-cache quantization methods while remaining much simpler. The reported compression is roughly $5.5\times$ compared to half precision [2410.15704].

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 $n_{\text{heads}} \times d_h$.

## 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:
$$
X = S + Z,
$$
where $S$ is a low-rank signal representing shared contextual structure across tokens in the block, and $Z$ is a full-rank residual capturing per-token idiosyncratic content. For keys, the decomposition arises from
$$
X[t,:] = R(t)\,\bar{h}_t W_K + R(t)\,\epsilon_t W_K = S[t,:] + Z[t,:],
$$
and for values the same decomposition holds without RoPE:
$$
X[t,:] = \bar{h}_t W_V + \epsilon_t W_V = S[t,:] + Z[t,:].
$$
The residual is modeled as colored noise with separable covariance, while $S$ is low-rank and the detectable singular spikes are governed by a BBP phase transition [2605.02905].

The spectral stage computes the SVD
$$
X = U\Sigma V^\top = \sum_{i=1}^{n\wedge d} \widetilde{\sigma}_i\,\tilde{u}_i\,\tilde{v}_i^\top
$$
and reconstructs only the detected outlier components with a nonlinear shrinker:
$$
\hat{S} = \sum_{i=1}^{\hat{r}^+} \varphi(\widetilde{\sigma}_i)\,\tilde{u}_i\,\tilde{v}_i^\top.
$$
Automatic rank selection is obtained from the estimated bulk edge $\hat{\lambda}_+$ and the BBP threshold
$$
\alpha = \frac{1}{\sqrt{\mathcal{T}(\lambda_+)}}.
$$
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 [2605.02905].

After shrinkage, the residual
$$
R = X - \hat{S}
$$
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 $N(0,1/d)$, and reconstructing by inverse rotation. The generic scalar mapping can be written as
$$
q(x_j) = s\cdot \mathrm{round}\!\left(\frac{x_j}{s}\right),
$$
although TurboQuant uses codebook bins rather than uniform steps [2504.19874]. eOptShrinkQ uses TurboQuant-MSE rather than TurboQuant-prod because, after shrinkage, the residual becomes close to isotropic and delocalized:
$$
\frac{\|r_t\|_\infty}{\|r_t\|_2} \le C\sqrt{\frac{\log d}{d}}
\quad \text{with high probability}.
$$
The paper further gives a residual inner-product bias reduction bound
$$
\frac{\bigl|\,\mathbb{E}\langle q,\tilde{r}_t\rangle - \langle q,r_t\rangle\,\bigr|}
{\bigl|\,\mathbb{E}\langle q,\tilde{x}_t\rangle - \langle q,x_t\rangle\,\bigr|}
\le \frac{1}{1+\mathrm{SNR}_t} + o(1),
$$
which is used to argue that outlier handling and dedicated inner-product bias correction are unnecessary after spectral denoising [2605.02905].

The storage budget reflects this two-part decomposition. Residual entries use $b$ bits per entry, with a small shared cost for one FP16 norm per row. Low-rank factors contribute an overhead
$$
\frac{\hat{r}^+(n+d)\,b_s}{nd}
\quad \text{bits per entry},
$$
so the MSE-variant total is
$$
\text{bpe} = b + \frac{\hat{r}^+(n+d)\,b_s}{nd}.
$$
Runtime decoding reconstructs $\hat{S}$ from stored singular vectors and singular values, dequantizes residual rows, and adds the two terms to form $\hat{X}$ [2605.02905].

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 [2605.02905].

## 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,
$$
U_k^{(t)} = \gamma U_k^{(t-1)} + \frac{u_k^{(t)}}{L}(1-\gamma),
$$
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,
$$
\mathcal{L}_{SSIM} = \sum_{m=1}^{M-1} SSIM\bigl(\hat{z}^{m}, \hat{z}^{m+1}\bigr),
$$
to reduce redundancy between successive heads. On APCodec with $4$ VQs of size $1024$, ERVQ reports $100\%$ utilization versus $14.7$–$41.2\%$ without ERVQ, perplexity improvements from $[102,157,256,401]$ to $[653,920,973,962]$, and bitrate efficiency improvement from $0.766$ to $0.976$ [2410.12359].

VRVQ makes the number of active residual heads variable across frames. It uses an importance network to produce a per-frame score $p[t]$, maps that score to a monotone top-$K$ binary mask, and applies only the first $K[t]$ heads on that frame. Training uses a straight-through estimator with a smooth surrogate
$$
f_\alpha^k(s) =
\frac{1}{2\alpha}\log\!\left(
\frac{\cosh(\alpha(s-k))}
{\cosh(\alpha(-s+k+1))}
\right) + \frac{1}{2},
$$
and a rate–distortion objective
$$
\mathcal{L} = D(x,\hat{x}) + \beta \mathcal{L}_R,\qquad
\mathcal{L}_R = \frac{1}{T}\sum_{t=1}^{T} p[t].
$$
In the DAC-based setup reported, $H=8$, each codebook has size $1024$, frame rate is approximately $86$ Hz, and signaling $K[t]$ costs $\lceil\log_2 8\rceil = 3$ bits per frame, or approximately $0.258$ kbps [2410.06016].

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 $0.89$ kbps to $8$ kbps without retraining, and gives a routing-mask overhead example of less than $0.1\%$ at $2.67$ kbps when $N_r=7$, $k_r=2$, and the routing window is $2$ seconds [2601.20362].

PURE Codec modifies the first residual head rather than the head count. The first stage is trained to approximate a denoised embedding $\tilde{Q}=\mathrm{Enc}(\mathrm{Enh}(S))$, while later stages encode the residual relative to the original encoder output. The enhancement-guided loss is
$$
L_{\text{enh}} = \mathbb{E}_{\text{Bernoulli}(p_{\text{enh}})}
\left[\|\hat{Q}^{(1)}-\tilde{Q}\|_2^2\right].
$$
The reported motivation is that the enhanced signal has lower perceptual entropy, empirically reduced by $57.80\%$ on average compared to noisy inputs. PURE uses a DAC-style backbone with embedding dimension $D=512$, $L=8$ quantizers, and codebook size $B=1024$, and reports large gains over a DAC baseline on noisy corpora such as URGENT and CommonVoice [2511.22687].

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 $3.35$ bpe achieves $9.6\%$ L2 and near-zero IP bias/std, versus TurboQuant\_MSE at $4.00$ bpe with $9.7\%$ L2; at approximately $2.35$ bpe, eOptShrinkQ\_MSE reaches $17.7\%$ L2 versus TurboQuant\_MSE at $2.00$ bpe with $34.1\%$ L2. On values, eOptShrinkQ\_MSE at $4.31$ bpe achieves $7.5\%$ L2 versus TurboQuant\_MSE at $4.00$ bpe with $9.7\%$ L2, and at $3.31$ bpe achieves $14.4\%$ versus $18.4\%$. On LongBench, eOptShrinkQ\_MSE at approximately $2.22$ bpe achieves $47.4$ average on Llama-3.1-8B and $48.3$ on Ministral-8B, outperforming both TurboQuant\_MSE and TurboQuant\_prod at $3.00$ bpe. On multi-needle retrieval, eOptShrinkQ\_MSE at $2.22$ bpe averages $0.981$ recall on Llama-3.1-8B, exceeding FP16 at $0.972$, and $0.992$ on Ministral-8B, nearly matching FP16 at $1.000$ [2605.02905].

The eOptShrinkQ paper also provides explicit implementation guidance. A recommended starting point is $b=2$ bits for the residual, with $\hat{r}^+ \in [1,10]$ and $b_s=4$, giving a typical total of $2.2$–$2.4$ bpe. Keys and values can use the same $b$, 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 $127$ tokens remain FP16 [2605.02905].

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, $L=8$ stages, and $C=2048$. The paper notes that $L=8$ 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 [2410.15704].

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 $d$ 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 [2605.02905].

Other limitations are modality-specific. TurboQuant’s theory becomes stronger as dimensionality increases, and the recommendations favor head dimension at least $64$; very small head dimensions weaken the Beta-to-Gaussian approximation and may require slightly larger bit-widths or stronger mixing transforms [2504.19874]. 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 [2511.22687].

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 [2605.02905]. 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.

Source: https://www.emergentmind.com/topics/per-head-residual-vector-quantization