Vocabulary Freezing: A New Approach to Slimming Small Models for On-Device Deployment

    When a model's parameter count drops to the hundreds of millions or even tens of millions, the embedding vocabulary often fails to shrink proportionally—and can end up dominating the model's parameters, memory footprint, and loading time, especially on edge devices. This article explains what vocabulary freezing actually means (it is more than simply halting weight updates), surveys the main engineering paths for slimming the vocabulary, including parameter sharing, low-rank decomposition, hash encoding, subword pruning, quantization, and distillation, and then lays out a practical workflow from parameter inventory to on-device release. It also offers a three-dimension framework to help you decide whether freezing a vocabulary is the right move and how to balance compression against task accuracy.

    1. The Real Burden of Small Models: Not Just Compute

    When a model’s parameter count drops to the hundred-million or ten-million level, the compute layers, attention layers, and feed-forward layers all shrink accordingly. The embedding vocabulary, however, often does not shrink at the same ratio. The embedding vocabulary is responsible for mapping discrete tokens into continuous vectors, and it usually serves both input encoding and part of output prediction. When the vocabulary holds over a hundred thousand entries and the hidden dimension is only a few hundred, the embedding matrix can account for a very large share of the model’s total parameters.

    Take a common class of small-parameter models as an example: its total parameter count is roughly 268 million, of which only about 71 million actually participate in the feed-forward computation, while the embedding vocabulary accounts for about 168 million—more than sixty percent of the total. This means that even when the compute units are already very lightweight, the weight file can still be significantly bloated by the vocabulary. Many people focus only on how fast the model can run, yet overlook the fact that during loading, resident memory, disk footprint, and cold-start phases, the vocabulary is often the true cost center.

    This problem is amplified further in on-device deployment. Cloud training cares about throughput, latency, and GPU memory, whereas on-device inference cares much more about model file size, resident memory, cold-start loading, cache hit rate, and memory bandwidth. The vocabulary matrix typically consists of a large number of floating-point values. If loaded fully into memory, it consumes not only storage but also slows down startup. Even when some inference implementations use sparse lookup or lazy loading, the vocabulary remains the part of the model structure most prone to bloat.

    Therefore, optimizing a small model cannot look only at whether the “compute-layer parameters” are few enough; it must also examine whether the “data-layer parameters” are under control. The idea of vocabulary freezing is precisely to turn an object that would otherwise easily participate in training, easily grow, and easily change with the corpus, into a relatively stable, reusable, and compressible resource.

    2. What Vocabulary Freezing Means: Not Simply Stopping Updates

    “Freezing” has several meanings in engineering. The most intuitive interpretation is to stop training updates: the embedding table parameters compute no gradients during backpropagation and are not updated by the optimizer. More broadly, vocabulary freezing also includes strategies such as fixing the vocabulary structure, fixing the index mapping, reusing vector representations, and sharing the output projection.

    1. Training-Parameter Freezing

    When a model has already obtained stable word vectors through pretraining on general corpora, fine-tuning can freeze the input embedding table and train only the backbone network. This is common in domain transfer, task fine-tuning, or on-device adaptation. The benefits are fewer trainable parameters, lower GPU memory usage, and improved training stability. When the task data is small, fine-tuning the vocabulary tends to overfit easily, and freezing the embedding table also reduces the impact of noise on the representation space.

    In engineering practice, training-parameter freezing usually means removing the embedding layer from the optimizer or explicitly disabling its gradient updates. Pseudocode is shown below:

    1. # Pseudocode: freezing the embedding table during training
    2. embedding = build_embedding_layer(vocab_size, dim)
    3. for weight in embedding.trainable_weights():
    4. weight.freeze()
    5. for step in training_steps:
    6. tokens = tokenize(batch)
    7. x = embedding.lookup(tokens)
    8. y = backbone(x)
    9. loss = compute_loss(y, labels)
    10. update(backbone_only=True)

    This approach suits scenarios that already have a stable vocabulary and only need to adapt to downstream tasks. It does not reduce the vocabulary’s storage footprint at inference time, but it lowers training cost and makes model updates more controllable.

    2. Representation Freezing

    Some scenarios do not use raw word vectors directly but instead use precomputed static representations, such as vectors derived from statistical co-occurrence, matrix factorization, or offline clustering. At inference time the model only performs lookups and no longer updates these vectors. Freezing representations ensures consistency of online word vectors and avoids drift across different training batches.

    In tasks such as retrieval, recommendation, and semantic matching, word vectors or item vectors are often computed offline and then fixed. The model only performs mapping and computation during online inference and does not participate in vector updates. The key to this approach is ensuring that the offline index and the online model version stay consistent; otherwise, recall quality fluctuations or semantic misalignment will occur.

    3. Structural Freezing

    After a small model goes live, the vocabulary size often should not change frequently. Adding new terms, removing low-frequency words, or adjusting subword segmentation all alter the index space and cause model weights to be misaligned. Freezing the vocabulary structure means fixing the vocabulary size and mapping rules, so that new words can only be extended through lightweight patches, external caches, or rule modules, rather than by directly modifying the core embedding table.

    Structural freezing is especially important for on-device models. Terminal models usually lack a stable, continuous training environment, and once the vocabulary index changes, old model weights may no longer be directly reusable. As a result, engineering practice tends to treat the vocabulary as part of the “model protocol”: once a version is released, it should remain stable.

    4. Inference Freezing

    In on-device inference, the vocabulary is typically read-only. It is not updated by backpropagation, nor is it adjusted online in response to user input. Here, “freezing” is closer to a deployment constraint: the embedding table in the model file must remain stable and support fast mapping, fast reading, and fast release.

    For mobile devices or embedded devices, the memory budget during inference is often very tight. If the vocabulary can be mapped in a read-only manner at startup and released promptly after inference, it reduces the pressure on resident memory. Vocabulary freezing is therefore not only a training strategy but also a deployment strategy.

    It is worth emphasizing that freezing does not equal compression. Even if a floating-point embedding table is not updated, its parameter count still exists. Truly reducing weight size requires further restructuring the frozen vocabulary into a smaller, sparser, and lower-precision representation.

    3. The Main Engineering Paths for Vocabulary Slimming

    1. Parameter Sharing: Reusing Input Embeddings and Output Projection

    Many language models need to map input tokens into vectors and also map vectors back into vocabulary probabilities at the output layer. If the input embedding and output embedding are maintained separately, the parameter count doubles. A common practice is to bind the two, so that the same word vector is used for both input lookup and output scoring. After freezing the shared embedding, the output layer introduces no independent parameters, and the overall model size drops.

    Pseudocode is shown below:

    1. # Pseudocode: shared embedding table
    2. embedding = build_embedding(vocab_size, dim)
    3. input_vec = embedding.lookup(input_ids)
    4. output_logits = dot(hidden_state, transpose(embedding.weights))

    The premise of this approach is that the input representation and the output scoring space are semantically consistent. If the task differences are large, shared embeddings may introduce slight accuracy loss, so validation on evaluation sets is required.

    2. Low-Rank Decomposition: Splitting a Large Matrix into Small Ones

    The vocabulary matrix can usually be approximated as low-rank: many word vectors are not fully independent, and there are similarities in semantics, word frequency, and subword form. Low-rank decomposition splits a large vocabulary matrix into two smaller matrices, expressing word vectors through a combination of basis vectors and coefficients. If the rank is r and the original matrix has dimension V×D, the reconstructed parameters are V×r and r×D. When r is far smaller than D, both parameters and storage drop.

    Pseudocode is shown below:

    1. # Pseudocode: low-rank embedding
    2. base = base_matrix(vocab_size, r)
    3. coef = coef_matrix(r, dim)
    4. embedding = multiply(base, coef)

    Low-rank decomposition suits models with large vocabularies but relatively stable semantic structures. It does not necessarily eliminate the cost of long-tail words entirely, but it can significantly reduce overall parameter redundancy.

    3. Hash Encoding and Composite Vocabularies

    Traditional vocabularies require every word to have an independent index, which causes long-tail and rare words to occupy a lot of space. Hash encoding generates indices from features, character n-grams, and subword fragments, letting multiple words share a vector. If hash collisions are frequent, one can introduce multi-hashing, composite hashing, or a collision-correction table. After freezing a hashed vocabulary, the vectors no longer change with training, and only a small number of shared vectors and collision patches need to be stored, which suits on-device scenarios.

    The key to a hashing scheme is controlling the collision rate. If there are too many collisions, different word meanings are wrongly mixed; if there are too few, it degenerates into an ordinary vocabulary. In practice, high-frequency words are usually kept as independent embeddings, while low-frequency words or rare subwords are delegated to hash buckets.

    4. Subword Pruning and Dynamic Vocabularies

    General-purpose vocabularies contain many low-frequency words, punctuation, code symbols, and multilingual fragments. For vertical tasks, one can perform subword-merge statistics on the training corpus, keep only high-frequency subwords, and map rare words to an unknown token or fall back to a character-level model. A dynamic vocabulary selectively loads based on input scale: common words stay resident in memory, while low-frequency words are supplemented through external mappings. Vocabulary freezing does not require “keeping every word” but rather “keeping the core mapping rules stable.”

    In vertical scenarios, subword pruning is often more effective than freezing alone. For example, if a task involves only a few domain terms and common short words, one can remove a large number of rare symbols and fragments unrelated to that task. This both shrinks the vocabulary and reduces index-lookup overhead at inference time.

    5. Quantization and Sparsification

    Embedding tables usually consist of a large number of floating-point values, and high-precision storage makes them large. Quantization maps floating-point weights to low-bit integers, such as 8-bit, 4-bit, or even more extreme ternary levels. Sparsification keeps important vectors or important dimensions and zeros out the rest, or compresses them through indices. For on-device models, sparse indexing and quantization are often combined to reduce disk footprint and memory-bandwidth pressure.

    Pseudocode is shown below:

    1. # Pseudocode: ternary quantization
    2. scale = calibrate_scale(embedding)
    3. quantized = round(embedding / scale)
    4. quantized = clip(quantized, -1, 1)

    Extreme quantization can cause semantic drift, so it usually needs to be paired with calibration data, error feedback, or fine-tuning of the backbone to compensate. For a large matrix structure like the vocabulary, the gains from quantization are usually obvious, but its impact on low-frequency and rare words must be thoroughly evaluated.

    6. Distillation and Small-Vocabulary Training

    If the goal is to compress the model by shrinking the vocabulary, a larger model can serve as the teacher, letting the smaller student model learn soft targets or similar representations under a restricted vocabulary. The teacher model can provide unknown-word handling, contextual relationships, or output distributions, while the student model only needs to master the high-frequency representations required for the target task. Such a small vocabulary is easier to freeze and more stable.

    The key to distillation is preserving the teacher model’s ranking relationships on critical semantics. Even if the student model’s vocabulary is smaller, it must not suffer severe degradation in confidence distributions, boundary samples, and long-tail expressions on the target task.

    4. The Boundary Between Freezing the Vocabulary and Compression

    Freezing the vocabulary is not a universal solution. It suits scenarios where the vocabulary is already relatively stable, training data is limited, terminal resources are tight, and the model update frequency is low. But if the task requires continuously introducing new words, new domain terminology, or multilingual expansion, over-freezing reduces expressive power. In such cases, the freezing strategy needs to be combined with incremental mechanisms.

    For example, one can adopt a “frozen core vocabulary + external extended vocabulary” architecture: the core embedding table stays read-only, and domain-specific new words are handled through an external cache, rule mapping, or a small adaptation module. Alternatively, one can adopt a “frozen base vectors + lightweight adapter fine-tuning” approach: training only on a small number of adapter layers, avoiding changes to the entire vocabulary.

    When evaluating the effect of freezing, one should not look only at the compression ratio but also at task metrics. Common evaluation dimensions include perplexity, classification accuracy, generation quality, time-to-first-token latency, peak memory, loading time, disk size, and update failure rate. For on-device applications, one should also pay attention to stability on low-memory devices and the cache-reuse rate when frequently switching tasks.

    5. Implementation Workflow: From Parameter Inventory to On-Device Release

    The first step is a parameter inventory. Developers need to clarify the model’s total parameters, compute-layer parameters, embedding-layer parameters, output-layer parameters, vocabulary size, hidden dimension, weight precision, and file size. Many models look like they have few parameters, but once the embedding table is stored in high precision, the size swells noticeably.

    The second step is choosing what to freeze. If the vocabulary quality is stable, freeze the input embedding; if input and output are shared, freeze the shared embedding; if the vocabulary is too large, first distill or prune it, then freeze; if on-device memory is tight, further quantize and sparsify.

    The third step is restructuring the representation. After freezing, the vocabulary still needs to be converted into a more efficient storage format. For example, convert a large matrix into low-rank factors, convert discrete vectors into hash buckets, convert floating-point weights into integer encodings, and prepare a fallback path for low-frequency words.

    The fourth step is inference validation. You need to measure cold start, loading, time-to-first-token latency, peak memory, and memory jitter over long-running periods on the target device. After freezing the vocabulary, the lookup logic should maintain contiguous access as much as possible, avoiding too many random indices that are unfriendly to the cache.

    The fifth step is monitoring and rollback. After the model goes live, record the vocabulary version, weight version, compression strategy, and task metrics. If there is insufficient coverage of new words, abnormal generation, or accuracy degradation, you should be able to quickly roll back to the previous version or patch it through an external extension layer.

    6. A Reusable Framework for Technical Judgment

    When facing the question “should I freeze the vocabulary,” you can use three dimensions of judgment.

    First, is the vocabulary stable? If the task corpus is relatively fixed, the vocabulary can be frozen; if the corpus changes frequently, an extension mechanism should be retained.

    Second, does the bottleneck come from parameter size? If the terminal pain point is a disk that is too large, insufficient memory, or slow loading, then freezing plus compression delivers clear value; if the bottleneck is compute latency, you should prioritize optimizing lookup access, operator scheduling, and memory layout.

    Third, can accuracy be compensated? If task performance drops noticeably after freezing, it can be compensated through backbone fine-tuning, adapter training, distillation, or external rule modules, rather than forcibly loosening the vocabulary.

    7. Conclusion

    As the competition among small models moves into deeper waters, the focus of optimization is expanding from “reducing compute” to “governing parameter structure.” Although the embedding vocabulary does not directly participate in complex inference, it is often the main source of model size, memory, and loading time. Freezing the vocabulary is not simply making parameters stop updating; rather, it transforms the vocabulary from an uncertain factor in the training state into a stable resource that can be shared, decomposed, quantized, and managed. For on-device deployment, the value of this idea lies not in manufacturing concepts, but in turning every megabyte, every memory access, and every segment of loading time into measurable engineering gains.