Freezing the Embedding Layer: Addressing Oversized Vocabularies in Small Models

    Edge deployment of small language models often faces a structural imbalance where the embedding table consumes a disproportionate share of the file size and memory. While quantization aggressively shrinks the compute layers, vocabulary tables are typically left at high precision, sometimes accounting for over 60% of a model's total parameters. This article explores why embedding tables resist standard compression techniques and evaluates freezing the embedding layer as a practical compromise. It further outlines comprehensive strategies—including group quantization, codebook compression, vocabulary pruning, and on-demand loading—to systematically reduce vocabulary volume and optimize edge inference.

    In edge model deployment, a commonly overlooked fact is that parameter count does not equal file size, nor do compute parameters equate to memory footprint. After ultra-low-bit quantization, a small model’s primary compute body can become extremely compact. However, the embedding table corresponding to the vocabulary is often preserved at higher precision, ultimately becoming the “heavyweight” in the file. When a model has only a few hundred million parameters, it is not uncommon for the embedding table to account for 60% of the volume. Addressing this contradiction, techniques like freezing, compressing, and on-demand loading of the vocabulary are evolving from niche tricks into systematic engineering challenges.

    1. The Issue is Structural Imbalance, Not Just “Model Too Big”

    Language models typically include an embedding table that maps discrete tokens to continuous vectors; many models also share parameters between the output layer and the embedding table. For large models with tens of billions of parameters, the embedding table is merely a fraction. But for small models with hundreds of millions of parameters, it can approach the size of the model itself.

    Take a small model with roughly 270 million parameters as an example. In public breakdowns, the feed-forward layers responsible for primary computation might only contain about 70 million parameters, while the embedding table could reach 168 million, accounting for about 63%. This means that when discussing “small model slimming,” if we only compress the attention and feed-forward layers while leaving the embedding table at 16-bit precision, the final file structure will suffer from a pronounced imbalance.

    Crucially, mainstream quantization methods usually prioritize linear layer weights, often bypassing the embedding layer or keeping it at higher precision. Ultra-low-bit weight techniques can compress the compute body to nearly 1-bit, but the embedding table might remain at 16-bit; common local inference engines are also relatively conservative regarding output layer compression. The result is that the body gets thinner and thinner, while the vocabulary becomes the largest part of the file. Some technical reports even use an “excluding embedding layer” metric when calculating memory footprint, which highlights that vocabulary volume has become a variable that cannot be ignored.

    Therefore, the problem is not simply “too many model parameters,” but a structural imbalance: after the compute body is compressed, the storage, read, and output projection costs of the embedding table are magnified. In edge deployment, every megabyte, every random table lookup, and every cold-start page load translates into real latency and memory peaks.

    2. Why Vocabularies Are Hard to Compress: Not an Ordinary Matrix

    The embedding table may appear to be just a 2D matrix, but its compression difficulty is higher than standard linear layers for four main reasons.

    First, table lookups are sparse accesses. A single forward pass only reads the rows corresponding to a few tokens, but token distribution during inference is highly long-tailed. Access is concentrated on high-frequency words, while low-frequency words appear occasionally. Uniform low-bit quantization may amplify errors for low-frequency words, while grouping by frequency requires extra indexing and dequantization logic.

    Second, the embedding table serves both input representation and output projection. If parameters are shared, compressing the embedding table affects not only input vectors but also the output logits distribution. The output layer is more sensitive to calibration; low-bit errors may degrade generation quality or shift the probability distribution.

    Third, multi-language and domain vocabularies cause long-tail swelling. To cover multiple languages, code, symbols, and domain terminology, vocabularies are often large. Pruning the vocabulary significantly reduces volume but introduces out-of-vocabulary (OOV) degradation, subword segmentation changes, and a decline in multilingual capabilities.

    Fourth, random lookups are unfriendly to memory bandwidth and cache. On edge devices, the embedding table may not fully reside in high-speed cache, and on-demand loading or paged reading introduces cold-start latency. The higher the compression rate, the more dequantization computation is needed; the lower the compression rate, the larger the file. This is a triangular trade-off among storage, compute, and latency.

    3. Freezing the Vocabulary: A Discussable Compromise

    “Freezing the vocabulary” does not mean deleting it; rather, it means stopping the update of embedding table parameters during the training or fine-tuning phase, training only the compute body or a few lightweight adapter modules. If the output layer shares parameters with the embedding, the shared table also remains frozen; if they are decoupled, separate strategies can be formulated.

    Freezing the vocabulary offers three direct benefits. First, it reduces trainable parameters, lowering fine-tuning VRAM and optimizer state overhead. Second, it keeps token mapping stable, facilitating subsequent codebook quantization, group quantization, and cache layout. Third, the edge side can fix vocabulary shards and index structures, reducing the full replacement cost during version upgrades.

    However, freezing is not a free lunch. If the target domain differs significantly from the original vocabulary distribution, freezing the embedding limits adaptation capabilities to new domains. If the compute body capacity does not match the fixed vocabulary, the model may shift the pressure to the feed-forward layers, causing training instability or slower convergence. Therefore, freezing the vocabulary usually requires complementary methods: lightweight adapter layers, low-rank corrections, domain vocabulary expansion, output layer calibration, and using distillation to maintain the original model’s output distribution.

    A common engineering route is: first freeze the embedding and output projection, and train the compute body and adapters; then apply group quantization or codebook compression to the vocabulary; finally, use a small calibration dataset to check perplexity, downstream tasks, and output calibration. Pseudocode is as follows:

    1. # Pseudocode: Freeze embedding and shared output projection, only train backbone and lightweight adapters
    2. for p in embedding.parameters():
    3. p.requires_grad = False
    4. if output_projection_is_shared:
    5. for p in output_projection.parameters():
    6. p.requires_grad = False
    7. for p in backbone.parameters():
    8. p.requires_grad = True
    9. for p in adapter.parameters():
    10. p.requires_grad = True
    11. # After training, apply group quantization/codebook compression to the frozen vocabulary

    The freezing strategy must also distinguish between “full freezing” and “partial freezing.” Full freezing suits scenarios with stable vocabularies and closely related domains; partial freezing can retain the trainability of high-frequency words or domain-critical tokens while freezing the rest. For edge deployment, partial freezing is more flexible, but the indexing and update logic is more complex.

    4. Technical Routes for Compressing Vocabularies

    Freezing only controls training dynamics; actually reducing volume relies on compression and loading strategies. Common routes can be used in combination.

    1. Group Quantization and Mixed Precision: Group by word frequency, language, or domain. Keep high-frequency words at higher precision, and use 4-bit, 2-bit, or even codebook indexes for low-frequency words. This balances volume and long-tail quality.
    2. Codebook/Vector Quantization: Learn a small codebook for embedding vectors and store codebook indexes instead of full vectors. Dequantize after lookup. The advantage is a high compression ratio, suitable for devices with limited memory bandwidth; the disadvantage is that dequantization computation and random access cache locality need optimization.
    3. Low-Rank Decomposition: Approximate the embedding table using low-rank matrices to reduce storage. High-frequency words and critical tokens may require extra residuals or high-precision protection; otherwise, semantic details are easily lost.
    4. Vocabulary Pruning and Merging: Prune low-frequency tokens based on corpus frequency, merge approximate subwords, or re-estimate the vocabulary for the target language/domain. Pruning is the most direct method but affects multilingual, code, and rare terminology; it requires distillation and calibration set evaluation.
    5. Shared Embedding and Output Projection: Sharing saves parameters, but compression causes input and output to constrain each other. If decoupled, it adds parameters but facilitates separate quantization; if shared, output calibration must be prioritized.
    6. On-Demand Loading and Block Caching: Split the vocabulary into multiple shards, prefetch hot shards by token frequency at runtime, and use memory mapping or on-demand reading for cold shards. Combined with an LRU hot word cache, it can reduce the resident memory peak.

    Pseudocode is as follows:

    1. # Pseudocode: Group quantization by word frequency + hot word cache
    2. groups = split_vocab_by_frequency(vocab)
    3. for group in groups:
    4. if group.is_hot:
    5. store(group.vectors, precision="higher")
    6. else:
    7. store_with_codebook(group.vectors, bits=4) # Use codebook index for low-frequency groups
    8. # Runtime: Hot shards resident, cold shards loaded on demand
    9. hot_cache = LRUCache(capacity=hot_capacity)
    10. for token_id in token_ids:
    11. if token_id in hot_cache:
    12. vec = hot_cache.get(token_id)
    13. else:
    14. vec = load_shard_and_dequantize(token_id)
    15. hot_cache.put(token_id, vec)

    The output layer also requires engineering processing. If the output projection is large, logits can be computed in blocks to avoid materializing the full output matrix at once. For edge generation tasks, candidate set pruning, hierarchical softmax, or approximate output strategies can be combined, but these methods require re-evaluating probability calibration.

    5. Evaluation Cannot Rely Solely on File Size

    Vocabulary compression evaluation should cover at least five categories of metrics:

    • Volume metrics: Total model file size, embedding table ratio, number of shards, and bytes loaded during cold start.
    • Memory metrics: Resident memory peak, hot cache hit rate, output layer peak memory.
    • Latency metrics: First token latency, per-token decoding latency, random lookup latency, dequantization overhead.
    • Quality metrics: Perplexity, downstream task accuracy, multilingual and rare word performance, long-tail token generation quality.
    • Calibration metrics: Output probability distribution shift, confidence calibration, proportion of anomalous tokens after low-bit quantization.

    It is recommended to adopt A/B comparison: keep the compute body compression strategy unchanged, only alter vocabulary precision, grouping strategy, and loading method, and observe the marginal changes in quality and latency. Special attention should be paid to situations where “average metrics look good, but low-frequency words and domain terminology degrade significantly,” because edge user inputs are often long-tailed.

    6. Deployment Suggestions: Treat the Vocabulary as a First-Class Citizen

    Small model edge deployment should no longer treat the vocabulary as a default, static accessory. A more reasonable approach is to incorporate it into the overall compression design:

    First, perform a volume breakdown to clarify the proportion of the compute body, embedding table, output projection, and runtime buffers, avoiding the imbalance of “only compressing the body, not the vocabulary.”

    Second, prioritize trying frozen embeddings with lightweight adapters to verify whether the target domain truly requires vocabulary updates; if needed, consider partial unfreezing or domain expansion.

    Third, adopt a combination of group quantization and codebook quantization—high-frequency words retain precision, low-frequency words retain volume; simultaneously use hot word caching and shard loading to control memory peaks.

    Fourth, vocabulary pruning must be paired with distillation and calibration; you cannot just look at the file reduction ratio. Multilingual and code scenarios require dedicated evaluation sets.

    Fifth, establish versioned vocabulary shards, canary releases, and monitoring alert mechanisms between cloud training and edge distribution to ensure vocabulary structure changes do not break edge caching and loading logic. For general cloud capabilities, you can use object storage, model distribution, logging, and monitoring to manage versions and canary releases, but specific APIs and billing should follow actual platform specifications.

    Conclusion

    The vocabulary eating up 60% of a small model’s weight is not an exaggerated headline, but a true reflection of the structural imbalance in edge model volumes. Freezing the vocabulary provides a compromise that stabilizes mapping and reduces training and deployment complexity; codebook quantization, vocabulary pruning, and on-demand loading are responsible for actually reducing the volume. The final solution will not consist of a single trick, but a combined engineering effort of training strategies, quantization formats, cache layouts, and evaluation systems. By treating the small model vocabulary as a first-class citizen, it is possible to make edge inference both compact and stable under limited storage and bandwidth.