Optimizing Small Model Size: Vocabulary Freezing for Efficient On-Device Deployment

    Vocabulary matrices can account for a surprisingly large share of a small language model’s parameters and memory footprint. This article explains how freezing embeddings during fine-tuning, combined with static quantization, can reduce training overhead and improve storage and memory efficiency for edge deployment. It also covers weight tying, implementation considerations, and future opportunities such as vocabulary pruning.

    1. Small Models and the Strict Constraints of On-Device Deployment

    The development of large language models has increasingly split into two directions. On one side, models with hundreds of billions of parameters continue to push the limits of general-purpose capabilities. On the other, models with fewer than one billion parameters are already sufficient for many everyday tasks. In applications such as text summarization, information extraction, and question answering, these small models offer an excellent balance between capability and cost.

    As small models become more capable, organizations are beginning to run them independently on smartphones, laptops, and edge computing devices. However, the computing environment changes significantly when a model moves from the cloud to the device.

    Cloud deployments typically focus on GPU capacity and cluster-level concurrency. On-device deployments are much more sensitive to every megabyte of model size and every byte that must be read from memory. Device memory is limited, and memory bandwidth often becomes the primary bottleneck during inference.

    Each forward pass requires the system to read a large number of model parameters from memory. If the model is too large, it not only consumes memory that would otherwise be available to other applications, but also introduces substantial I/O overhead and higher inference latency. In this context, model size and memory access speed directly affect both hardware costs and user experience.

    2. Vocabulary Size: The Hidden Source of Model Weight

    When optimizing models for on-device deployment, developers commonly use techniques such as quantization and knowledge distillation. However, one important component is often left largely untouched: the vocabulary.

    Almost all modern language models contain an embedding table. Because neural networks cannot process raw text directly, a tokenizer first splits text into tokens. Each token is then mapped to a dense vector with a fixed dimension. This mapping table is the embedding table.

    Its size is generally determined by the product of the vocabulary size, or V, and the hidden dimension.

    Consider a small model with one billion parameters, a hidden dimension of 2,048, and a vocabulary of 32,000 tokens. The embedding table alone contains approximately 65.5 million parameters. When stored in half precision, or FP16, these parameters require roughly 130 MB of storage.

    More importantly, in many mainstream architectures, the input embedding table shares its parameters with the output layer that converts hidden states into probability distributions over the vocabulary. This technique is commonly known as weight tying.

    The same large matrix is therefore used in both directions:

    • The input side maps tokens to vectors.
    • The output side maps hidden states to vocabulary probabilities.

    When the total parameter count is fixed, the number of Transformer decoder layers is often reduced to control the overall model size. As a result, the embedding table and its tied output layer can represent a surprisingly large proportion of the model.

    In highly compact small models, the vocabulary-related parameters may account for more than 60% of the total model size. Yet conventional fine-tuning and compression workflows tend to focus on the attention mechanism and feed-forward networks, leaving this large matrix unchanged.

    3. Freezing the Vocabulary to Reduce Compute and Storage Costs

    Freezing the vocabulary is an effective way to address the excessive size of embedding parameters. This does not simply mean deleting parameters. Instead, it applies targeted optimization based on the characteristics of the vocabulary matrix.

    1. Stable foundational semantics

      The vectors in the vocabulary represent basic semantic features of language. After pretraining, these foundational mappings are generally relatively stable. When adapting a small model to a specific domain or on-device task, fine-tuning primarily needs to improve logical reasoning and instruction following rather than rebuild the meaning of basic vocabulary items. As a result, freezing the vocabulary does not necessarily cause a significant decline in task performance.

    2. Lower backpropagation overhead

      If the vocabulary remains trainable during fine-tuning, backpropagation must calculate and store gradients for the large embedding matrix. This can substantially increase memory consumption. Freezing the layer eliminates the need to propagate gradients through it, reducing memory usage and accelerating training.

    3. Decoupled optimization for inference and storage

      During on-device inference, a frozen vocabulary does not need to be updated dynamically. Its parameters can therefore be converted to lower-precision formats, such as INT8 or even INT4, without introducing errors related to ongoing gradient updates. Because the weights are stable, the impact of quantization error on overall model accuracy can also be controlled.

    4. Engineering Practice: Combining Vocabulary Freezing with Quantization

    In practice, freezing the vocabulary is relatively straightforward. In common deep learning frameworks, it can be implemented by changing whether gradients are calculated for the relevant parameters.

    The following simplified example shows how to freeze an embedding layer and its tied output layer:

    1. import torch
    2. import torch.nn as nn
    3. class SmallLanguageModel(nn.Module):
    4. def __init__(self, vocab_size, hidden_dim):
    5. super().__init__()
    6. # Embedding layer
    7. self.embedding = nn.Embedding(vocab_size, hidden_dim)
    8. # Transformer body (simplified)
    9. self.transformer = nn.TransformerEncoder(...)
    10. # Output layer (typically tied to the embedding layer)
    11. self.lm_head = nn.Linear(hidden_dim, vocab_size, bias=False)
    12. # Weight tying
    13. self.lm_head.weight = self.embedding.weight
    14. def freeze_embeddings(self):
    15. """Freeze the vocabulary and its tied output layer."""
    16. # Disable gradient computation
    17. for param in self.embedding.parameters():
    18. param.requires_grad = False
    19. # Because the weights are tied, the lm_head weights are frozen as well
    20. print(f"Vocabulary frozen. Trainable parameters: {sum(p.numel() for p in self.parameters() if p.requires_grad)}")
    21. # Initialize the model and freeze the embeddings
    22. model = SmallLanguageModel(vocab_size=32000, hidden_dim=2048)
    23. model.freeze_embeddings()

    Before deployment, this freezing strategy can be combined with aggressive static quantization for the vocabulary parameters. For example, the vocabulary weights can be quantized to 8-bit integers.

    Although this may introduce a small amount of accuracy loss, the benefits can be substantial when the vocabulary accounts for half or more of the model’s total size. Quantization can reduce storage requirements and decrease the amount of data that must be read from memory during inference, improving both memory efficiency and access performance.

    5. Future Directions for Small On-Device Models

    Bringing small language models to edge devices is a system-level engineering effort. It requires optimization across multiple dimensions, including model architecture, parameter storage, and the inference engine.

    For a long time, the vocabulary has been an overlooked source of model size. Freezing and quantizing vocabulary parameters are likely to become important steps in optimizing small models for on-device deployment.

    Beyond freezing and quantization, vocabulary pruning is another promising direction. A model designed for a specific on-device application may not need to recognize every token in a vocabulary containing tens of thousands of entries. Removing long-tail, low-frequency tokens and building a task-specific vocabulary could reduce the size of the embedding table at its source.

    Combined with techniques such as KV cache optimization and operator fusion, these methods can help small models run more lightly and efficiently on edge devices without sacrificing their core capabilities. This makes it increasingly practical to integrate AI capabilities seamlessly into everyday devices.