On-Device Multimodal LLM Architecture: PLE, Cross-Layer KV Sharing, and Adaptation Practices

    A practical walkthrough of adapting and exporting a new series of open-source multimodal models for on-device and edge inference. Spanning a 2B dense model at the low end up to a 31B dense model at the high end—plus two roughly 26B variants (one MoE that activates only 4B, one dense)—the series mixes attention forms, KV Cache strategies, embedding schemes, normalization, KV head layouts, and modality encoders, so a fixed structural template will not work. This article breaks down the three defining mechanisms—Per-Layer Embeddings (PLE), cross-layer KV Cache sharing, and native multimodal input—then covers the full path from export and numerical alignment to quantization and performance tuning. It closes with a self-test verification checklist and guidance on choosing the right spec for phones, desktops, and edge devices.

    I. Background: Why the New Generation of Open-Source Multimodal Models Is Hard to Adapt

    The new series of open-source multimodal models (referred to below as “the new series”) has become a notable target in the on-device and edge inference space. It ships four specs: a 2B-class dense model at the smallest end for on-device use, a 31B-class dense model at the largest end for desktop-class machines, and two middle variants that share roughly the same parameter count (~26B) but activate very differently—one is a MoE model that activates only 4B, the other is dense. Together the four specs cover the full compute range from phone to server.

    What actually makes adaptation complex is not the parameter span. The four tiers are not simple parameter scaling: they combine different mechanisms across attention form, KV Cache strategy, embedding method, normalization position, KV head configuration, and even the modality encoders. An inference engine therefore cannot rely on a single fixed structural template; it needs the ability to toggle features and configure them per layer. Within the same series there are both dense and MoE models, and both the traditional form of independent per-layer KV and the form of cross-layer shared KV.

    This article records the process of adapting and exporting every spec in the series, with a focus on three distinctive mechanisms:

    • Per-Layer Embeddings (PLE): changes the scale of embedding parameters and their injection path;
    • Cross-layer KV Cache sharing: changes the memory layout of the cache and the data flow between layers;
    • Native multimodal support: changes the input pipeline and the VRAM/memory budget model.

    The sections below first trace the architecture’s evolution, then analyze these three mechanisms one by one, and finally lay out the complete path from export and quantization to performance tuning, along with usage recommendations.

    II. From the Previous Generation to the New Series: Three Generations of Architecture

    The new series did not jump straight from the generation before last. There is a key transition version aimed at on-device hardware in between. This transition version was the first to introduce mechanisms such as per-layer embeddings and KV sharing, and it added native multimodal support. The new series inherited these designs and extended them further in sharing scale, embedding fusion, KV structure, and MoE. The table below (key items only) compares the previous-generation dense model, the on-device transition version, and a representative configuration of the new series. Items in the new-series column marked “some specs” apply only to specific models; configurations are not uniform across the series.

    Feature Previous gen On-device transition New series
    Attention Hybrid (local sliding window + global) Hybrid attention Hybrid attention
    KV Cache Independent per layer Group sharing (~10 layers share one) Group sharing (~18–20 layers share one)
    Embedding Main embedding tied to output layer weights Per-layer embeddings, direct injection after lookup Per-layer embeddings, lookup + projection fusion
    QKV Norm Q/K normalization only Q/K/V all normalized Q/K/V normalized, with an explicitly set attention scaling factor
    Value vector projection Independent v_proj Independent v_proj Some specs set K=V, with no independent v_proj
    KV heads Uniform across layers Uniform across layers Heterogeneous KV heads (different config per layer)
    Vision encoder ViT-like Lightweight mobile vision backbone ViT-like + pooling layer (some specs)
    Audio support None Conformer-like encoder Audio supported
    Mixture of Experts None None Yes (~26B total params, 4B activated, 128 experts with Top-8 routing)

    The progression can be summarized along three main threads:

    Thread 1: Memory efficiency for on-device. The shared-KV span grows from about 10 layers to about 18–20 layers, which directly determines how long a context an on-device device can open within an acceptable memory budget. Per-layer embeddings evolve from “inject directly after lookup” to “lookup + projection fusion,” giving more flexible injection at the cost of an extra projection computation—so the engine must support fusing a matrix multiply with a residual add.

    Thread 2: Finer-grained attention structure. Hybrid attention is retained across all three generations, but the surrounding structure grows steadily less uniform:

    • Some specs set K=V directly, eliminating the independent value projection;
    • Different layers use heterogeneous KV heads;
    • Global layers use a RoPE base frequency suited to long context, while local layers use a RoPE base frequency oriented to short-range windows (dual RoPE);
    • The attention scaling factor is set explicitly.

    Each design has its own benefit, but all of them force the engine to abandon the implicit assumption that every layer shares the same structure.

    Thread 3: Multimodal goes from optional to native. The previous generation was text-only. The on-device transition version added audio and a lightweight vision backbone. Some specs in the new series upgrade to a ViT-like vision encoder plus a pooling layer, and unify text, image, and audio into a single token sequence.

    III. Per-Layer Embeddings (PLE): Embeddings Move from “Shared” to “Layered”

    3.1 The problem it solves

    A conventional language model keeps only one embedding table: an input token looks up a vector, that vector enters layer 1, and every subsequent layer transforms the same initial representation step by step. On-device scenarios impose two particular constraints: memory and VRAM bandwidth are tight, and the parameter budget is limited. The motivation behind per-layer embeddings is to give each layer an input prior that matches its own role, while the layered structure itself provides enough capacity headroom for runtime pruning or quantization.

    In implementation terms, each token queries several embedding tables that map one-to-one to the layers, and the lookup results are injected into the corresponding layer’s input via residual addition. The difference between the two generations lies precisely in the “injection method”:

    • On-device transition version: inject directly after lookup;
    • New series: fuse the lookup result with the main embedding through a projection layer, then inject.

    3.2 Three impacts on the inference engine

    (1) Parameter scale and resident memory. Per-layer embeddings multiply the embedding-related parameters. On memory-constrained devices like phones, whether the embedding tables can stay resident, whether they share a memory pool with other weights, and whether they can be weight-bound with the output layer all directly affect the largest spec that can be supported. It is worth making the “share of embedding-related parameters” the first metric when evaluating a spec.

    (2) Operators and graph structure. Per-layer lookup is essentially a series of gather operations placed at each layer’s entry point, which produces many parallel memory-access branches in the compute graph. The engine needs to:

    • Support lookup and residual injection located per layer;
    • Fuse sequences such as “projection + residual add + next-layer normalization” into fewer operators;
    • Avoid repeatedly materializing intermediate tensors at every layer boundary.

    (3) Sparse activation and dynamism. The on-device transition version also introduced per-layer activation sparsity: not every layer is active for every token; instead, routing decides which layers’ embeddings are activated. This creates two problems for static-graph export:

    • Control flow: if the routing result depends on runtime data, exporting to a static graph requires handling conditional branches, or degrading to an equivalent “compute everything + mask” implementation;
    • Performance accounting: peak compute and average compute can differ greatly, so looking only at theoretical FLOPs will overestimate the real cost.

    3.3 A simplified pseudocode sketch

    1. # Pseudocode: ignoring normalization and linear-layer biases
    2. # ple_table[i]: per-layer embedding table for layer i
    3. # ple_proj[i]: projection applied to the lookup result (new-series fusion method)
    4. def layer_input(i, h, token_ids, main_embed):
    5. e = ple_table[i].lookup(token_ids) # per-layer lookup, op: gather
    6. if ple_proj[i] is not None:
    7. e = ple_proj[i](e) # lookup + projection fusion
    8. return h + e # residual injection into this layer's input

    IV. Cross-Layer KV Cache Sharing: One Cache, Reused Across Layers

    4.1 The basic principle

    In a conventional Transformer, every layer computes and caches its own K and V independently. When generating token t, layer l appends the current token’s K and V to that layer’s cache, then computes attention between the current token’s Q and all of that layer’s historical K.

    Cross-layer sharing groups several consecutive layers together. Within a group, the first “provider” layer computes and writes K and V as usual, and the subsequent “consumer” layers directly reuse the provider layer’s K and V, using only their own Q to compute attention. The diagram below illustrates this (numbering is for illustration only):

    1. Conventional independent KV: Cross-layer shared KV:
    2. L0 [K0 V0][Q0] L0 [K0 V0][Q0] ← provider, writes cache
    3. L1 [K1 V1][Q1] L1 (shared)[Q1] ← consumer, reuses L0
    4. L2 [K2 V2][Q2] L2 (shared)[Q2]
    5. L3 [K3 V3][Q3] L3 [K3 V3][Q3] ← new group provider
    6. ...... ......

    Take the case where 20 layers share one cache and the rest are independent: the theoretical cache size drops to roughly one-tenth of the original (ignoring the additional savings from sliding-window layers keeping only the in-window K/V). This is exactly what lets on-device devices open a long context with limited memory. Consumer layers still keep their own independent Q projection and output projection, so sharing does not mean the layers become identical. The new series expands the sharing span to about 18–20 layers, making the benefit more pronounced, but the cost is a wider “single point of failure” impact: once the provider layer’s values go wrong, the problem spreads across the entire group.

    4.2 Key changes on the engine side

    (1) Cache allocation logic. The engine needs a “layer-to-cache-slot” mapping table, allocating cache only to provider layers and redirecting consumer layers to the corresponding slots at runtime. A common mistake is to keep the old “one block per layer” logic, which wastes a large amount of memory, or to mistakenly execute an append write in a consumer layer.

    (2) Heterogeneous KV heads. When different layers (including the provider and consumer layers within the same group) have different KV head counts or head dimensions, the cache block size and memory layout cannot be uniform. Two workable approaches are:

    • Align allocation to the “maximum head count,” wasting some space;
    • Implement variable-length cache blocks, at the cost of more complex addressing.

    More importantly, there is a sharing constraint: a consumer layer’s Q dimension must match the provider layer’s K dimension, so sharing groups can only be formed among structurally compatible layers and cannot be applied mechanically as “share once every N layers.”

    (3) Local sliding-window layers and ring cache. A local attention layer attends only to the most recent W tokens, so its cache can be a ring structure that overwrites the oldest entries once full. The engine must ensure the ring cache’s read/write positions correspond one-to-one with logical positions; otherwise, when long-sequence generation crosses a window boundary, attention results can silently shift in ways that are hard to notice.

    (4) The implicit constraint of dual RoPE. Sharing means the provider and consumer layers face the same K, and that K has already had the provider layer’s RoPE applied before entering the cache. When a consumer layer takes the dot product with its own Q (to which RoPE is also applied according to its own configuration), the relative-position relationship only holds when the encoding method of the two positions is consistent. Therefore, layers within the same sharing group must use the same RoPE configuration, and the boundary of the dual RoPE must align with the sharing-group boundary.

    (5) Prefix caching and KV reuse. The sharing structure is naturally well suited to prefix reuse: the provider layers for the same prompt are computed once, and subsequent requests hit the cache directly. The prerequisite, however, is that the prefix’s layer configuration exactly matches the current model; mixing caches from different specs or sharing strategies will produce incorrect results outright.

    4.3 The extra impact of K=V on cache management

    Some specs set K=V, meaning no separate value vector is computed and K is used directly as V. This removes one projection mathematically, but in implementation it requires that “append writes” and “reads” be strictly separated: if you perform an in-place update on the cached K to save memory (for example, reusing the same memory block to write a new token), the V that a consumer layer reads will be silently overwritten. It is advisable to wrap the cache in a read-only view and forbid any in-place modification of K/V.

    V. Native Multimodal: How Three Modalities Cooperate Within One Model

    5.1 Unifying the input side

    The new series unifies text, image, and audio into a single sequence:

    • Text: token vectors produced by the embedding layer;
    • Image: image tokens produced by the vision encoder;
    • Audio: audio tokens produced by the audio encoder.

    Once the three kinds of vectors are concatenated, they are fed into the language-model backbone together. This raises the bar for the engine: it is no longer enough to “run a vision model plus run a language model.” The engine must support:

    • Insertion of a variable number of multimodal tokens;
    • One-to-one mapping from image/text and audio/text placeholders to the actual features;
    • Consistent position encoding for tokens of different modalities within the sequence.

    5.2 Three common failure modes

    • Placeholder–feature count mismatch: the number of placeholders in the prompt template does not match the number of tokens output by the encoder. In mild cases this causes misalignment; in severe cases it shifts the semantics of an entire segment. It is best to validate the count explicitly and raise an error rather than silently truncate.
    • Modality boundary breach: the attention mask fails to correctly restrict cross-modal visibility, letting text tokens see image fragments they should not.
    • Position encoding double counting: multimodal tokens and text tokens are counted separately, causing position conflicts.

    5.3 Independent difficulties on the encoder side

    Vision and audio encoders typically run before the backbone, and their input size is not fixed (image resolution and audio duration both vary). The engine must support dynamic shapes or a bucketing strategy; otherwise it either reserves too much memory for the maximum size or triggers recompilation frequently. Some specs also add a pooling layer after the vision encoder to compress the number of image tokens. This is essentially a trade of precision for context budget: on the engine side you only need to ensure the pooling operator’s semantics match training, but during evaluation you should keep in mind that the higher the compression ratio, the more noticeable the degradation on fine-grained vision tasks (such as small-object recognition or document details).

    VI. Other Easily Overlooked Mechanism Differences

    Beyond the three main mechanisms, several differences in the table also directly affect adaptation results:

    • QKV Norm and attention scaling: normalization applies to Q, K, and V simultaneously, and the scaling factor is set explicitly to a specific value. If the engine follows the default “divide by the square root of d” implementation, the values shift globally, showing up as degraded output quality rather than a direct error—which makes it expensive to track down.
    • Mixture of Experts: the MoE specs in the new series use Top-8 routing over 128 experts. On-device deployment must pay particular attention to loading expert weights on demand and swapping memory in and out, as well as the stability of routing after quantization (quantization error can change the Top-K selection).
    • Vision encoder upgrade: moving from a mobile backbone to a ViT-like encoder plus a pooling layer means the vision side’s share of compute rises, and the end-to-end latency bottleneck may shift from the language model to the vision-encoding stage.

    VII. From Export to Production: Adaptation Process and Verification

    7.1 A phased approach

    1. Complete the operators: first implement the new operators—gather, grouped attention, ring-cache writes, variable-length KV addressing, pooling, and so on—rather than stitching them together from many small operators.
    2. Align numerics: using the reference implementation as the baseline, compare intermediate tensors layer by layer to locate the first layer where a deviation appears, instead of looking only at the final logits.
    3. Choose a quantization strategy: evaluate the sensitivity of embedding tables, provider-layer K/V, and expert weights separately; per-layer embeddings and routing layers are usually more sensitive than ordinary linear layers.
    4. Tune performance: optimize memory access and operator fusion only after correctness is established. Reversing this order significantly increases debugging difficulty.

    7.2 Verification checklist (usable directly for self-testing)

    • For the same prompt, is the first-token logits difference between the reference implementation and the on-device engine within an acceptable range?
    • After the generation length crosses a sliding-window boundary, is the output still coherent?
    • Within a sharing group, do the provider and consumer layers’ caches correspond one-to-one, with no over-allocation and no mis-writes?
    • With mixed text-and-image input, do the placeholder count and the actual feature count match?
    • Under long context, does peak memory drop significantly with the sharing strategy?
    • Do the routing selection (for MoE specs) and the number of vision tokens stay stable before and after quantization?

    VIII. Usage Recommendations and Summary

    Drawing on the adaptation work, a few practical recommendations:

    • Start with the smaller spec on-device: a 2B-class spec paired with shared KV is a good starting point for balancing latency and memory on a phone.
    • Choose MoE or 31B on desktop/edge: the former has fewer activated parameters and is throughput-friendly; the latter has a simpler structure and a more mature toolchain—pick based on the task type.
    • Budget multimodal tasks up front: the compute and memory cost of the vision and audio encoders is often underestimated; it is best to get a single modality working before stacking others on top.
    • Treat “configurable structure” as a baseline engine requirement: within the same series, the combinations of mechanisms vary widely, and an engine with hard-coded structural templates will struggle to cover the whole series.

    Overall, the value of the new series lies in taking a combination of mechanisms inherited from the on-device transition version and pushing “long context + native multimodal” into a range that can run on-device. For an inference engine, the real challenge is not the parameter count but the structural differences introduced by per-layer embeddings, cross-layer KV sharing, and multimodal input. Abstracting these differences into configurable, verifiable engine capabilities is the key to adapting this class of model.