Vocabulary Freezing: A Key Technique for Lightweighting Small Models
In edge and on-device AI scenarios, the vocabulary—not the compute layers—often dominates both the parameter count and the file size of small language models. This article explains why conventional quantization struggles to compress embedding tables, then introduces "vocabulary freezing" as a governance approach that turns a dynamic, high-precision parameter into a manageable static asset. It surveys practical compression paths—including low-bit and mixed-precision embeddings, offline calibration and error compensation, codebook representation, low-rank factorization, hashing and bucketing, and input/output decoupling—and shows how to govern vocabulary during on-device deployment through model file layering, memory mapping and lazy loading, high-frequency caching, and gray release with rollback. It closes with a multi-dimensional evaluation framework and a step-by-step roadmap so teams can make small models not just runnable, but lighter, more stable, and more efficient.
1. The Real Weight of a Small Model: Vocabulary Is Becoming the Main Cost
In on-device intelligence scenarios, the value of a small model is no longer measured by “having few parameters” but by its ability to run reliably on resource-constrained devices such as phones, PCs, and edge boxes. Yet when you open up many small models, you encounter a counterintuitive pattern: the parts that actually perform feature transformation, feed-forward computation, and inference decisions do not necessarily dominate the parameter count. Instead, the input and output vocabulary structures often account for the majority of the parameters.
Take a small model of roughly 268 million parameters built for end devices as an example. The parts that do the real complex computation—the feed-forward layers, attention projection layers, and so on—may total only around 71 million parameters. The embedding table, which maps tokens to vectors, can reach around 168 million parameters, nearly 63% of the total. In other words, if you only look at how much a model “can compute,” a small model is very light. But if you look at how big the model file is, the vocabulary itself is the main burden.
The vocabulary matters because natural language models do not process text directly. They first split text into tokens, then map each token to a vector. A model typically contains two key structures:
- Input embedding table: maps each token id to a vector. It is usually a matrix of shape
[vocab_size, vector_dim]. - Output projection layer: maps hidden states back into the vocabulary space to predict the probability distribution over the next token. It is usually a matrix of shape
[hidden_dim, vocab_size].
In some model designs, the input embedding table and the output projection layer share the same weight matrix. Even when they do not, both grow linearly with vocabulary size. For large-parameter models, the vocabulary is only a small fraction of the total parameters. But for a small model with only a few hundred million parameters, the vocabulary quickly becomes the dominant structure.
This leads to a key conclusion: Lightweighting a small model cannot focus on compressing the compute layers alone—it must also re-examine the vocabulary.
2. Why Conventional Quantization Does Not Fully Solve the Vocabulary Problem
Quantization is one of the most common model compression techniques. Its core idea is to represent weights with fewer bits—for example, compressing 16-bit floats down to 8-bit, 4-bit, or lower. For the matrix-multiplication-heavy body of a model, quantization usually reduces storage significantly and, on certain hardware, improves compute efficiency.
But when it comes to the vocabulary, the problem is far more complex.
1. The Embedding Table Is a Lookup Table, Not a Regular Matrix
The weights of the model body typically participate in continuous matrix multiplications, so quantization can be accelerated with specialized kernels. The embedding table behaves more like a lookup table: the input is a token id, and the output is the corresponding row vector. During inference, the model does not run one large matrix multiplication across all tokens; instead, it selectively fetches a few rows based on the input tokens.
This creates several issues:
- Although a low-bit embedding table is small to store, each row lookup may require real-time decoding.
- If the vocabulary is very large, the decoding overhead can hurt throughput.
- Support for embedding-table quantization varies across inference engines, which raises the cost of engineering integration.
So an embedding table does not automatically deliver the same benefit as compressing regular weights to 4 bits.
2. The Vocabulary Is Highly Sensitive to Semantic Quality
The embedding table carries the base semantic position of each token. If you compress it too aggressively—for instance, pushing it to extremely low bits—the vector expressiveness of tokens such as near-synonyms, rare words, digits, symbols, and technical terms may degrade.
In large models, this error can be absorbed by subsequent layers. But in small models, the later layers already have limited capacity, so errors are more easily amplified. The following scenarios are especially prone to problems:
- Long-tail word coverage;
- Multilingual or domain-specific vocabularies;
- Code, math, formulas, and structured input;
- User-defined vocabularies;
- Tasks that are sensitive to the output probability distribution.
Therefore, vocabulary compression must be judged not only by size, but also by semantic fidelity.
3. After Compressing a Small Model, the Vocabulary Looks Even Larger
If the model body is compressed to 1-bit, 2-bit, or ternary states while the vocabulary keeps a relatively high precision, the structure of the entire model file changes: the compute layers become tiny, but the vocabulary stays large.
For example, a small model that originally had only a bit over 200 million parameters might, after being compressed to extremely low bits, leave the body portion at just tens of MB. But if the vocabulary keeps a high precision, it can still occupy hundreds of MB. At that point, the vocabulary shifts from “one part of the overhead” to “the main bottleneck.”
This is also why lightweighting a small model requires managing the vocabulary separately.
3. Freezing the Vocabulary: Turning a Dynamic Parameter into a Governable Resource
“Freezing the vocabulary” does not mean simply deleting it. It means separating the vocabulary from dynamic training or frequent updates and treating it as a fixed resource, a static asset, or an offline-compressible object.
Its core idea can be summarized as:
The vocabulary is responsible for semantic mapping, but it does not have to remain an active parameter that is always trainable, always updatable, and always stored at full precision.
Once the vocabulary is frozen, the training stage can reduce the memory and compute overhead of updating the embedding table; the deployment stage can export, compress, and cache the vocabulary separately, and even load it dynamically according to device capabilities.
1. Direct Benefits of Freezing the Vocabulary
Freezing the vocabulary brings several kinds of benefits:
Lower training update cost
The embedding table usually participates in gradient updates. If the vocabulary is large, every backward pass incurs a substantial update cost. Freezing it reduces this cost and lets training resources focus on the backbone network.Easier offline compression
Once frozen, the vocabulary can be separated from the online training process and processed offline with quantization, clustering, codebook construction, sparsification, and similar methods.Support for tiered deployment
The same model can share one frozen vocabulary, and different devices can load a vocabulary resource of different precision according to their memory capacity.Lower runtime uncertainty
Once the vocabulary is fixed, quantization error, caching strategy, and loading method can all be validated in advance, reducing online fluctuations.
2. Boundary Conditions for Freezing the Vocabulary
Freezing the vocabulary is not suitable for every scenario. It fits better when:
- The model is used mainly for inference and is not updated frequently;
- The vocabulary size is already relatively stable;
- The target device is constrained in memory or bandwidth;
- You need to control the cost of on-device deployment;
- The model iterates in a versioned manner after launch.
But if the business needs to add new words frequently, adapt quickly to new domains, or continuously learn from user input, freezing the vocabulary may limit the model’s adaptability. In that case, a more reasonable approach is:
- Freeze the main embedding table;
- Apply incremental updates on a small number of adaptation layers;
- Periodically recalibrate the vocabulary with domain corpora;
- Use low-rank adaptation or incremental codebook expansion for new-domain tokens.
4. Common Engineering Paths for Vocabulary Compression
Once the vocabulary is frozen, you still need to consider how to reduce storage, lower memory-access cost, and preserve model quality as much as possible. The following are several common and composable technical paths.
1. Low-Bit Embedding and Mixed Precision
The most direct approach is to compress the embedding table from high bits to low bits—for example, 16-bit, 8-bit, 4-bit, or lower. To improve stability, you can adopt a mixed-precision strategy:
- Keep higher precision for high-frequency tokens;
- Use lower precision for low-frequency tokens;
- Handle special symbols, digits, and control tokens separately;
- Keep high precision for key domain words.
A simplified pseudocode:
def build_frozen_embedding(embedding_matrix, token_ids, bits=4):high_frequency_ids = get_high_frequency_tokens(token_ids)frozen_table = []for token_id, row in enumerate(embedding_matrix):if token_id in high_frequency_ids:frozen_table.append(keep_high_precision(row))else:frozen_table.append(quantize_row(row, bits=bits))return FrozenEmbedding(frozen_table)
The advantage of this approach is that it is straightforward to implement. The drawback is that you must carefully weigh the compression ratio against quality.
2. Offline Calibration and Error Compensation
After quantizing the vocabulary, you cannot evaluate the result by “compression ratio” alone; you also need to assess error using calibration data. You can use representative text samples to compare the original and compressed embedding tables, for example by measuring:
- Vector cosine similarity;
- Nearest-neighbor token retention rate;
- Change in model perplexity;
- Change in downstream task accuracy;
- Difference in output probability distributions.
If the error is too large, you can apply compensation strategies:
- Keep high precision for key tokens;
- Correct dimensions with large error separately;
- Add a lightweight residual mapping;
- Add a short vector transformation layer after the low-bit embedding;
- Fine-tune the backbone layers with a small amount of calibration data.
The goal of these methods is not to make the vocabulary “absolutely lossless,” but to reduce storage and inference cost further while keeping error within an acceptable range.
3. Codebook Representation
Codebook representation is better suited to large vocabularies. The basic idea is not to store the full vector of each token, but to cluster or quantize the embedding vectors first, then represent each vector as a combination of a set of codewords.
For example, each token vector can be represented as:
token_vector ≈ sum(codebook[i] for i in selected_indices)
Or more simply, each token stores only the index of one center codeword:
compressed_embedding[token] = codebook[token_id]
This splits an embedding table that originally needed to store [vocab_size, vector_dim] into:
- A smaller codebook table;
- A codeword index for each token;
- An optional residual term.
The advantage of codebook representation is a high compression ratio, which suits on-device devices. The drawback is that it requires extra decoding, and the clustering quality affects semantic fidelity.
4. Low-Rank Factorization
If the vocabulary matrix is large but its semantic structure has some low-rank property, you can use low-rank decomposition to reduce storage.
The original embedding table can be understood as:
E ∈ R^(vocab_size × vector_dim)
It can be approximated as:
E ≈ A × B
where:
Ahas shape[vocab_size, low_rank_dim]Bhas shape[low_rank_dim, vector_dim]
The storage requirement then changes from:
vocab_size × vector_dim
to:
vocab_size × low_rank_dim + low_rank_dim × vector_dim
When the low-rank dimension is much smaller than the vector dimension, the storage cost drops significantly. However, low-rank factorization introduces extra matrix multiplications, so you need to weigh the benefit against the compute capability of the inference engine.
5. Hashing and Bucketing
Another compression idea is to reduce the number of vectors stored independently per token. Through hashing or bucketing, multiple tokens can share the same set of parameters.
For example:
hash(token) -> bucket_idembedding[token] = base_embedding[bucket_id] + token_specific_bias
The advantage is that it can significantly reduce the parameter count. The drawback is that it introduces hash collisions, which can affect the expressiveness of rare tokens. So it is better suited as a supplementary technique rather than the sole compression method.
6. Input/Output Decoupling
Many models share parameters between the input embedding and the output projection. Sharing parameters saves some storage but also makes compression and governance more complex, because the same matrix serves both input semantic mapping and output probability mapping.
In some small-model lightweighting scenarios, you can decouple the two:
- Use low-bit or codebook embeddings on the input side;
- Use low-rank projections or grouped output on the output side;
- Keep higher precision on the output layer to avoid distorting the probability distribution;
- Compress the input layer as much as possible, because the input side relies more on lookup and representation.
This decoupling improves the flexibility of compression strategies.
5. Vocabulary Governance in On-Device Deployment
The vocabulary is not only a model-quality issue but also a deployment-engineering issue. Good performance in the cloud does not guarantee that a model runs well on-device. On-device inference usually faces the following constraints:
- Limited memory capacity;
- Limited memory bandwidth;
- File loading time affects first-response latency;
- Model size affects distribution and updates;
- Long-tail tokens may cause unstable latency.
Therefore, vocabulary compression must be designed together with the deployment method.
1. Model File Layering
You can split the model file into several parts:
- Backbone network weights;
- Frozen embedding table;
- Quantization metadata;
- Codebook or center vectors;
- Index table;
- Calibration configuration;
- Version information.
The benefit of layered storage is that different modules can be updated independently. For example, you can update only the vocabulary without updating the backbone, or update only the quantization configuration without retraining the model.
2. Memory Mapping and Lazy Loading
For a large vocabulary, you do not necessarily need to load everything into memory at once. You can use memory mapping or lazy loading so the system reads the relevant rows on demand.
This suits scenarios such as:
- Limited memory but fast disk or flash storage;
- Each request involves only a small number of tokens;
- You need to control peak memory;
- Model versions need to be switched quickly.
However, note that if every request triggers many random reads, tail latency may increase. So you can improve performance by caching high-frequency tokens, batch prefetching, and optimizing locality.
3. Caching High-Frequency Vocabulary Items
Natural language processing exhibits a clear frequency distribution: a small number of tokens cover a large share of input. So you can keep the vectors of high-frequency tokens resident in memory or near the compute unit, and put low-frequency tokens in compressed storage.
A strategy:
- Keep high precision for high-frequency tokens;
- Use low-bit or codebook representation for low-frequency tokens;
- Use shared representation for extremely low-frequency tokens;
- Cache special tokens separately;
- Adjust the cache set dynamically based on business corpora.
This controls memory while keeping low latency for common requests.
4. Gray Release and Rollback
Vocabulary compression can change model outputs, so you need a complete release process:
- Evaluate the quality difference before and after compression offline;
- Roll out to a small traffic segment;
- Compare core metrics;
- Observe performance on abnormal inputs;
- Keep the original vocabulary version;
- Support fast rollback.
Without a rollback mechanism, the risk of vocabulary compression increases significantly.
6. How to Evaluate Vocabulary Freezing and Compression Solutions
Vocabulary governance should not be judged only by “did the file get smaller.” You need to build a multi-dimensional evaluation system.
1. Compression Ratio
Basic metrics include:
- Original model file size;
- Compressed model file size;
- Original embedding table size;
- Compressed embedding table size;
- Proportion of the vocabulary in the overall model;
- Change in peak memory.
A key observation: if the vocabulary accounts for more than half of the total model size, you should prioritize vocabulary-specific governance.
2. Quality Metrics
Common quality metrics include:
- Perplexity;
- Downstream task accuracy;
- Generation quality;
- Semantic similarity;
- Nearest-neighbor retention rate;
- Rare-token performance;
- Long-text stability.
For end-user products, you should also pay extra attention to the real user input distribution, rather than relying only on public test sets.
3. Performance Metrics
On-device deployment also requires attention to:
- First-token latency;
- Average inference latency;
- P95 or P99 latency;
- Peak memory;
- Memory bandwidth usage;
- Model loading time;
- Cache hit rate;
- Energy consumption changes.
If vocabulary compression reduces only storage but significantly increases decoding time, it may not suit certain real-time scenarios.
4. Stability Metrics
Vocabulary compression may also affect system stability, so you should observe:
- Whether abnormal tokens cause decoding errors;
- Whether empty vocabularies or oversized inputs trigger exceptions;
- Whether the caching strategy causes jitter;
- Whether low-bit quantization causes numerical anomalies;
- Whether the output distribution changes abruptly after a model update.
7. Recommended Implementation Roadmap
For teams preparing to govern the vocabulary of small models, the following engineering roadmap is a useful reference.
Step 1: Measure First, Then Optimize
Do not pursue extreme compression from the start. First measure:
- Vocabulary size;
- Embedding table parameter count;
- Proportion of the embedding table in total parameters;
- Proportion of the embedding table in the model file;
- Embedding table read frequency during inference;
- The current source of the memory bottleneck.
If the vocabulary is only a small fraction, you may prioritize optimizing the backbone network; if it is a large fraction, you must govern it specifically.
Step 2: Establish a Quality Baseline
Before compressing, record the model’s performance on typical tasks, including:
- Common question answering;
- Text generation;
- Classification tasks;
- Information extraction;
- Code or structured output;
- Multilingual input;
- Special symbols and digit handling.
Without a baseline, you cannot tell whether compression has degraded quality.
Step 3: Choose a Compression Strategy
You can choose different strategies based on the target device:
- For stable quality: prioritize 8-bit and 4-bit mixed quantization;
- For extreme size: consider codebook representation, low-bit compression, or structured compression;
- For low latency: reduce decoding complexity and cache the high-frequency vocabulary;
- For fast deployment: use a frozen vocabulary plus offline quantization;
- For long-term evolution: keep an incremental vocabulary update mechanism.
Step 4: Offline Calibration
Use representative corpora for calibration and compare the differences before and after compression. The calibration set should cover real user input as much as possible, rather than relying only on training data.
The calibration process can include:
- Vector error evaluation;
- Probability distribution evaluation;
- Task metric evaluation;
- Long-tail token evaluation;
- Boundary-input stress testing.
Step 5: Small-Scale Gray Release
Vocabulary compression is a model-level change and should not be rolled out to full traffic directly. It is recommended to validate in a small-traffic environment first, observing:
- User feedback;
- Task success rate;
- Latency changes;
- Peak memory;
- Crash rate;
- Abnormal logs.
Expand the scope only after confirming stability.
Step 6: Continuous Monitoring
After launch, you need to continuously monitor model performance and resource consumption. You can combine general cloud capabilities for governance, for example:
- Use object storage to distribute model files;
- Use container platforms to deploy inference services;
- Use monitoring and alerting to observe latency and memory;
- Use log services to record abnormal inputs;
- Use version management to keep rollback-ready models.
This reduces the online risk introduced by vocabulary compression.
8. Key Takeaways
Small-model lightweighting is moving from “reducing parameters” toward “fine-grained governance of parameter structure.” People are used to focusing on the number of layers, attention heads, and feed-forward layer size. But in many on-device models, what really drives size and deployment cost may not be the compute layers—it may be the vocabulary.
The core tensions of vocabulary compression can be summarized in three points:
The vocabulary occupies a large number of parameters
A small model’s compute layers are limited, but the vocabulary grows with language coverage.Conventional quantization struggles to fully compress the vocabulary
The embedding table is a lookup table, not a regular matrix, so quantization requires extra decoding and quality validation.Freezing the vocabulary provides a more controllable governance approach
Through freezing, offline compression, codebook representation, low-rank representation, mixed precision, and caching strategies, you can find a more reasonable balance among quality, size, and latency.
Therefore, vocabulary governance for small models should not be a simple matter of “making the matrix smaller.” It should be a systems-engineering effort: it must consider both training efficiency and inference performance; it must control model size while preserving semantic quality; and it must support current deployment while leaving room for future evolution.
For developers and enterprise users, the most important engineering idea is:
Turn the vocabulary from a “passive large matrix” into a “freezable, quantizable, distributable model resource.”
As long as the vocabulary can be measured, compressed, deployed, and monitored independently, small models can truly move from “runnable” to “light to run, stable to run, and cheap to run.”
