Exact GPU-Native Leech Lattice Quantization and Differentiable Soft Routing via Golay Sextet Contraction
196,560 unit codewords. Structured hard selection, differentiable full-shell routing, fractional-bit residual encoding and packed cosine search.
Abstract
The minimal shell of the 24-dimensional Leech lattice contains 196,560 vectors with exceptional spherical geometry, but direct enumeration imposes substantial computation and memory costs. We derive an exact, subtraction-free factorization of its Boltzmann partition function using extended binary Golay sextets, together with differentiable routing, Jacobian-vector products, and tropical hard quantization with canonical 18-bit indexing. The representation requires 64.17 KiB for soft routing and 80.64 KiB including hard indexing, compared with an 18 MiB dense FP32 dictionary. On a Tesla T4, compiled soft routing achieves up to 13.03× acceleration over the tested dense baseline and reduces peak additional allocated GPU memory by 90.9%. Greedy residual quantization provides index rates of 0.75, 1.50, and 2.25 bits/dimension using fixed codewords and shared calibrated gains. Across two pretrained sentence-embedding models and 18,118 filtered 20 Newsgroups documents, Leech achieves lower distortion in 177 of 180 paired, matched-rate PQ comparisons. Under topic-domain calibration shift, standard per-subspace PQ incurs 7.6–9.1% additional distortion, whereas Leech distortion remains nearly unchanged. Actual packed index compression reaches 40.42× and 20.76× relative to FP32 at up to 100,000 vectors, with numerically verified direct compressed scoring. Limitations include slower prototype compressed search and inferior reconstruction relative to binary scalar quantization in a learned Fashion-MNIST bottleneck.
Unrefereed technical report. Historical measurements are from the frozen notebooks; the installed package passed separate CPU and T4 regression checks.
Install directly
python -m pip install https://srfp311t1.com/downloads/leech_quant-0.1.0-py3-none-any.whl
Python 3.10+, PyTorch 2.2+ and NumPy 1.24+. Install a suitable CUDA build of PyTorch first. No PyPI account or package publication is needed; dependencies still need to be installed. The static package index is also available at /simple/.
For environments with both dependencies already installed, use:
python -m pip install --no-deps https://srfp311t1.com/downloads/leech_quant-0.1.0-py3-none-any.whl#sha256=d9fb0d193839c766e9976e409287e91ffb870a95e7b977d99bab594c267e1af6
Search a compressed index
from leech_quant import LeechIndex index = LeechIndex(dim=768, stages=2, device="cuda") index.build(embeddings, calibration=calibration_embeddings) scores, ids = index.search(queries, k=10, mode="tiled")
Pass separate calibration vectors for scientific comparisons. Dimensions must be divisible by 96. Use mode="lut" for direct compressed scoring; mode="tiled" decodes bounded tiles and batches queries.
Encode and decode
from leech_quant import LeechQuantizer q = LeechQuantizer(stages=3, device="cuda") q.fit_gains(calibration_embeddings) packed = q.encode(embeddings) reconstructed = q.decode(packed)
Differentiable routing
from leech_quant import LeechSoftRouter router = LeechSoftRouter(T=0.07, device="cuda") logZ, mean = router(blocks) # [B, 24] jvp = router.jvp(blocks, upstream_gradient)
The fixed dictionary requires no learned centroids, but the reconstruction gains are calibrated. Standalone quantization does not normalize vectors automatically; the search index does.
Calibration-domain transfer
18,118 filtered 20 Newsgroups documents; 13,766 database vectors across both domains and 256 queries per seed (49, 50, 51). The table compares the same held-out target documents under target versus source calibration. Penalty = 100 × (source-calibrated MSE / target-calibrated MSE − 1). Three-seed means. Standard PQ is a custom independent 4D Lloyd implementation, not FAISS.
MPNet · 768D
| Method | Bits/dim | Target calibrated MSE | Source calibrated MSE | Shift penalty | OOD R@10 |
|---|---|---|---|---|---|
| leech18 | 0.75 | 0.409743 | 0.409743 | +0.0000% | 78.62% |
| pq18_std | 0.75 | 0.406867 | 0.443371 | +8.9720% | 77.08% |
| pooled_pq18 | 0.75 | 0.463154 | 0.465670 | +0.5434% | 76.33% |
| leech36 | 1.50 | 0.167366 | 0.167362 | -0.0026% | 87.24% |
| pq36_std | 1.50 | 0.169412 | 0.184877 | +9.1286% | 86.28% |
| pooled_pq36 | 1.50 | 0.190169 | 0.191386 | +0.6402% | 86.43% |
| leech54 | 2.25 | 0.068527 | 0.068527 | -0.0006% | 92.32% |
| pooled_pq54 | 2.25 | 0.073601 | 0.074210 | +0.8276% | 91.90% |
MiniLM · 384D
| Method | Bits/dim | Target calibrated MSE | Source calibrated MSE | Shift penalty | OOD R@10 |
|---|---|---|---|---|---|
| leech18 | 0.75 | 0.407552 | 0.407552 | -0.0000% | 67.47% |
| pq18_std | 0.75 | 0.433407 | 0.467596 | +7.8885% | 64.66% |
| pooled_pq18 | 0.75 | 0.460000 | 0.463443 | +0.7486% | 65.44% |
| leech36 | 1.50 | 0.165652 | 0.165657 | +0.0030% | 82.50% |
| pq36_std | 1.50 | 0.179375 | 0.194101 | +8.2097% | 80.16% |
| pooled_pq36 | 1.50 | 0.185259 | 0.186856 | +0.8622% | 80.39% |
| leech54 | 2.25 | 0.067488 | 0.067485 | -0.0044% | 88.62% |
| pooled_pq54 | 2.25 | 0.071997 | 0.072774 | +1.0791% | 87.47% |
Across all 180 overlapping paired PQ comparisons: 177 lower-distortion wins and 159 higher-recall wins. Largest absolute relative shift across 54 paired Leech conditions: 0.009396%. Standard PQ54 was not evaluated. The comparisons are not independent trials and do not establish universal OOD robustness.
Download complete validation JSON · Vector rate–distortion plot
Bit-packed scale and search
Isotropic vectors, 32 queries; actual index MB (decimal) includes inverse norms and shared gains but excludes static tables. Batched and sequential search are reported separately.
50,000 × 768D
| Method | Index MB | Build (s) | Recall@10 | Batched QPS | Single QPS |
|---|---|---|---|---|---|
| FP32 | 153.60 | — | 100.00% | 4,151 | 152.0 |
| FP16 | 76.80 | — | 99.06% | 8,430 | 146.6 |
| Leech18 | 3.80 | 2.60 | 16.56% | 3,125 | 144.5 |
| Leech36 | 7.40 | 3.65 | 39.06% | 2,602 | 115.9 |
| Leech36 (1 sweep) | 7.40 | 7.15 | 39.06% | 2,734 | 115.0 |
| Pooled PQ36 | 7.40 | 0.08 | 37.81% | — | 209.6 |
100,000 × 768D
| Method | Index MB | Build (s) | Recall@10 | Batched QPS | Single QPS |
|---|---|---|---|---|---|
| FP32 | 307.20 | — | 100.00% | 6,155 | 248.1 |
| FP16 | 153.60 | — | 100.00% | 6,440 | 194.3 |
| Leech18 | 7.60 | 3.67 | 15.00% | 1,604 | 79.4 |
| Leech36 | 14.80 | 10.28 | 40.31% | 306 | 60.6 |
| Leech36 (1 sweep) | 14.80 | 14.68 | 40.31% | 1,423 | 60.2 |
| Pooled PQ36 | 14.80 | 0.18 | 40.31% | — | 106.0 |
Direct LUT vs. tiled scoring agreed on 100% of top-10 sets in the original experiments (maximum tile discrepancy 2.98e-8). Recall above is against the original FP32 neighbors, not agreement between compressed scoring modes. The 100K two-stage tiled timing variability is reported in full; its cause is unknown.
Full-shell soft routing
65,712 bytes of soft tables versus 18 MiB dense FP32 codebook; 82,576 bytes including hard indexing. Timings are steady-state original notebook measurements, not refactored-wheel benchmarks. Extra memory is peak additional allocated tensor memory.
All 18 measured batch / temperature combinations
| Batch | T | Dense ms | Chunked ms | Compiled ms | vs. dense | Compiled extra MiB |
|---|---|---|---|---|---|---|
| 1 | 0.001 | 0.589 | 3.634 | 0.816 | 0.72× | 0.14 |
| 8 | 0.001 | 1.099 | 3.648 | 1.041 | 1.06× | 1.09 |
| 32 | 0.001 | 1.795 | 3.635 | 0.896 | 2.00× | 4.33 |
| 128 | 0.001 | 6.420 | 6.971 | 1.220 | 5.26× | 17.31 |
| 256 | 0.001 | 12.509 | 12.884 | 0.966 | 12.95× | 34.82 |
| 384 | 0.001 | 18.685 | 18.304 | 1.442 | 12.95× | 52.64 |
| 512 | 0.001 | 24.758 | 24.445 | 1.901 | 13.03× | 69.65 |
| 768 | 0.001 | 37.116 | 36.374 | 2.931 | 12.67× | 104.26 |
| 1024 | 0.001 | 49.452 | 45.667 | 3.967 | 12.47× | 139.37 |
| 1 | 0.070 | 0.331 | 3.283 | 1.080 | 0.31× | 0.14 |
| 8 | 0.070 | 0.876 | 3.478 | 0.839 | 1.04× | 1.09 |
| 32 | 0.070 | 1.831 | 3.516 | 0.822 | 2.23× | 4.33 |
| 128 | 0.070 | 6.374 | 6.888 | 0.862 | 7.40× | 17.31 |
| 256 | 0.070 | 12.491 | 12.820 | 1.458 | 8.57× | 34.82 |
| 384 | 0.070 | 18.685 | 18.298 | 1.482 | 12.61× | 52.64 |
| 512 | 0.070 | 24.764 | 24.259 | 1.980 | 12.51× | 69.65 |
| 768 | 0.070 | 37.079 | 36.099 | 2.989 | 12.40× | 104.26 |
| 1024 | 0.070 | 49.371 | 45.601 | 4.123 | 11.97× | 139.37 |
Download V3 routing results · Vector latency and memory plot
Scope and limitations
Research prototype, not a production ADC engine. Sequential LUT throughput (60–145 QPS) trails the tested pooled PQ36 and dense GPU search. All measurements use one T4; hardware-optimized dense or PQ engines are not compared. Fashion-MNIST binary FSQ achieves lower learned-bottleneck MSE than Leech, and fixed-temperature soft backward underperforms STE.
Exactness refers to the mathematical minimal-shell factorization and numerically verified scoring of compressed reconstructions, not infinite-lattice CVP or lossless neighbor recovery. The 80.64 KiB encoder/router table figure is not total scanner memory. At 768D, query LUTs occupy 727,808 bytes. The installed wheel passed both CUDA checks; at T=0.001 the two stable/ordinary FP32 JVP modes differed by up to 0.0112152 in absolute value. LLM weight/KV compression is untested.
Downloads and reproducibility
SHA-256 manifest covers every other download in this release. The wheel and source distribution are unchanged from the Apache-2.0 release; the PDF contains the self-hosted canonical URL.
Frozen benchmark logs
Cite this technical report
@misc{leechquant2026,
title = {Exact GPU-Native Leech Lattice Quantization and Differentiable Soft Routing via Golay Sextet Contraction},
author = {{SRFP311T1 Collaboration}},
year = {2026},
month = dec,
note = {SRFP311T1 technical report and software release v0.1.0},
url = {https://srfp311t1.com/leech_quant/}
}
Software license: Apache-2.0. The paper is a separate scholarly work; no separate paper reuse license is asserted.
Research and integration inquiries
Interested in fused C++/AVX-512, CUDA/Triton ADC kernels, vector-database integration or low-bit model compression research? Contact dev@srfp311t1.com.