Skip to Content

TurboQuant-MSE is the MSE-optimized variant. It randomly rotates the input vector so each coordinate follows a known distribution, then applies an optimal scalar quantizer independently to each coordinate. It achieves Dmse3π214bD_{\text{mse}} \leq \frac{\sqrt{3}\pi}{2} \cdot \frac{1}{4^b} — within a factor of 2.7\approx 2.7 of the information-theoretic limit.

Algorithm 1: TurboQuant-MSE

Setup (one-time, shared across all vectors)

Input: dimension dd, bit-width bb

  1. Generate random rotation matrix ΠRd×d\boldsymbol{\Pi} \in \mathbb{R}^{d \times d} — a uniformly random orthogonal matrix. In practice, generate a d×dd \times d matrix with i.i.d. N(0,1)\mathcal{N}(0,1) entries and compute its QR decomposition; Π\boldsymbol{\Pi} is the QQ factor.

  2. Construct codebook: find centroids c1,c2,,c2b[1,1]c_1, c_2, \ldots, c_{2^b} \in [-1,1] that minimize the MSE cost C(fX,b)\mathcal{C}(f_X, b) via the Lloyd-Max algorithm.

Quantization: QUANT(x\boldsymbol{x})

Input: vector xSd1\boldsymbol{x} \in \mathbb{S}^{d-1}

  1. Compute rotated vector: yΠx\boldsymbol{y} \leftarrow \boldsymbol{\Pi} \cdot \boldsymbol{x}

  2. For every coordinate j[d]j \in [d]: find the nearest centroid index

idxjargmink[2b]yjck\text{idx}_j \leftarrow \arg\min_{k \in [2^b]} |\boldsymbol{y}_j - c_k|
  1. Output: idx[2b]d\text{idx} \in [2^b]^d — a vector of dd indices, each a bb-bit integer. Storage: bdb \cdot d bits total.

Dequantization: DEQUANT(idx\text{idx})

  1. For every j[d]j \in [d]: look up the centroid y~jcidxj\tilde{\boldsymbol{y}}_j \leftarrow c_{\text{idx}_j}

  2. Rotate back to original basis: x~Πy~\tilde{\boldsymbol{x}} \leftarrow \boldsymbol{\Pi}^\top \cdot \tilde{\boldsymbol{y}}

  3. Output: x~Rd\tilde{\boldsymbol{x}} \in \mathbb{R}^d — the reconstructed vector

End-to-End Pipeline

Step through the full quantization pipeline: generate a random vector, rotate it, quantize each coordinate to the nearest Lloyd-Max centroid, then rotate back. Compare the reconstruction with the original.

Loading visualization...

Optimal Scalar Quantization (Lloyd-Max)

The core engine of TurboQuant: given the known coordinate distribution fXf_X, partition [1,1][-1,1] into 2b2^b intervals and assign a representative centroid cic_i to each. Each coordinate is replaced by the centroid of the interval it falls in.

The MSE cost to minimize:

C(fX,b):=minc1c2bi=12bci1+ci2ci+ci+12xci2fX(x)dx\mathcal{C}(f_X, b) := \min_{c_1 \leq \cdots \leq c_{2^b}} \sum_{i=1}^{2^b} \int_{\frac{c_{i-1}+c_i}{2}}^{\frac{c_i+c_{i+1}}{2}} |x - c_i|^2 \cdot f_X(x)\, dx

This is exactly a 1-dimensional k-means problem with a continuous distribution instead of discrete points. The intervals are defined by midpoints between consecutive centroids — the Voronoi tessellation in 1-D.

The Lloyd-Max algorithm finds the optimal centroids via alternating optimization:

  1. Initialize centroids uniformly in [1,1][-1,1]
  2. Repeat until convergence:
    • Boundary step: compute boundaries bi=(ci+ci+1)/2b_i = (c_i + c_{i+1})/2
    • Centroid step: update each centroid to the conditional expectation: cibi1bixfX(x)dxbi1bifX(x)dxc_i \leftarrow \frac{\int_{b_{i-1}}^{b_i} x \cdot f_X(x)\, dx}{\int_{b_{i-1}}^{b_i} f_X(x)\, dx}

Adjust the bit-width and dimension to see how the quantization bins adapt to the distribution shape.

Loading visualization...

Precomputed Optimal Values

bb2b2^b centroidsC(fX,b)\mathcal{C}(f_X, b)Dmse=dC(fX,b)D_{\text{mse}} = d \cdot \mathcal{C}(f_X, b)
120.36/d0.36/d0.360.36
240.117/d0.117/d0.1170.117
380.03/d0.03/d0.030.03
4160.009/d0.009/d0.0090.009

The codebook is universal: the same centroids work for any input vector, because the random rotation ensures all coordinates follow the same distribution.

Theorem 1 (Performance Guarantee)

For any bit-width b1b \geq 1 and any vector xSd1\boldsymbol{x} \in \mathbb{S}^{d-1}:

Dmse:=Ex~[xx~22]3π214bD_{\text{mse}} := \mathbb{E}_{\tilde{\boldsymbol{x}}}\left[\|\boldsymbol{x} - \tilde{\boldsymbol{x}}\|_2^2\right] \leq \frac{\sqrt{3}\pi}{2} \cdot \frac{1}{4^b}

Note: The 3π214b\frac{\sqrt{3}\pi}{2} \cdot \frac{1}{4^b} formula is an asymptotic upper bound from the Panter-Dite formula (tight for large bb). For small bb, the exact Lloyd-Max values above are tighter.

bbPanter-Dite boundExact Lloyd-MaxRatio
10.6800.6800.360.361.89×1.89\times
20.1700.1700.1170.1171.45×1.45\times
30.04250.04250.030.031.42×1.42\times
40.01060.01060.0090.0091.18×1.18\times

Full Proof of Theorem 1

Step 1: Rotation Preserves Distances

Since Π\boldsymbol{\Pi} is orthogonal:

xx~2=ΠxΠx~2=yy~2\|\boldsymbol{x} - \tilde{\boldsymbol{x}}\|_2 = \|\boldsymbol{\Pi} \cdot \boldsymbol{x} - \boldsymbol{\Pi} \cdot \tilde{\boldsymbol{x}}\|_2 = \|\boldsymbol{y} - \tilde{\boldsymbol{y}}\|_2

Step 2: Decompose into Per-Coordinate Errors

Dmse=E[yy~22]=j[d]E[yjy~j2]D_{\text{mse}} = \mathbb{E}\left[\|\boldsymbol{y} - \tilde{\boldsymbol{y}}\|_2^2\right] = \sum_{j \in [d]} \mathbb{E}\left[|\boldsymbol{y}_j - \tilde{\boldsymbol{y}}_j|^2\right]

Step 3: All Coordinates Are Identically Distributed

Since y=Πx\boldsymbol{y} = \boldsymbol{\Pi} \cdot \boldsymbol{x} is uniformly distributed on Sd1\mathbb{S}^{d-1}, every coordinate yj\boldsymbol{y}_j follows the same distribution fXf_X. All dd terms in the sum are identical:

Dmse=dE[y1cidx12]=dC(fX,b)D_{\text{mse}} = d \cdot \mathbb{E}\left[|\boldsymbol{y}_1 - c_{\text{idx}_1}|^2\right] = d \cdot \mathcal{C}(f_X, b)

Step 4: Bound via Panter-Dite (for large bb)

For the Gaussian approximation fXN(0,1/d)f_X \approx \mathcal{N}(0, 1/d):

C(fX,b)112(fX(x)1/3dx)314b\mathcal{C}(f_X, b) \leq \frac{1}{12} \cdot \left(\int f_X(x)^{1/3} dx\right)^3 \cdot \frac{1}{4^b}

Evaluating the integral for fX=N(0,1/d)f_X = \mathcal{N}(0, 1/d):

(fX1/3)3=63πd\left(\int f_X^{1/3}\right)^3 = \frac{6\sqrt{3}\pi}{d}

Therefore:

C(fX,b)11263πd14b=3π2d14b\mathcal{C}(f_X, b) \leq \frac{1}{12} \cdot \frac{6\sqrt{3}\pi}{d} \cdot \frac{1}{4^b} = \frac{\sqrt{3}\pi}{2d} \cdot \frac{1}{4^b}

And:

Dmse=dC(fX,b)3π214bD_{\text{mse}} = d \cdot \mathcal{C}(f_X, b) \leq \frac{\sqrt{3}\pi}{2} \cdot \frac{1}{4^b} \qquad \blacksquare

Why TurboQuant-MSE is Biased for Inner Products

At b=1b = 1, the optimal centroids are {±2/(πd)}\left\{\pm\sqrt{2/(\pi d)}\right\}. The quantization effectively computes sign(yj)\text{sign}(\boldsymbol{y}_j), giving:

E[y,Qmse1(Qmse(x))]=2πy,x\mathbb{E}\left[\langle \boldsymbol{y}, Q_{\text{mse}}^{-1}(Q_{\text{mse}}(\boldsymbol{x}))\rangle\right] = \frac{2}{\pi} \cdot \langle \boldsymbol{y}, \boldsymbol{x}\rangle

There’s a multiplicative bias of 2/π0.6372/\pi \approx 0.637. This bias diminishes with increasing bb but is significant at low bit-widths. This motivates TurboQuant-Prod (Algorithm 2).

Computational Complexity

  • QUANT: O(d2)O(d^2) for the rotation + O(d2b)O(d \cdot 2^b) for nearest-centroid search
  • DEQUANT: O(d)O(d) centroid lookup + O(d2)O(d^2) matrix-vector multiply
  • All operations are dense matrix multiplications — fully vectorizable on GPU
Last updated on