Many recent open-weight language models use n-gram embedding tables to improve performance. These tables store learned representations of short token sequences, such as pairs or triples of consecutive tokens, which the model retrieves during processing. However, they can require substantial memory: DeepSeek-V4.1-Flash, for example, allocates 196 billion parameters to its Engram n-gram memory. We therefore investigate whether this memory cost can be reduced while preserving the performance improvement that the tables provide. We propose storing n-gram embeddings at low precision and systematically investigate different quantization methods and bit allocations across tables. Across nanochat-, Llama-, and GPT-2-family models trained from scratch, four-bit tables save approximately 75% of table memory while preserving more than 99% of the validation-loss improvement from adding the tables. Using fewer bits leads to a larger drop in performance, although we find that a short fine-tuning phase recovers a significant part of this loss. In addition, reinvesting the saved memory in larger tables can improve performance beyond that of the original full-precision tables while still using less memory. These table memory savings also extend to large existing models: on DeepSeek-V4.1-Flash and Qwen3.8-Flash-Next, low-bit tables save 47-55% of table memory, with perplexity increases of less than 1.2% and largely preserved downstream task performance. These findings establish low-bit precision as a practical way to reduce the memory requirements of n-gram embeddings and use the saved capacity to improve model performance.
Figures & tables
Figure 1: Four n-gram lookups, stored at low precision. (a) The bigram and trigram ending at the current token each retrieve two embeddings. The four embeddings are concatenated and added to the token embedding to form ut . (b) Each two-bit index selects one of four codebook values. Multiplying each selected value by the embedding’s 16-bit scale reconstructs the embedding. Codebook values use 16 bits and are shared across all embeddings of a table.
Figure 2: Four-bit embeddings save about 75% of table memory while retaining more than 99% of the improvement. (a) The five models with the default 262k embeddings per table. (b) The 26M nanochat model and both Llama-family models with 1M embeddings per table. Points and error bars show means and sample standard deviations over three seeds. The dashed line matches the original 16-bit tables.
Figure 3: Choosing an appropriate embedding scale is more important than choosing among uniform, normal-quantile, and Lloyd–Max codebooks. (a) Two-bit comparisons on the 31M Llama-family model with 262k embeddings per table. Uniform* is the three-value variant {−1,0,1} that includes zero. Error bars show sample standard deviations over three seeds. (b) Selected bigram/trigram precision pairs for all five models with the default 262k embeddings per table. Appendix C.3 gives all precision pairs.
Figure 4: Uniform and mixed precision provide different memory–performance choices in DeepSeek-V4.1-Flash and Qwen3.8-Flash-Next. (a) Two through five bits for every table, with labels giving bits per value. (b) Representative mixed allocations, ordered by n-gram length. Both panels use WikiText-2 validation perplexity.
Figure 5: Downstream evaluation of the selected mixed-precision settings. Change in accuracy (%) for DeepSeek 4/5/4 and Qwen 4/3, computed as low-bit accuracy minus original accuracy. Error bars show paired 95% bootstrap confidence intervals. The settings save 46.7% and 55.0% of table memory, respectively.
Figure 6: Fine-tuning after compression recovers much of the n-gram improvement. Improvement retained on the 31M Llama-family model, relative to full-precision and no-table models with the same training budget. Error bars show sample standard deviations over three seeds.
Figure 7: Larger low-bit tables can improve performance while using less memory. Both axes use the original 262k-embedding, 16-bit tables as the reference, marked at (100%, 100%). The shaded region indicates greater improvement while using less memory. Fine-tuning follows compression. Error bars show sample standard deviations over three seeds.
Appendix figures & tables13 assets
Supplementary material from the paper’s appendix.
Appendix
Model
Parameters (millions)
Layers
Width d
Embeddings per table
nanochat 26M
26.35
6
384
262k, 1M
nanochat 50M
50.33
8
512
262k
GPT-2-family 30M
30.46
8
512
262k
Llama-family 31M
30.94
8
512
262k, 1M
Llama-family 322M
322.50
32
960
262k, 1M
Appendix
Table 1: Model dimensions and n-gram table sizes. Parameter counts exclude the n-gram tables, and d denotes model width.
Setting
nanochat
GPT-2 30M / Llama 31M
Llama 322M
Optimization
Backbone optimizer
Muon / AdamW
AdamW
AdamW
Table optimizer
AdamW
AdamW
AdamW
Backbone learning rate
0.04
0.001
0.0006
Table learning rate
0.6768/d
0.003
0.0018
Training budget
Appendix
Table 2: Training settings. For nanochat, the backbone learning rate applies to Muon-updated matrices. Other parameter groups follow the original implementation.
Precision (bits)
Memory used (%)
Validation loss (bits/byte)
Loss change (%)
Improvement (%)
nanochat 26M
1
7.3
1.03963 ± 0.00032
2.132 ± 0.049
29.0 ± 2.8
2
13.5
1.02164 ± 0.00066
0.365 ± 0.004
87.9 ± 0.6
3
19.8
1.01876 ± 0.00070
0.082 ± 0.001
97.3 ± 0.2
4
26.0
1.01812 ± 0.00070
0.018 ± 0.000
99.4 ± 0.0
16
100.0
1.01793 ± 0.00070
0.000 ± 0.000
100.0 ± 0.0
Appendix
Table 3: Compression with 262k embeddings per table, using Lloyd–Max codebooks and error-fitted scales. Validation loss, loss change, and improvement are means ± sample standard deviations over three seeds.
Precision (bits)
Memory used (%)
Validation loss (bits/byte)
Loss change (%)
Improvement (%)
nanochat 26M
1
29.2
1.03065 ± 0.00097
1.250 ± 0.050
58.4 ± 2.2
2
54.2
1.01127 ± 0.00023
− 0.655 ± 0.047
121.9 ± 2.6
3
79.2
1.00829 ± 0.00021
− 0.947 ± 0.049
131.6 ± 3.2
4
104.2
1.00765 ± 0.00021
− 1.010 ± 0.049
133.7 ± 3.3
16
400.0
1.00746 ± 0.00021
− 1.028 ± 0.049
134.3 ± 3.4
Appendix
Table 4: Compression with 1M embeddings per table, using Lloyd–Max codebooks and error-fitted scales. Validation loss, loss change, and improvement are means ± sample standard deviations over three seeds.
Precision / codebook and scale
nanochat 26M, 262k 26M, 1M 50M, 262k
Llama-family 31M, 262k
GPT-2-family 30M, 262k
4 bits
Uniform*, maximum-based
1.01831
1.00783
0.97371
1.03994
1.07733
Lloyd–Max, error-fitted
1.01812
1.00765
0.97356
1.03971
1.07693
3 bits
Uniform*, maximum-based
1.02004
1.00950
0.97499
1.04172
1.08039
Lloyd–Max, error-fitted
1.01876
1.00829
0.97402
1.04021
1.07774
Appendix
Table 5: Validation loss (BPB), averaged over three seeds. Uniform* includes zero and uses 2b−1 values.
Figure 8: Complete bigram/trigram precision sweep with Lloyd–Max codebooks and error-fitted scales. Entries give improvement retained (%) as mean ± sample standard deviation over three seeds.
Figure 9: DeepSeek-V4.1-Flash: all 64 bigram/trigram/four-gram precision allocations with Lloyd–Max codebooks and error-fitted scales. Entries show validation perplexity change (%).
Figure 10: Qwen3.8-Flash-Next: all sixteen bigram/trigram allocations for each codebook, using error-fitted scales. Entries show validation perplexity change (%).
Model / dataset
Original
Low-bit
Change (%)
95% interval
DeepSeek / WikiText-2
2.7564
2.7870
+1.110
[0.689, 1.540]
DeepSeek / PTB
7.7730
7.7794
+0.082
[ − 0.145, 0.322]
DeepSeek / C4
7.9679
7.9584
− 0.119
[ − 0.357, 0.101]
Qwen / WikiText-2
4.2270
4.2671
+0.949
[0.443, 1.479]
Qwen / PTB
4.0633
4.0558
− 0.183
[ − 0.656, 0.282]
Qwen / C4
9.2329
9.2354
+0.027
[ − 0.232, 0.332]
Appendix
Table 6: Perplexity before and after compression with DeepSeek 4/5/4-bit tables and Qwen 4/3-bit tables. Confidence intervals for perplexity change are computed by paired bootstrap resampling of evaluation windows.
Model / task
Original
Low-bit
Difference
95% interval
DeepSeek / HellaSwag
82.48
82.44
− 0.04
[ − 0.38, +0.29]
DeepSeek / ARC-Challenge
61.60
60.58
− 1.02
[ − 2.65, +0.60]
DeepSeek / WinoGrande
64.48
62.75
− 1.74
[ − 4.18, +0.71]
Qwen / HellaSwag
87.72
87.57
− 0.15
[ − 0.39, +0.09]
Qwen / ARC-Challenge
62.88
63.65
+0.77
[ − 0.68, +2.22]
Qwen / WinoGrande
72.77
71.35
− 1.42
[ − 3.24, +0.39]
Appendix
Table 7: Downstream accuracy (%), with low-bit minus original accuracy and paired 95% bootstrap confidence intervals.
Training sequence
1 bit
2 bits
3 bits
4 bits
Compress → pre-train
77.0 ± 4.6
87.0 ± 9.4
92.2 ± 9.3
96.8 ± 0.3
Pre-train → compress → fine-tune
65.3 ± 0.9
92.0 ± 0.3
98.0 ± 0.0
99.5 ± 0.0
Pre-train → fine-tune → compress
− 5.7 ± 6.3
86.5 ± 0.9
97.4 ± 0.2
99.4 ± 0.1
Pre-train → compress
− 5.7 ± 4.6
86.5 ± 0.4
97.4 ± 0.1
99.4 ± 0.0
Appendix
Table 8: Improvement retained (%) for the four training sequences on the 31M Llama-family model, with 262k embeddings per table. Means and sample standard deviations over three seeds. Fine-tuning comparisons use equally fine-tuned references.
Precision (bits)
Improvement relative to original (%) Fine-tune then compress Compress then fine-tune
Memory (%)
nanochat 26M
1
63.0 ± 2.1
97.4 ± 0.9
29.2
2
126.0 ± 2.8
128.7 ± 3.0
54.2
3
135.5 ± 3.4
135.8 ± 3.5
79.2
4
137.5 ± 3.6
137.6 ± 3.6
104.2
Llama-family 31M
Appendix
Table 9: Fine-tuning 1M-embedding tables before or after compression. Improvement and table memory are relative to the original 262k-embedding, 16-bit tables. Results are means and sample standard deviations over three seeds.
Model
Conventional
Same-column
Fully random
16 bits
nanochat 26M
100.00 ± 0.00
104.84 ± 1.14
102.14 ± 4.33
GPT-2-family 30M
100.00 ± 0.00
98.46 ± 2.95
99.92 ± 3.36
Llama-family 31M
100.00 ± 0.00
112.03 ± 4.53
107.97 ± 10.99
2 bits
nanochat 26M
91.71 ± 1.23
93.61 ± 2.36
93.95 ± 3.04
Appendix
Table 10: Alternative hashing methods at 16-bit and two-bit precision. Values give the improvement relative to conventional 16-bit tables (%), reported as mean ± sample standard deviation over three seeds. For every row, 100% denotes the validation-loss reduction from adding conventional 16-bit tables to the corresponding model without tables.
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 203GB to 51GB, leaving room for larger workloads when the table is kept on GPU.
In a small language model the vocabulary is the single largest part. In Gemma 3 270M the embedding table holds 168M of 268M parameters, and because quantisation methods leave the embedding in 16-bit, it is also most of the file once the rest of the model is compressed. We ask what that table actually buys. We replace it with one frozen table of 512-bit codes, 16 MB, with no trainable parameters, derived once from a pretrained embedding by principal-component projection and sign binarisation, and we train the same Gemma-shaped body from scratch on the same 2.05B tokens with and without it. The learned table buys 0.20 nats of validation loss for 2.6 times the trainable parameters, but on LAMBADA, HellaSwag and PIQA the frozen-table model is better or tied; only ARC-Easy favours the learned table. With a ternary BitNet b1.58 body the whole model is a 46 MB file, still ties the float model on LAMBADA and PIQA, and on a laptop CPU generates 615 to 740 tokens per second in 62 MB of memory, five to six times the speed of the float model's 8-bit GGUF in llama.cpp at a seventh of the memory. The frozen table wins by 1.7 to 2.3 nats on rare words, accepts 10,000 new words after training with a 3% cost where the learned table collapses by 43%, and all of it is released with the weights, the data and every evaluation answer.
Low-bit quantization shrinks language models but treats precision as a single global hyper-parameter: every weight uses the same bit-width. We introduce Variable Bit-width Quantization (VBQ), a training-time method in which each contiguous group of 64 weights learns its own resolution from {1,2,4,8} bits via a Gumbel-Softmax relaxation, trained jointly by an alternating optimization that gives the precision logits a clean, task-aligned signal. VBQ discovers a consistent, strongly heterogeneous allocation within individual projection types, not merely across layers, impossible to express with per-layer methods: 69% of groups collapse to 1 bit, the LM head averages 1.09 bits, while the first MLP block keeps ~2.5 bits. This pattern is stable enough to freeze into a fixed recipe and reuse without further search. The recipe yields a "bigger-but-smaller" regime: a 131M model at 1.82 mean bits reaches perplexity 4.2 on TinyStories, beating a 55M FP16 model (PPL 4.4) at 3.8x less storage, and lets a 1.46B model on FineWeb-Edu match a 593M FP16 control at ~3.7x less storage with 2.5x more parameters. As quality-per-byte, VBQ is 3.9-8.4x more efficient than FP16. The recipe maps directly to packed low-bit storage, so it also accelerates inference: with custom fused dequantize-and-multiply kernels, memory-bandwidth-bound autoregressive decode is faster at equal output, and the speedup grows with scale (parity at 131M, 1.9x at 1.0B, 4.7x at 9B on Apple silicon). A distributional analysis (KL divergence and argmax-flip rate) reveals a striking mechanism: deeper layers progressively self-heal the quantization error injected by early layers. The win is a from-scratch, train-time phenomenon; scaling the search economically beyond 1.5B parameters remains open. VBQ reframes precision as a learnable, non-uniform resource and shows that spending a fixed bit budget unevenly beats spending it uniformly.