Preprint ยท 2026

N-Gram Memories at Two Bits Quantizing Lookup Tables in Large Language Models

  • Donghoon Han Dnotitia
  • Minseop Jung Dnotitia
  • Dong Woo Kwak Dnotitia
  • SeungJae Lee Dnotitia
  • Junhoo Lee KAIST
arXiv 2610.21810 Model coming soon
Conditional Program overview: input addresses select independent row records, each holding a trellis code and a local scale; a shared decoder reconstructs the row and the scale restores its norm
Conditional Program (CP). An input selects row addresses in the compressed memory. Each record contains a trellis code and a bf16 scale; a shared decoder reconstructs the vector, and the scale restores its norm before the existing readout. (a) Offline, the encoder selects a low-error trellis path and stores its code with the norm-restoring scale. (b) Online, only addressed records are fetched, decoded and scaled.

Abstract

Conditional memory expands language-model capacity through selective lookup, but the full embedding table must remain available for every possible input. We introduce Conditional Program (CP), a compressed representation that reconstructs only the rows an input requests. CP represents each row by a short code and a local scale, with a reconstruction program shared across the table. We instantiate this representation with a Gaussian trellis, norm restoration and independently decodable row records. CP's two-bit code lowers output KL by 41โ€“63% relative to 2-bit round-to-nearest. Analysis across three trained n-gram memory families shows that Gaussian-like coordinate statistics coexist with learned relationships among rows; at matched storage budgets, the shared trellis outperforms the fitted codebooks and low-rank residual variants we test. For DeepSeek, it reduces table storage from 203 GB to 51 GB, leaving room for larger workloads when the table is kept on GPU.

Key numbers

203 โ†’ 51 GB
DeepSeek table storage
41โ€“63%
Lower output KL vs. 2-bit RTN
4โ€“8ร—
Smaller tables at two bits
10.78 โ†’ 6.54 ms
Host-memory lookup, 4k-token prefill

1. The problem: a huge table, read a few rows at a time

Conditional memory adds capacity without a proportional increase in per-token compute: a model hashes input n-grams into row addresses and reads only those rows from a large embedding table. DeepSeek-V4.1-Flash, Qwen3.8-Flash-Next and LongCat-Flash-Lite all carry such tables โ€” 202.7 GB, 102.4 GB and 62.8 GB respectively. Moving them from GPU to host memory changes where that cost is paid without reducing it.

Weight quantization methods are built for dense matrices. A lookup table is different: storage must shrink across the whole table, but each request touches only a handful of rows. A format that couples rows inside larger tiles saves bytes yet forces the runtime to fetch and decode unrelated data on every lookup.

2. Conditional Program

CP stores each row ei as a short code ci and a local scale ฮฑi, and reconstructs it with a decoder shared by the whole table: รชi = ฮฑi ยท f(ci). Three design choices follow from the access pattern and the row statistics.

  • Shared Gaussian trellis. Normalized rows accumulate many small, weakly dependent training contributions, so their coordinates look approximately Gaussian. CP encodes them in their stored coordinates with a Gaussian HYB bitshift trellis (tail-biting), without an extra rotation.
  • Norm restoration. Instead of the least-squares scale, which shrinks rows whose direction is imperfectly decoded, CP sets ฮฑi = โ€–eiโ€– / โ€–f(ci)โ€–, preserving the magnitude the model consumes.
  • Independent row records. Each code and its bf16 scale form one addressable record. A fused kernel fetches and decodes only the requested rows and hands them to the unchanged readout in the original lookup order.

3. Downstream quality at two bits

We compress only the lookup tables and evaluate 40 tasks across commonsense, knowledge, reading comprehension, multilingual understanding, and math and code. Removing the table shows how much each model relies on it; CP keeps most of that benefit at roughly a quarter to an eighth of the storage.

Method Bits Table GB PopQA TriviaQA GSM8K Overall
DeepSeek โ€” Originalโ€”202.744.287.996.479.8
w/o memoryโ€”0.020.975.095.873.5
RTN261.443.187.897.079.7
CP250.743.787.796.479.9
Qwen โ€” Originalโ€”102.436.382.387.675.6
w/o memoryโ€”0.026.673.483.072.4
RTN215.435.182.086.475.4
CP213.436.482.286.875.5
LongCat โ€” Originalโ€”62.826.668.590.868.2
w/o memoryโ€”0.011.831.213.030.5
RTN29.826.167.588.866.7
CP28.126.168.389.067.3

Selected columns from Table 1 of the paper (scores 0โ€“100; Overall equally weights five task-group means). Table GB includes scales and offsets. The paper also reports RTN 3-bit, QTIP and CP at 1.5 bits, and all 40 tasks in the appendix.

4. Output fidelity across storage budgets

Table size versus output KL on DeepSeek, Qwen and LongCat; the CP curve lies below and left of RTN, QTIP and four-bit float formats
Table size versus six-domain geometric-mean output KL (log scale); lower and further left is better. CP labels include per-row scales.

Task scores can hide behavioral drift, so we also measure per-token KL(porig โ€– pquant) over six text domains. At two bits CP lowers KL by 41โ€“63% relative to RTN and by a further 3โ€“9% relative to a QTIP-style trellis with one scale per table. CP at 2.5 bits approaches RTN 3-bit with less storage, and at higher rates it beats NVFP4 and MXFP4 while using less memory.

5. What matters in the design

A shared trellis beats fitted codebooks. Frequently read rows do share structure โ€” 16 fitted directions capture 10โ€“33% of their energy against a 6โ€“10% Gaussian reference. Yet at a matched 2.10 bpp on Qwen, the shared trellis (KL 0.0198) outperforms vector quantizers fitted to the table (0.0226โ€“0.0238), and explicit mean or principal-component terms buy little for the storage they cost.

Restore the norm, not the least-squares fit. With identical codes and storage, the norm-restoring scale gives lower output KL than the least-squares scale on all three models (e.g. 0.0327 vs. 0.0349 on Qwen, 0.0426 vs. 0.0462 on LongCat). Minimizing reconstruction error is not the same as preserving model behavior. Within-row rotation shows no resolved benefit.

6. Serving

Selective lookup. Replaying 4,096-token DeepSeek lookups on one H200, CP's row records complete in 0.190 ms from HBM versus 0.221 ms for a tile-window decoder over QTIP's tiled layout, and in 6.54 ms versus 10.78 ms from pinned host DRAM over PCIe.

Workload capacity. On four H200s, the DeepSeek table drops from 50.7 GB to 12.7 GB per GPU. Prefill for 8 ร— 4k tokens falls from 64.66 s to 13.27 s, and a 512-sequence decode batch and a 64k-token prefill that run out of memory with FP8 tables now fit. On eight GPUs, CP frees 19.0 GB per GPU, raising the largest tested decode batch from 1,024 to at least 2,048 and prefill from 96k to at least 128k tokens.

Scope. Results cover post-training compression of three models with hashed lookup tables and may not extend to other memory architectures. When GPU memory is already sufficient, complete inference steps show little speed improvement in our implementation.

Citation

@article{han2026ngram,
  title   = {N-Gram Memories at Two Bits: Quantizing Lookup Tables in Large Language Models},
  author  = {Han, Donghoon and Jung, Minseop and Kwak, Dong Woo and Lee, SeungJae and Lee, Junhoo},
  journal = {arXiv preprint arXiv:2610.21810},
  year    = {2026}
}