Per-Layer Embeddings: Slimming Embedding Tables for On-Device Multimodal Models

    On-device multimodal models are increasingly bottlenecked not by compute but by their embedding tables. This article explains why vocabularies balloon into the single largest memory cost, why the access pattern is fundamentally random rather than compute-bound, and where conventional optimizations such as weight sharing, low-rank factorization, and whole-table quantization fall short. It then introduces Per-Layer Embeddings, a structural change that splits one large table into per-layer slices while keeping total parameters nearly unchanged, shrinking the working set touched by any single lookup. The article walks through a framework-agnostic implementation, the tradeoffs of choosing the slice count, the synergy with low-bit quantization, compatibility with parameter pruning and layer skipping, and additional gains in multimodal settings. It closes with common pitfalls, a deployment checklist, and guidance on where teams should focus validation.

    Why Embedding Tables Are the #1 Memory Burden in On-Device Models

    Vocab bloat is structural, not a misconfiguration

    The vocabulary of an on-device multimodal model usually has to serve three roles at once: covering multiple writing systems (with many low-frequency characters and combining marks), encoding the discretized units for continuous modalities such as image and audio, and preserving special control tokens and tool-calling tokens. Stacked together, these demands routinely push the vocabulary from the hundreds of thousands into the mid-hundreds of thousands or larger.

    The memory cost of the embedding table is a straightforward product:

    1. embedding_table_bytes = vocab_size V × hidden_dim d × bytes_per_param b

    Plug in a typical order of magnitude (arithmetic example only): with V = 256,000, d = 2,048, stored in 16-bit floats (b = 2), a single table is roughly 1,000 MB. That does not even count the “un-embedding” output layer—if the input embedding and the output projection do not share weights, you need the same table again. On a phone with only 2–4 GB of usable memory, this one item alone decides whether the model fits at all.

    The pressure is asymmetric: random access, not sequential compute

    An embedding lookup is essentially a random index by token id, with almost no arithmetic intensity. The rest of the Transformer is where hardware excels—feeding large matrix multiplications through the pipeline. A lookup is discrete, random, and impossible to coalesce; its hit rate depends entirely on whether the working set can stay resident in on-chip cache. A 1 GB table means nearly every lookup is likely to hit main memory, and layer-by-layer, token-by-token random access turns latency into hard-to-predict jitter.

    Where conventional optimizations hit their limits

    Technique Benefit Remaining issue
    Sharing input/output weights Saves an entire table When the vocab is too large, a single table is still unaffordable
    Low-rank factorization (A·B form) Substantially reduces parameter count Weaker expressiveness; still needs to be projected back to d dimensions, so access volume does not drop
    Hash / reparameterized lookup High parameter sharing Requires extra hashing and collision handling; complex on-device
    Directly low-bit quantizing the whole table Storage halves or drops to 1/4 Outlier columns in large tables are severe; quantization error concentrates and on-device accuracy degrades noticeably
    Sparse / on-demand loading Lower peak usage Depends on storage bandwidth; large cold-start jitter

    The real bottleneck therefore splits into two independent problems: whether this table’s representational capacity is enough, and whether the part actually resident at any given moment is small enough. The core contribution of Per-Layer Embeddings is a single structural change that improves both at once.

    The Basic Idea Behind Per-Layer Embeddings

    From “one big table” to “one small table per layer”

    The conventional design looks up the embedding once for a token, producing a d-dimensional vector that then flows through all layers unchanged.

    Per-Layer Embeddings instead splits the d dimensions into N slices, each of size d/N, mapped to a Transformer layer (or a group of layers). On entering each layer, the model uses its own slice to look up its own small table of size V × (d/N), then assembles the result into the full representation that layer needs.

    Three points matter here:

    1. Total parameters stay roughly the same: N tables sum to N × V × d/N = V × d.
    2. The working set touched by a single lookup shrinks to 1/N: any given layer only touches a table roughly 1/N the size.
    3. Representational capacity actually increases: because each layer has independent parameters, each layer can learn a layer-specific representation of the same token instead of sharing one vector that gets repeatedly overwritten.

    A framework-agnostic sketch

    1. # Configuration
    2. V = 256_000 # vocab size
    3. d = 2_048 # hidden dimension
    4. N = num_layers # number of slices = number of layers (can be grouped, see 3.1)
    5. d_slice = d // N
    6. # Initialization: N small tables, shape [V, d_slice], total params ≈ V*d
    7. layer_embed_tables = [
    8. EmbeddingTable(V, d_slice) for _ in range(N)
    9. ]
    10. def forward_layer(layer_idx, hidden, token_ids):
    11. """
    12. layer_idx : index of the current layer
    13. hidden : full representation entering this layer, shape [B, T, d]
    14. token_ids : token ids for this sequence, shape [B, T]
    15. """
    16. # 1) Look up only this layer's slice table -> [B, T, d_slice]
    17. slice_embed = layer_embed_tables[layer_idx].lookup(token_ids)
    18. # 2) Take the slice range of hidden that belongs to this layer
    19. lo = layer_idx * d_slice
    20. hi = lo + d_slice
    21. base = hidden[..., lo:hi]
    22. # 3) Fuse: addition is simplest, but this can be gated fusion
    23. gate = sigmoid(Linear(d_slice)(base)) # element-wise gate for more plasticity
    24. refined = base + gate * slice_embed
    25. # 4) Write back to this layer's slice, leaving the others unchanged
    26. hidden[..., lo:hi] = refined
    27. return transformer_block(layer_idx)(hidden)

    If this needs to work together with an “input embedding + output un-embedding” setup, one engineering detail is worth stressing: the input-side lookup result should only be written back into the first slice, and the output-side un-embedding should only read from the last slice. Otherwise the mapping between each layer’s slice and the vocabulary semantics gets broken.

    1. # Input side: embedding(token_ids) -> fill only slice 0
    2. x = zeros(B, T, d)
    3. x[..., 0:d_slice] = layer_embed_tables[0].lookup(token_ids)
    4. # Output side: take only the last slice to project to the vocabulary
    5. logits = Linear(d_slice, V)(x[..., (N-1)*d_slice : N*d_slice])

    Why “layering” yields a real capacity gain

    By total parameter count alone, per-layer embeddings are on par with the original design, but the approach changes two things:

    • Parameters can be allocated non-uniformly across layers. Some layers (especially shallow ones) need finer vocabulary discrimination and can use larger slices; deeper layers rely more on already-abstracted semantics and can use smaller slices. This freedom is impossible in a single-table structure.
    • Adding embedding-side parameters is a better deal than increasing width. With a fixed hidden dimension d, widening d raises the compute cost of every layer at once; adding embedding-side parameters only increases memory and access volume, without changing the matrix-multiplication scale. For memory-constrained, compute-relatively-abundant on-device hardware, this is a worthwhile trade.

    To be honest about it: per-layer embeddings do not reduce the total bytes each layer must scan—going through all N layers reads the same total slice volume as the original single table. What it delivers is a lower peak working set, better locality for random access, and greater tractability for quantization and parameter organization, not an arithmetic reduction in total access volume. Treating it as “free speedup” is the most common misreading.

    Key Tradeoffs in Engineering

    How to choose the number of slices N

    N is not better the larger it gets; you have to balance three directions:

    • Larger N: each layer’s working set is smaller and low-bit quantization is easier; but as the slice dimension d/N shrinks, the relative overhead of linear projections and gating grows, and too-small slices struggle to carry enough information.
    • N equal to the number of layers: the most intuitive mapping, convenient for aligning parameter pruning with layer pruning.
    • N smaller than the number of layers (grouped sharing): grouping several consecutive layers to share one slice table, sitting between the two, usually the safest starting point.

    In practice, start with d/N in the 64–256 range as an initial search space, run a grid search using perplexity/task metrics, and separately monitor first-token latency.

    Synergy with low-bit quantization

    The most valuable spillover of the per-layer structure shows up in quantization. When quantizing the whole table, the model must cover all word vectors with a single global scale, yet high-frequency and low-frequency tokens, and text tokens and image tokens, have wildly different magnitude distributions; outliers stretch the quantization range, and what ultimately suffers is the accuracy of the common tokens that make up the vast majority.

    After slicing, each table is responsible for only a “sub-semantic direction” of the vocabulary, and the distribution is noticeably more concentrated. Further, you can set quantization parameters per slice and per vocabulary segment, keeping each small block’s quantization error within an acceptable range. Combined with group quantization (each group of columns sharing a set of scale/zero-point), the 8-bit and 4-bit integer storage common on-device finally becomes practical.

    Relationship with parameter pruning and layer skipping

    A natural property of the per-layer slices is that each table is only accessed by its corresponding layer. This brings two direct benefits:

    • If the runtime decides to skip some layers (low-load or low-power modes), the slice tables of the skipped layers can be left unloaded entirely, and peak memory drops accordingly.
    • With a “nested / prunable” parameter layout, you can keep a subset of slices on demand without breaking the shape of the rest, yielding several usable sub-models of different sizes from a single training run.

    This is exactly the structural basis that lets an on-device model advertise both a “smaller effective parameter count” and a “larger raw parameter count”—the former referring to the parameters actually resident and involved in computation, the latter to the total parameters in the weight file.

    Additional gains in multimodal scenarios

    Multimodal inputs (image patches, audio frames), once discretized, share the same vocabulary as text, but their “importance curves” across layers do not line up with text: shallow layers carry more local texture and phoneme-level information, while deeper layers lean toward semantic alignment. Per-layer embeddings let each layer learn modality-specific representations on its own terms, rather than forcing one shared vector to handle two distributions at once. In addition, if image-side encoding happens on the server, you can precompute per-layer embeddings and transmit compressed per-layer embedding caches by layer, so the device only does lightweight fusion, further reducing the on-device operator burden.

    Common Pitfalls and How to Avoid Them

    • Assuming per-layer embeddings lower FLOPs: it barely changes the matrix-multiplication scale; the gains are in memory and access, so evaluation metrics should include peak memory, P99 latency, and cache hit rate.
    • Rounding d when the slice dimension is not divisible by N: when d % N ≠ 0, direct integer division drops dimensions; you must explicitly handle the remainder slice (folding it into the last group), or you get hard-to-locate dimension mismatches.
    • Forgetting to keep updates in sync when sharing weights: if the input embedding and the output un-embedding reuse the same tables, confirm that gradient paths and parameter updates are consistent, so one side is not updated while the other reads stale weights.
    • Skipping calibration before quantization: low-bit quantization needs a representative calibration set covering multilingual and multimodal samples; calibrating on pure text alone leaves image-token quantization parameters badly mismatched.
    • Treating effective parameter count as a marketing figure: when describing model size externally, clearly distinguish “raw parameter count” from “actually resident parameter count” to avoid misleading selection decisions.

    Deployment Checklist

    1. Memory budget: itemize storage by V × d/N × b × number of slices, add KV cache, activations, and runtime overhead, and confirm a safety margin remains.
    2. Slice-count search: use d/N ∈ [64, 256] as the initial range for a small grid search, recording both accuracy and first-token latency.
    3. Quantization flow: first gather per-slice statistics on word-vector magnitude distribution, then decide grouping granularity and bit width; the calibration set must cover all supported languages and modalities.
    4. Inference-path verification: confirm token-id out-of-range protection for lookups, the id-range mapping for image/audio tokens, and the fallback handling for unloaded slice tables in pruned mode.
    5. Regression baseline: fix a set of cases covering long and short text, multiple languages, and image Q&A, comparing accuracy and latency version by version to prevent slice dimensions or quantization parameters from introducing silent regressions.
    6. Observability: bring peak memory, per-slice-table cache hits, and cosine similarity of outputs before and after quantization into monitoring and alerting, so anomalies can be traced directly to a specific slice.

    Summary

    The value of Per-Layer Embeddings lies not in any single trick but in turning the core tension of on-device multimodal models—an oversized vocabulary—into a structurally schedulable problem: with total parameters conserved, split one unaffordable large table into several small tables that can be quantized independently, loaded independently, and configured per layer for capacity, thereby improving peak memory, quantization accuracy, and pruning flexibility all at once. For teams doing on-device model selection and inference optimization, the two areas most worth validating first are slice-count selection and quantization calibration—they determine whether this structure can actually deliver on its theoretical gains.