Embedding Layer Quantization: Addressing 60% Parameters in Small Models
This article explores the trade-offs of various embedding layer optimization techniques, including quantization, dimensionality reduction, token sharing, and streaming loading. It focuses on how to choose the right strategy for your specific model and task, emphasizing that all approaches require validation against actual task metrics and do not guarantee universal performance gains.
This article discusses the trade-offs of embedding layer quantization, dimensionality reduction, sharing, and streaming loading. The focus is on determining which approach is suitable for your specific model and task. The ideas presented require validation using actual task metrics and do not constitute a universal performance promise.
Why the Embedding Table Accounts for 60% of Parameters
In a language model with approximately 268 million parameters, the embedding table contains about 168 million parameters, accounting for roughly 63% of the total. Excluding the embedding table, the remaining layer-by-layer computation parameters total about 100 million, of which the feed-forward network accounts for about 71 million, with the rest including attention projections and normalization layers. In other words, the part of the model that actually participates in layer-by-layer computations only accounts for about one-third.
This distribution has a significant impact on edge devices. During inference, the embedding layer simply performs a lookup, mapping each token ID to a vector. It does almost no feature extraction but consumes a large amount of storage and reads the corresponding data during every inference. The smaller the model, the higher this proportion.
After Main Body Compression, the Embedding Table Becomes the Main Burden
Ternary network weights only take three values: -1, 0, and +1. The information content of these three values is about 1.58 bits, and in practice, they are often encoded using 2 bits or a more compact packaging method. The bit-width of ternary weights lies between 1 and 2 bits, often referred to as low-bit weights.
Assuming that the 100 million parameters outside the embedding layer are estimated at 1.58 bits, the computation main body requires about 20 MB. This figure excludes additional items like scaling factors and the embedding table itself. If the embedding table is still saved in 16-bit floating point, the 168 million parameters require about 335 MB, far exceeding the computation main body.
Therefore, after the main body is compressed, the proportion of the embedding table in storage becomes noticeably higher. This is why many compression schemes turn their attention to the embedding layer.
Why Embedding Layers Are Difficult to Quantize
Mainstream quantization methods typically make conservative changes to the embedding layer for three reasons.
First, the embedding table is a dense matrix where each token corresponds to an entire row vector. During inference, it only performs row indexing, with no multiply-accumulate operations, nor does it pass through non-linear or normalization layers to absorb errors. Quantization noise directly enters all subsequent layers and accumulates layer by layer during matrix multiplication.
Second, in models using weight tying, the embedding table shares the same parameters as the output layer. The input end requires vectors to carry semantic encoding, while the output end requires vectors that can distinguish different tokens. The numerical precision requirements on both ends are not entirely consistent; reducing the bit-width may degrade the quality of both sides simultaneously. Models that do not use weight tying do not have this coupling, so the model structure should be confirmed first before making a judgment.
Third, the common idea of layer-by-layer calibration is to introduce an error in the current layer and then adjust it via the activation distribution of subsequent layers. The computation path after the embedding layer is relatively short, leaving limited room for such adjustments.
Four Approaches and How to Use Them
The following four directions attempt to break the default practice that “the embedding table must exist in its entirety.” Each requires measuring the gains and losses on the target task. The prerequisites and fallback options for each are listed below.
Approach 1: Dimensionality Reduction for Embedding Storage
The method involves decomposing the embedding matrix into the product of two low-rank matrices. The smaller factors are stored, and during inference, the hidden layer dimension is restored through a small linear transformation.
The key to this method is the choice of rank. The lower the rank, the more storage is saved, but the fidelity of semantic distances also worsens. It is recommended to measure perplexity and downstream task metrics at different ranks on a representative calibration set, then choose the lowest rank with an acceptable loss. If a certain task metric drops beyond a threshold, full vectors can be retained for high-frequency tokens, and low-rank approximation can be applied only to the low-frequency part.
Approach 2: Shared Token and Subword Vocabulary Strategies
The method involves counting token frequencies. High-frequency tokens retain independent vectors, while low-frequency tokens are grouped into several cluster centers, using the nearest center vector as a replacement during inference.
The main parameter to decide is the number of cluster centers. The fewer the centers, the more storage is saved, but the representation of low-frequency tokens becomes coarser. If brute-force search is used, each lookup requires comparison with all centers, and the computation is proportional to the number of centers. When there are many centers, an approximate nearest neighbor index should be considered. The fallback strategy can be set up so that when the loss for a category of tokens on the validation set exceeds a threshold, independent vectors are restored for that category.
Meanwhile, splitting word embeddings into a combination of roots, affixes, and positional representations can reduce redundant storage. This structure requires tokenizer and vocabulary support, involving significant changes, and is more suitable for models planned during the training phase.
Approach 3: Offline Freezing and Streaming Loading
The method treats the trained embedding table as a static resource, storing it on disk and reading it on demand via memory mapping (mmap). Each inference only loads the token vectors present in the context.
This approach reduces resident memory, but whether it improves startup latency depends on several conditions: the random read speed of the storage, the hit rate of the system page cache, and the number of page faults generated during the first access. On devices with slower storage or cold starts, the first inference may actually be slower. Therefore, before implementation, the first-token latency for both cold and warm starts should be measured on the target device, and general latency figures should not be directly applied.
The fallback method is to keep a resident copy of a small portion of popular tokens, reading the rest on demand.
Approach 4: Cross-layer Weight Sharing and Distillation Compression
The method explores parameter reuse between input embeddings and intermediate hidden layers, using a trainable lightweight mapping module to maintain the coherence of semantic information. During training, large model distillation can guide the compression encoding of the small model’s embedding layer. During inference, only the mapping table and a small decompression module are retained.
This direction has the highest training cost, requiring additional distillation data and training steps, and its benefits depend heavily on the quality of the distillation. It is suitable for teams with continuous training capabilities who need to reuse the same foundation model across multiple tasks.
Comparison of the Four Approaches
| Approach | Storage Compression | Accuracy Risk | Edge Adaptation | Implementation Complexity | Applicable Boundaries |
|---|---|---|---|---|---|
| Dimensionality Reduction | Medium to High, depends on rank | Medium, lower rank is more obvious | Good, one extra small matrix multiplication at inference | Low | Universal, requires calibration |
| Token Clustering Sharing | High, depends on the number of centers | Medium to High, concentrated on low-frequency tokens | Fairly good, requires nearest neighbor search | Medium | Corpora with clear frequency distribution |
| Streaming Loading | Reduces resident memory, disk usage unchanged | Low | Depends on storage speed | Low to Medium | Memory-constrained devices with fast storage |
| Cross-layer Sharing & Distillation | High | Depends on distillation quality | Good | High | Teams with training resources and multi-task reuse |
Pre-deployment Checklist
- Confirm whether the model uses weight tying, and choose the approach accordingly.
- Fix a calibration set and evaluation set, and record the baseline perplexity and task metrics.
- Change only one variable per compression, recording accuracy changes step by step.
- Measure cold and warm start latency, as well as peak memory, on the target device respectively.
- Set fallback conditions for each approach; restore full precision for the corresponding part if the threshold is exceeded.
Conclusion
The high proportion of parameters occupied by the embedding table is a real problem in the compression of small models. However, the benefits of compressing it depend on the model structure, task requirements, and device conditions. Measure the baseline before starting, choose one approach, and set an acceptable loss for it, so that the compression results can be reproduced and explained clearly.
