How to Compress and Freeze Embedding Layers in Small Models: When Over 60% of Parameters Live in the Vocabulary Table
This article explains why embedding tables can dominate the parameter count of small on-device models, often accounting for over 60% of total parameters. It covers the main causes of vocabulary bloat, including vocab size, hidden dimension, and weight tying, then presents four compression strategies: quantization, vocabulary pruning, low-rank factorization, and freezing the embedding layer. It also provides engineering guidance for measuring, validating, and deploying these optimizations on memory- and bandwidth-constrained devices.
1. Dissecting a small model: the heaviest part is not necessarily compute
Many people assume that a larger model is heavier and more cumbersome. However, when we take apart a small on-device model designed for phones and laptops with about 268 million parameters, a counterintuitive fact emerges: the feed-forward network (FFN) layers and attention projections, which are responsible for semantic transformation and reasoning computation, together account for only about 70 million parameters. The embedding table, which maps tokens to vectors, alone accounts for about 168 million parameters, or more than 60% of the total.
This means that for a model advertised as having “268 million parameters,” most of the storage and loading overhead does not come from the “compute units” we usually think of. Instead, it comes from a lookup table that performs almost no multiply-accumulate operations. For on-device scenarios that require extreme size and memory efficiency, this bulk is both the hardest to shed and the most easily overlooked.
2. Why the vocabulary table takes up so much space
To understand the root of the problem, start with the parameter count formula for an embedding table:
Embedding table parameters = vocab_size × hidden_size
Using a common configuration as an example, if the vocabulary size is 250,000 and the vector dimension is 672, then one table alone is:
250,000 × 672 ≈ 168 million parameters
This matches the earlier number exactly.
Two points are especially important:
- Vocabulary size expands with language and task requirements. Multilingual settings, mixed Chinese-English data, and the addition of many subword units can push the vocabulary size into the hundreds of thousands.
- The vector dimension cannot be compressed arbitrarily. The dimension determines the expressive capacity of each token, and lowering it too much may hurt semantic quality. As a result, designers are often reluctant to cut it aggressively.
A more difficult issue is that, in many architectures, this embedding table is also weight-tied with the final output layer. The same table is used both for input lookup and for output projection. Although this saves one set of parameters, it also means that the table is “locked” into the model backbone. Any compression must ensure that both the input side and the output side remain usable.
3. On-device deployment amplifies the cost problem
In the past, this kind of redundancy could be hidden by ample cloud memory and relatively low bandwidth costs. When a model is actually placed inside a phone, laptop, or embedded device, however, the situation changes completely:
- Every megabyte matters. Application package size, first-time download traffic, and device storage usage are all directly tied to the model file size.
- Memory bandwidth becomes a bottleneck for inference. On-device inference is often memory-access intensive. Large structures such as vocabulary tables, which require read-only, random-access lookup, continue to consume valuable memory bandwidth and cache.
- Cold starts are sensitive. Loading a large embedding table can significantly slow down the model’s first response, which directly affects user experience.
The question therefore shifts from “Can it run?” to “How can it run while being small and fast?” The vocabulary table is one of the highest-return places to start optimizing.
4. Four technical paths for compressing and slimming the vocabulary
1. Quantization: reducing each weight from 16 bits to lower precision
This is the most direct approach. Standard floating-point weights usually occupy 16 or even 32 bits, but the embedding table is not particularly sensitive to the precision of each individual value. Industry practice has shown that compressing weights to 8-bit integers often causes almost no quality loss. More aggressive schemes constrain weights to three values—-1, 0, and +1, also known as ternary quantization—and use an appropriate scaling factor to reduce the size by several times while keeping quality loss within an acceptable range.
Ternary quantization is especially suitable for read-only lookup structures such as embedding tables because:
- Lookup operations can directly read the low-bit weights using the index, reducing memory usage.
- Computation can be reduced to simple additions and subtractions, avoiding floating-point multiply-add operations.
2. Vocabulary pruning: directly reducing the number of tokens
Because the parameter count is linearly related to vocabulary size, removing low-frequency or redundant tokens is the most direct slimming method. Common practices include:
- Merging synonymous or visually similar subwords to reduce long-tail units.
- Removing tokens that are rarely or never used based on corpus frequency, and mapping them to an “unknown” or fallback unit.
- For multilingual models, pruning branches that are not needed for the target deployment languages.
Pruning requires careful handling of index remapping. The goal is to ensure that removed tokens can safely fall back during inference, avoiding out-of-bounds errors or semantic collapse.
3. Low-rank factorization: replacing one large matrix with two smaller matrices
An embedding table is essentially a large vocab × hidden matrix. If this matrix is “low-rank,” it can be approximated by multiplying two smaller matrices:
W (vocab × hidden) ≈ A (vocab × r) · B (r × hidden), where r ≪ hidden
By choosing an intermediate rank r that is much smaller than the original dimension, the parameter count drops from vocab × hidden to vocab × r + r × hidden. When the vocabulary is large, this decomposition can bring significant compression gains. The trade-off is an additional small matrix multiplication during lookup.
4. Freezing the embedding layer: locking down the vocabulary table
This is the approach referred to in the title: detach the embedding table from trainable parameters and fix it as a compressed static resource.
The core idea is that the embedding table is often already stable in the later stages of training, and further fine-tuning brings limited marginal benefit for downstream tasks. Therefore, near the end of training—or after loading an already trained model—the following process can be applied:
# Pseudocode: Freeze and compress the embedding tableembedding = model.embedding.weight # Shape: [vocab, hidden]# 1) Quantize to ternary values {-1, 0, +1}scale = embedding.abs().mean() # Compute the scale factorquantized = torch.sign(embedding / scale) # Take the sign to obtain ternary weights# 2) Detach from the computation graph and register as a read-only buffermodel.register_buffer("embedding_frozen", quantized, persistent=True)model.embedding.weight.requires_grad_(False)# 3) Dequantize during the forward passdef lookup(token_id):return model.embedding_frozen[token_id] * scale
The benefits of freezing are direct:
- Lower peak memory usage. After freezing, the model no longer keeps gradients or optimizer states for the embedding table. Optimizers such as Adam often need to store two momentum estimates for each parameter, and this overhead can be on the same order as the parameters themselves.
- More aggressive compression formats become usable. Because the embedding table no longer participates in training, it can safely use extreme compression methods such as binary, ternary, or sparse encodings that are less training-friendly.
- Training becomes more focused. More of the gradient budget can be spent on the compute layers that actually affect inference quality.
One important caveat is that freezing is not a permanent solution. If domain fine-tuning is performed later and the new corpus introduces expressions not covered by the old vocabulary, hard freezing may hurt performance. In that case, partial freezing can be used: freeze only high-frequency, stable tokens while keeping new or long-tail tokens trainable.
5. Engineering practice and validation
When applying these approaches in real projects, the following workflow is recommended:
- Profile before making changes. Accurately measure the parameter count and byte footprint of each layer, and confirm that the vocabulary table is indeed the largest part. This avoids optimizing in the wrong direction.
- Make single-point breakthroughs and validate one at a time. Start with quantization only, and measure changes in size, memory usage, latency, and downstream metrics. Then add pruning or factorization step by step. Avoid deploying multiple techniques at the same time, which can make it difficult to attribute the results.
- Benchmark latency and memory bandwidth on target devices. Theoretical compression ratios do not necessarily equal real-world speedups. Run benchmarks on the target hardware and pay attention to both first-byte latency and steady-state throughput.
- Keep fallback mechanisms and use canary releases. Vocabulary compression can affect semantics across the entire pipeline. Use canary releases and small-traffic A/B tests to monitor regressions on long-tail cases.
- Combine quantization with freezing. First freeze the embedding table to remove optimizer overhead, then apply low-bit quantization to the static table. Combining the two usually reduces the vocabulary table size to a fraction of the original while maintaining nearly unchanged quality.
6. Conclusion
Competition among small on-device models has shifted from “whether there are enough parameters” to “whether every byte is used well.” Once compute layers have been repeatedly compressed to the extreme, the long-neglected embedding vocabulary table becomes the last optimization opportunity. Through quantization, pruning, low-rank factorization, and freezing, the vocabulary table—which accounts for most of the model’s size—can be reduced to a fraction of its original size, significantly relieving memory bandwidth and loading pressure on devices. For teams that need to put models into phones and laptops, reducing this “bulk” first is often the highest-return first step.
