Freezing the Vocabulary: A Key Step in Slimming Down On-Device Small Models

    On-device small models are now capable enough for everyday tasks like text classification, information extraction, simple dialogue, and code completion, but running them locally turns every megabyte of size and every byte of read speed into a real cost. In genuinely small models, the vocabulary (the embedding table) is often the single largest component—sometimes more than half of all parameters—yet it tends to be overlooked while attention and feed-forward layers get the spotlight. This article explains why the vocabulary is so large (a simple V × d multiplication), why tied embeddings couple the input vocabulary with the output layer, and walks through four mature, composable engineering paths to slim it down: training-time freezing, quantization, pruning, and low-rank factorization. It closes with practical advice on measuring before acting, evaluating accuracy loss layer by layer, and automating a compress–evaluate–regress loop.

    1. On-Device Deployment Makes Every Byte Count

    Over the past couple of years, sub-billion-parameter small models have improved dramatically. The lightweight model families from mainstream cloud providers, small open-source models, and the many on-device-tuned variants now available can handle everyday tasks like text classification, information extraction, simple dialogue, and code completion reliably. At the same time, the demand to actually run these models locally on phones, laptops, and smart devices is growing fast. On-device inference means lower latency, better privacy, and availability without a network connection.

    But the rules change the moment you move to the edge. In the cloud, a GPU has tens of gigabytes of memory, so using an extra few dozen megabytes doesn’t matter. On a device, the model has to live in memory or flash; a cold start has to read the weights from storage into memory, and every read and every megabyte maps directly to battery life, heat, and startup speed. In other words, every megabyte of model size and every byte of read speed becomes real money.

    Under these constraints, engineering teams usually zero in on the Transformer backbone—attention layers, feed-forward layers, and the depth of the stack. But there is a fact that is easy to overlook: in a genuinely small model, the vocabulary (the embedding table) is often the single largest component, sometimes accounting for more than half of all parameters.

    2. Why the Vocabulary Is So Big: A Simple Multiplication

    The first step of a language model is to map discrete tokens to continuous vectors, and this relies on an embedding table. It assigns a learnable vector of length d (the hidden dimension) to each token in the vocabulary. So the vocabulary’s parameter count is a simple multiplication:

    1. Vocabulary params = vocabulary size V × hidden dimension d
    2. Vocabulary size = V × d × bytes per parameter

    Plug in some typical numbers: V = 32000, d = 512, stored in half precision (2 bytes), and the vocabulary is roughly:

    1. 32000 × 512 × 2 ≈ 31.25 MB

    For a large cloud model, this is negligible. But for a small model whose backbone has only about 100 million parameters, the per-layer parameter count of a single attention and feed-forward block scales with d²; stack a dozen or so layers and the backbone stays modest, while this table—thanks to the V × d product—easily eats up a large share. When the vocabulary grows to 48000, 64000, or more, or when the hidden dimension is high, the vocabulary’s share can easily climb to 50%–60%—which is exactly why the vocabulary ends up carrying much of a small model’s weight.

    3. The Overlooked Coupling: Input Vocabulary and Output Layer Usually Share Parameters

    It is worth noting that almost all language models use a technique called tied embeddings: the embedding table at the input, which looks up a vector for each token, shares the same parameters with the layer at the output that projects the hidden state back into a distribution over the vocabulary (usually called the language model head, or LM head).

    This is mathematically sound: the input’s “token → vector” mapping and the output’s “vector → token scores” mapping are transposes of each other, so sharing parameters both reduces the parameter count and often improves training. But it also leads to a conclusion that is easy to overlook:

    • Once you use tied embeddings, the vocabulary parameters get pulled from both the input and output directions and updated repeatedly during training, which makes it hard to compress or freeze them on their own;
    • Once you want to touch the vocabulary for another purpose (such as pruning or quantization), you first have to untangle this shared parameter’s dual role in the storage and compute pipeline.

    So “freezing the vocabulary” is not just a slogan. It requires first acknowledging that the vocabulary is both large and coupled with the output layer, and then designing a targeted optimization plan.

    4. Four Engineering Paths to Slimming Down the Vocabulary

    Below, from the angles of “reducing storage size” and “reducing training overhead,” are four mature and composable approaches. They all follow widely accepted industry practices and don’t depend on any specific product.

    1. Training-Time Freezing: No Updates, No Optimizer Overhead

    The most direct way to honor “freeze it” is to freeze the vocabulary parameters during fine-tuning or continued training: train only the backbone and leave the vocabulary vectors untouched. This brings three benefits:

    • Optimizer states (such as first- and second-order momentum) typically scale with the parameter count and take up memory several times over, so freezing the vocabulary saves that GPU/memory usage;
    • Vocabulary vectors are sensitive to perturbations in high-dimensional space, so keeping them fixed makes fine-tuning more stable and avoids overfitting on small datasets;
    • Once frozen, the vocabulary becomes a read-only asset that can be quantized, compressed, and packaged offline independently, without getting entangled with the backbone.

    The tradeoff to weigh: if a downstream task introduces new domain vocabulary, pure freezing may limit adaptation. In practice, people often use a compromise of “briefly unfreezing to align, then freezing again.”

    2. Vocabulary Quantization: Expressing the Same Vector in Fewer Bits

    Quantization doesn’t change the vocabulary size; it only reduces the bytes per parameter. Compress the vocabulary from half precision (16-bit) to 8-bit and the size is halved; compress it to 4-bit and, in theory, it drops to a quarter of the original. Since the vocabulary is a pure lookup structure that doesn’t take part in complex computation, quantizing it is often “gentler” than quantizing attention or feed-forward layers, with relatively controllable accuracy loss. A common approach is to compute scale factors and zero points per row (each token vector) or per group, balancing compression ratio against reconstruction accuracy.

    3. Vocabulary Pruning: Keeping Only the Tokens That Are Actually Used

    The token distribution of on-device tasks is usually far more concentrated than that of a general corpus. If the model targets a fixed domain (say, customer-service Q&A or form extraction), many long-tail tokens in the vocabulary almost never fire. Pruning works by first tallying token frequency in the real corpus, cutting out low-frequency rows, and then rebuilding the vocabulary and the corresponding output layer dimensions. This shrinks both the input lookup and the output projection at once. The risk lies in handling out-of-vocabulary words, so you need a matching fallback mechanism (such as falling back to subword or byte-level tokenization) to avoid running into inputs that can’t be encoded after pruning.

    4. Low-Rank Factorization: Building a Large Vocabulary from Small Matrices

    Low-rank factorization (embedding factorization) doesn’t reduce the number of tokens; it decomposes a large V × d matrix into the product of two smaller matrices: V × r and r × d, where r is a rank far smaller than both V and d. The parameter count drops from V × d to r × (V + d). Take V=32000, d=512, r=128:

    1. Original: 32000 × 512 = 16,384,000
    2. Factored: 32000 × 128 + 128 × 512 ≈ 4,161,536

    The parameter count drops to about a quarter, and the pressure on on-device reads and resident memory is greatly eased. The cost is one extra r × d matrix multiply during the lookup, so you need to measure to weigh the compression gains against inference overhead. The pseudocode below (framework-agnostic) shows this structure:

    1. # Low-rank factored embedding lookup
    2. token_embed = embed_small[token_id] # shape r, look up the small table first
    3. vector = token_embed @ proj_up # then project up to d dimensions
    4. # The output side is the same: hidden @ proj_down gives r dimensions,
    5. # then take the inner product with embed_small to reconstruct the vocabulary distribution
    6. logits = (hidden @ proj_down) @ embed_small.T

    5. Practical Recommendations and Tradeoffs

    These paths aren’t mutually exclusive; in engineering they are usually combined: first lay down the vocabulary’s “size foundation” with low-rank factorization or pruning, then layer on quantization to compress storage, and finally stabilize accuracy and save training resources with training-time freezing. When putting this into practice, three principles are worth keeping in mind:

    • Measure first, then act. Use tools to tally the vocabulary’s share and the token frequency distribution, and compare size, cold-start latency, and task metrics before and after compression, to avoid optimizing blindly.
    • Look at accuracy loss layer by layer. Vocabulary quantization, pruning, and factorization each affect different stages and should be evaluated one at a time, keeping a small number of high-precision tokens if necessary.
    • Automate the evaluation. Model slimming touches multiple stages—storage, loading, memory, and inference—so you can use generic object storage on cloud platforms for version management, and monitoring and alerting to track online latency and resource usage, forming a “compress–evaluate–regress” loop.

    6. Conclusion

    Competition among small models is no longer just about “whether there are enough parameters to be smart,” but about “whether it can run, run fast, and run cheap once it’s on a device.” While the whole industry focuses on the backbone architecture, that quietly bulky vocabulary is precisely the most worthwhile thing to reconsider. Freezing it, compressing it, and restructuring it is not just a technical slogan—it is a practical engineering path that improves size, load speed, and training efficiency at once. As on-device AI rolls out across the board, this may well be the “last mile” for small models on their way to real devices.