Shrinking Small Model Vocabulary: Embedding Layer Freezing in Trinarized Networks
As large language models are compressed for resource-constrained edge devices, the vocabulary embedding table has become a major bottleneck. This article explores why the embedding layer remains disproportionately large in sub-billion-parameter models, especially under trinarized network compression, and provides practical optimization strategies including vocabulary pruning, embedding freezing, and low-rank decomposition to achieve efficient edge deployment.
Shrinking Small Model Vocabulary: Embedding Layer Freezing in Trinarized Networks
With the rapid development of edge AI, compressing large language models (LLMs) and deploying them on resource-constrained devices like smartphones and laptops has become a focal point for developers. However, when examining the internal structure of small models with hundreds of millions of parameters, a critical yet often overlooked issue emerges: the vocabulary (embedding table) has become the biggest obstacle to further model size reduction.
Take a mainstream ~270M parameter small model designed for mobile and PC as an example. If we break down its parameter distribution, the feedforward network layer, which handles core computation and inference, accounts for only about 71 million parameters. Meanwhile, the embedding table, responsible for converting input text into numerical vectors, reaches a staggering 168 million parameters, accounting for 63% of the entire model volume. When the model’s “body” has been sculpted slim by various compression techniques, the embedding table remains an unavoidable bulk.
1. The Dilemma of Extreme Compression: Slim Body, Bulky Vocabulary
In recent years, several key technological advancements in the small model ecosystem have made edge deployment possible, but they have also highlighted the vocabulary issue.
1.1 Breakthrough in Weight Trinarization
Extreme compression techniques proposed by the industry have proven that the main weights of neural networks can be represented using only -1, 0, and +1 (trinarized networks). This technology minimizes the loss of core inference quality while exponentially reducing the model’s main volume and computational load. This means the model’s “computational muscle” can be compressed close to the 1-bit limit.
1.2 Practicality of Small Models
Small models with fewer than one billion or a few hundred million parameters have truly gained practical value for daily tasks. Whether for daily Q&A, text summarization, or local knowledge retrieval, these small models demonstrate satisfactory performance after specific instruction fine-tuning, providing the business support necessary for edge operations.
1.3 Cost Sensitivity in Edge Deployment
When a model is actually squeezed into a phone or laptop, every megabyte of storage and every byte of I/O read speed directly translates into power consumption and response latency. Model size is no longer just an engineering metric; it is a tangible user experience cost.
However, behind these exciting advancements, mainstream quantization algorithms tacitly bypass the embedding layer. Conventional quantization techniques (like compressing 16-bit floats to 4-bit integers) handle feedforward layers with ease but often fall short with embedding tables. Common local inference engines can only compress output layers to a maximum of 6 to 8 bits, frequently accompanied by the risk of precision loss.
Based on industry research estimates, if the aforementioned 270M parameter small model is equipped with a trinarized main network but retains a 16-bit float vocabulary, the final generated file would consist of a “20MB compute body + 335MB vocabulary.” This extreme imbalance sometimes forces technical teams to annotate their memory usage statistics as “excluding the embedding layer” when publishing reports on extremely compressed models, simply to exclude this awkward bulk.
2. Deep Dive: Why is the Embedding Layer So Sticky?
To solve this problem, we must first understand the unique nature of the embedding layer in language model architectures.
Almost all modern language models contain an “embedding table.” At the model’s input, it maps each discrete token to a high-dimensional dense vector; at the model’s output, it usually shares parameters with the input embedding layer, mapping hidden states back to the vocabulary space to output the probability distribution of each token. Although this tied mechanism reduces some parameter redundancy, it forces the embedding layer to simultaneously satisfy two distinct mathematical properties: “feature representation” and “classification output.”
2.1 Conflict in Distribution Characteristics
The weight distribution of feedforward layers typically exhibits an approximate Gaussian distribution, making it highly suitable for symmetric quantization. In contrast, the parameter distribution of embedding tables often exhibits a long-tail or extreme sparsity. Forcing low-bit quantization causes severe distortion of the relative distances within the vector space. At the output end, this distortion is amplified into a shift in the probability distribution, causing the model to generate illogical tokens.
2.2 Inverted Parameter Ratios
For massive models with tens or hundreds of billions of parameters, a vocabulary of tens of thousands of tokens is merely a fraction of the overall parameters. But for small models with hundreds of millions of parameters, maintaining general language understanding usually means the vocabulary size cannot be drastically reduced (often ranging from 30,000 to 250,000). This causes the embedding table parameters to be nearly equal in size to the model itself.
3. The Solution: Embedding Layer Freezing and Optimization Practices
Faced with this dilemma, developers and researchers must break the convention of “default acceptance,” re-evaluate the value of the vocabulary, and adopt targeted optimization strategies.
3.1 Vocabulary Pruning
This is the most direct method to reduce the embedding layer’s volume. General large models contain a vast array of multilingual vocabulary and low-frequency professional terms, which are often useless in specific edge scenarios (like local knowledge assistants or specific device controls). By analyzing the token frequency of business corpora and removing rarely used tokens, the vocabulary size can be significantly reduced.
Here is a simplified pseudo-code example for vocabulary pruning:
def prune_embedding(model, valid_token_ids):# Extract original embedding layer weights [vocab_size, hidden_dim]original_weights = model.get_input_embeddings().weight.data# Keep only the weights of valid tokenspruned_weights = original_weights[valid_token_ids, :]# Rebuild and replace the embedding layer in the modelnew_embedding = nn.Embedding(len(valid_token_ids), original_weights.size(1))new_embedding.weight.data.copy_(pruned_weights)model.set_input_embeddings(new_embedding)# Apply the same logic for shared output layer weightsmodel.tie_weights()return model
3.2 Embedding Layer Freezing
During the fine-tuning phase, you can choose to “freeze” the parameters of the embedding layer so they no longer participate in gradient updates. While this does not directly reduce the static file size of the model, it reduces the memory footprint of optimizer states (such as Adam’s momentum and variance) in memory. During edge execution, utilizing object storage services like Baidu AI Cloud for the cold and hot separation management of model weights allows the frozen vocabulary to be loaded as a read-only memory-mapped file, reducing resident memory pressure and improving startup speed.
3.3 Low-Rank Decomposition
Borrowing the idea from LoRA, the massive embedding matrix can be decomposed into the multiplication of two smaller matrices. For example, a [vocab_size, 4096] matrix can be decomposed into [vocab_size, 256] and [256, 4096]. Although this adds the computational overhead of an extra matrix multiplication, the reduction in parameters is often more valuable on storage-constrained edge devices.
4. Engineering Deployment Recommendations
In practical edge engineering deployment, developers are advised to adopt the following workflow:
- Scenario Definition and Frequency Analysis: Define the languages and domains the model needs to support, and collect corpora from real operating environments for token frequency statistics.
- Structured Pruning: Perform directional pruning on the vocabulary based on the analysis results, synchronously adjusting the dimensions of the output head.
- Mixed Precision Quantization: Apply extreme trinarization or 4-bit quantization to feedforward and attention layers, and attempt 8-bit group quantization on the pruned embedding layer to find the balance between precision and size.
- On-Demand Memory Loading: Utilize the operating system’s memory-mapping technology to split the vocabulary into high-frequency and low-frequency zones. Keep the high-frequency vocabulary resident in memory, and load the low-frequency vocabulary from disk on demand, combining smart scheduling strategies to lower the overall memory peak.
Conclusion
When the main network compression of edge small models approaches physical limits, vocabulary optimization becomes the inevitable battleground for the next “slimming war.” Moving from passively accepting a bulky embedding layer to actively performing vocabulary pruning, low-rank decomposition, and memory management requires developers to approach edge deployment with a more rigorous system engineering perspective. Only by truly “freezing” and slimming down this bloated vocabulary can sub-100MB extreme edge LLMs transition from theory to widespread adoption.
