m1b commited on
Commit
dc42abd
·
verified ·
1 Parent(s): ce5a0b2

Upload GEOMETRIC_PIPELINE.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. GEOMETRIC_PIPELINE.md +200 -0
GEOMETRIC_PIPELINE.md ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Geometric Information-Theoretic Compression Pipeline for Parameter Golf
2
+
3
+ ## The Core Idea: Three Theorems That Chain Together
4
+
5
+ The current SOTA (1.0810 BPB) uses GPTQ with per-row scalar INT6 quantization + Brotli entropy coding. This pipeline is ad-hoc: it doesn't exploit the geometric structure of the weight space. Three theorems from information geometry and random matrix theory tell us exactly how to do better.
6
+
7
+ ---
8
+
9
+ ## Theorem 1: The Marchenko-Pastur Spectral Separation (RMT-KD, arxiv 2602.22345)
10
+
11
+ **Statement**: For a trained weight matrix W ∈ ℝ^{m×n}, the eigenvalue spectrum of WW^T decomposes into:
12
+ - A **noise bulk** predicted by the Marchenko-Pastur law (random matrix theory)
13
+ - **Signal eigenvalues** that exceed the bulk edge λ₊ = σ²(1 + √(m/n))²
14
+
15
+ **Proof sketch**: Under the assumption that the "noise" component of W behaves like an iid random matrix with variance σ², the Marchenko-Pastur law gives the limiting spectral density. Eigenvalues above λ₊ correspond to learned structure; those below are noise that can be discarded.
16
+
17
+ **Implication for Parameter Golf**: Before quantizing, we can project each weight matrix onto its signal subspace (eigenvalues > λ₊). This removes the noise bulk — which is high-entropy and hard to compress — leaving only the low-rank signal, which has far lower entropy. RMT-KD achieves 80% parameter reduction with +1.8% accuracy on BERT.
18
+
19
+ **Concrete operation**: For each weight matrix W:
20
+ 1. Compute SVD: W = UΣV^T
21
+ 2. Estimate noise variance σ² from calibration data
22
+ 3. Compute MP bulk edge: λ₊ = σ²(1 + √(m/n))²
23
+ 4. Keep only singular values σᵢ > √λ₊, zero out the rest
24
+ 5. Store the truncated SVD: W ≈ U_k Σ_k V_k^T where k = #{σᵢ > √λ₊}
25
+
26
+ ---
27
+
28
+ ## Theorem 2: Incoherence Processing via Randomized Hadamard Transform (QuIP#, arxiv 2402.04396)
29
+
30
+ **Statement**: For any weight matrix W ∈ ℝ^{m×n} and Hessian H ∈ ℝ^{n×n}, the Randomized Hadamard Transform (RHT) produces W̃ = U·S_U·W·S_V·V^T and H̃ = V·S_V·H·S_V·V^T such that:
31
+ - W̃ is μ_W-incoherent with μ_W = 2log(4mn/δ)
32
+ - H̃ is μ_H-incoherent with μ_H = √(2log(2n²/δ))
33
+ with probability ≥ 1-δ.
34
+
35
+ **What this means**: Incoherent matrices have no outliers — all entries are approximately the same magnitude. This is *exactly* the condition under which scalar quantization is near-optimal (approaching the Shannon rate-distortion bound). Without incoherence processing, outliers force the quantizer to waste bits on large dynamic ranges.
36
+
37
+ **Mathematical fact (Zador's theorem)**: For a d-dimensional source with distribution f(x), the minimum achievable MSE distortion at rate R bits/sample is:
38
+ ```
39
+ D*(R) ≈ (1/(2πe)) · (∫f(x)^{d/(d+2)} dx)^{(d+2)/d} · 2^{-2R}
40
+ ```
41
+ For a uniform (incoherent) distribution, this achieves the best possible rate. For a distribution with outliers, the distortion is strictly worse.
42
+
43
+ **Implication**: Apply RHT before quantization to make the weights maximally amenable to fixed-rate coding. This is provably better than the current SDClip approach (which clips outliers but doesn't eliminate them).
44
+
45
+ **Concrete operation**:
46
+ 1. Generate random sign vectors S_U, S_V ∈ {±1}^n
47
+ 2. W̃ = Had(diag(S_U) · Had(diag(S_V) · W^T)^T) — O(n log n) via Fast Walsh-Hadamard
48
+ 3. H̃ = Had(diag(S_V) · Had(diag(S_V) · H)^T)
49
+ 4. Quantize W̃ (now incoherent) with LDLQ adaptive rounding
50
+ 5. At inference: dequantize W̃_q, then undo the transform: W_q = Had^{-1}(W̃_q)
51
+
52
+ **Key advantage**: The Hadamard transform is its own inverse (H^{-1} = H^T = H/n) and costs O(n log n). No extra storage needed — just store the random signs (n bits per matrix).
53
+
54
+ ---
55
+
56
+ ## Theorem 3: Optimal Distortion Rate via Sphere Quantization (TurboQuant, arxiv 2504.19874)
57
+
58
+ **Statement (Theorem 1)**: For any vector x ∈ S^{d-1} on the unit sphere, TurboQuant achieves:
59
+ ```
60
+ D_mse ≤ (√3 · π / 2) · 4^{-b}
61
+ ```
62
+ at b bits per coordinate, which is within a constant factor (≈2.7×) of the information-theoretic lower bound.
63
+
64
+ **How it works**:
65
+ 1. Apply a random rotation Π to the weight vector
66
+ 2. After rotation, each coordinate follows a Beta distribution → nearly Gaussian in high dimensions
67
+ 3. Coordinates become nearly independent → apply optimal scalar quantizer per coordinate
68
+ 4. The optimal scalar quantizer centroids are precomputed (continuous k-means on Beta distribution)
69
+
70
+ **This is the Pyramid Vector Quantization (PVQ) insight** (arxiv 2410.16926): by reparameterizing weights as direction (on the sphere) + scale, we can use the integer lattice on the sphere as an implicit codebook. No explicit codebook storage needed. PVQ achieves signal-to-quantization-noise ratios close to the optimal E8 lattice.
71
+
72
+ **For Parameter Golf**: PVQ at groupsize 8-16 achieves ~1 dB better SQNR than scalar INT6, equivalent to ~0.5 extra bits of precision for free. At Llama-3 70B, PVQ achieves 3.25 bits/weight retaining 98% downstream accuracy.
73
+
74
+ ---
75
+
76
+ ## The Complete Pipeline: RMT → RHT → PVQ
77
+
78
+ Chain the three theorems into a principled compression pipeline:
79
+
80
+ ```
81
+ Training (standard) → Spectral Truncation (RMT) → Incoherence Processing (RHT) → Spherical Quantization (PVQ) → Entropy Coding (Brotli)
82
+ ```
83
+
84
+ ### Step 1: Train as usual
85
+ Standard training with Muon + current SOTA recipe (11L × 512d, etc.)
86
+
87
+ ### Step 2: Spectral Truncation (post-training)
88
+ For each weight matrix W:
89
+ ```python
90
+ U, S, Vt = torch.linalg.svd(W, full_matrices=False)
91
+ # Estimate noise floor via Marchenko-Pastur
92
+ aspect_ratio = W.shape[0] / W.shape[1]
93
+ sigma_sq = median(S**2) / (1 + sqrt(aspect_ratio))**2 # robust estimator
94
+ lambda_plus = sigma_sq * (1 + sqrt(aspect_ratio))**2
95
+ threshold = sqrt(lambda_plus)
96
+ mask = S > threshold
97
+ W_trunc = (U[:, mask] * S[mask]) @ Vt[mask, :]
98
+ ```
99
+ This removes ~20-40% of singular values (noise), reducing effective rank and entropy.
100
+
101
+ ### Step 3: Incoherence Processing (pre-quantization)
102
+ ```python
103
+ # Randomized Hadamard Transform — O(n log n)
104
+ S_signs = torch.randint(0, 2, (n,)) * 2 - 1 # random ±1
105
+ W_hat = hadamard_transform(diag(S_signs) @ W_trunc.T).T
106
+ H_hat = hadamard_transform(diag(S_signs) @ H @ diag(S_signs))
107
+ ```
108
+ Now W_hat is μ-incoherent: no outliers, uniform magnitude distribution.
109
+
110
+ ### Step 4: Hessian-Aware PVQ Quantization
111
+ ```python
112
+ # Decompose into direction (on sphere) + scale (amplitude)
113
+ rows = W_hat.reshape(-1, group_size) # group_size = 8 or 16
114
+ scales = rows.norm(dim=1, keepdim=True)
115
+ directions = rows / scales.clamp_min(1e-10)
116
+
117
+ # Quantize direction via PVQ (project onto integer lattice on L1 sphere)
118
+ K = 2**bits - 1 # number of pulses
119
+ q_directions = pvq_quantize(directions, K) # maps to integer lattice
120
+ q_scales = quantize_beta(scales, bits=4) # optimal Beta quantizer for amplitudes
121
+
122
+ # Encode: PVQ codes are uniquely decodable, no explicit codebook needed
123
+ codes = pvq_encode(q_directions) # combinatorial number system
124
+ ```
125
+
126
+ ### Step 5: Entropy Coding
127
+ Apply Brotli-11 to the quantized byte stream. Because:
128
+ - Spectral truncation removed high-entropy noise → lower entropy
129
+ - Incoherence processing uniformized magnitudes → better compression
130
+ - PVQ encodes more information per bit than scalar INT6 → fewer total bits
131
+
132
+ ### Step 6: Inference (dequantization)
133
+ ```python
134
+ # Reverse pipeline
135
+ q_directions = pvq_decode(codes)
136
+ rows_hat = q_directions * q_scales
137
+ W_hat = rows_hat.reshape(m, n)
138
+ # Undo Hadamard
139
+ W_q = hadamard_transform(diag(S_signs) @ W_hat.T).T # RHT is its own inverse up to scaling
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Why This Beats Current GPTQ + Brotli
145
+
146
+ | Property | GPTQ + SDClip + Brotli | RMT → RHT → PVQ + Brotli |
147
+ |----------|------------------------|---------------------------|
148
+ | Outlier handling | Clips to k×std (heuristic) | Hadamard provably eliminates outliers (μ = O(log n)) |
149
+ | Quantization | Scalar per-row INT6 | Vector PVQ on sphere (1 dB better SQNR) |
150
+ | Noise removal | None | MP spectral truncation removes noise bulk |
151
+ | Rate-distortion | ~2-3 dB from Shannon bound | ~1 dB from Shannon bound (TurboQuant Thm 1) |
152
+ | Codebook storage | None (good) | None (PVQ uses implicit lattice) |
153
+ | Dequant overhead | Simple: q × scale | Hadamard + PVQ decode (~O(n log n)) |
154
+ | Proven guarantees | GPTQ has LDLQ optimality only | All three steps have proven bounds |
155
+
156
+ ### Expected Gain
157
+
158
+ Each improvement compounds:
159
+ - Spectral truncation: ~15-25% fewer effective parameters to store (removes noise)
160
+ - RHT incoherence: ~0.5-1.0 bits/weight better effective precision
161
+ - PVQ vs scalar: ~0.5-1.0 dB better SQNR at same bits
162
+
163
+ Combined: **equivalent to gaining ~1-2 extra bits of precision**, which is like going from INT6 to INT7-8 quality at the same storage budget. Or equivalently, **fitting ~20-30% more effective parameters in 16MB**.
164
+
165
+ At the scaling law, 20-30% more effective parameters ≈ **-0.005 to -0.015 BPB**.
166
+
167
+ ---
168
+
169
+ ## Mathematical Elegance
170
+
171
+ The pipeline has a clean information-geometric interpretation:
172
+
173
+ 1. **RMT Truncation** = project onto the **signal manifold** (remove directions with < noise-level curvature on the loss landscape)
174
+ 2. **RHT Incoherence** = isometrically embed the weight space into a **maximally spread** coordinate system (minimize the max-coordinate ratio, which is the entropy-penalty for scalar coding)
175
+ 3. **PVQ Quantization** = encode on the **sphere** using the optimal integer lattice (the L1-sphere lattice approaches Zador's bound for spherically symmetric sources)
176
+
177
+ Each step reduces entropy while provably preserving signal. The composition is provably near-optimal: within a constant factor of the information-theoretic minimum description length for the learned weight distribution.
178
+
179
+ ---
180
+
181
+ ## Implementation Complexity
182
+
183
+ The full pipeline adds ~150 lines of code to the existing GPTQ path:
184
+ - SVD for spectral truncation: `torch.linalg.svd` (already in PyTorch)
185
+ - Hadamard transform: fast WHT in ~20 lines (bit-reversal + butterfly ops)
186
+ - PVQ quantize/encode/decode: ~80 lines (Algorithm 1-3 from the PVQ paper)
187
+ - No external libraries needed. No GPU kernels needed for the quantization path (it runs post-training on CPU).
188
+
189
+ The inference overhead (Hadamard + PVQ decode) adds ~5-10% to eval time, well within the 10-minute eval budget.
190
+
191
+ ---
192
+
193
+ ## References
194
+
195
+ 1. **Marchenko-Pastur Spectral Separation**: "Spectral Geometry for Deep Learning" (arxiv 2602.22345, 2026) — 80% compression, +1.8% accuracy on BERT via MP bulk edge estimation
196
+ 2. **Incoherence + RHT**: "QuIP#: Even Better LLM Quantization" (arxiv 2402.04396, 2024) — proven O(log n) incoherence bound, 2-bit quantization retaining >95% quality on Llama-3 70B
197
+ 3. **PVQ on Sphere**: "Pyramid Vector Quantization for LLMs" (arxiv 2410.16926, 2024) — SQNR close to E8 optimal, 3.25 bits/weight on Llama-3 70B retaining 98% accuracy
198
+ 4. **TurboQuant Bounds**: "Online Vector Quantization with Near-optimal Distortion Rate" (arxiv 2504.19874, 2025) — proven within 2.7× of Shannon lower bound at all bit-widths
199
+ 5. **Fisher-Weighted SVD**: "Generalized Fisher-Weighted SVD" (arxiv 2505.17974, 2025) — Kronecker-factored Fisher for optimal low-rank approximation respecting parameter importance
200
+ 6. **Zador's Theorem** (1963): Asymptotic distortion-rate function for vector quantization — the theoretical floor our pipeline approaches