Open-Source On-Device LLM Architecture Evolution and Inference Engine Adaptation

    This article reviews the architecture evolution of open-source on-device LLM series and examines the inference engine adaptation requirements behind mechanisms such as per-layer embeddings, cross-layer KV cache sharing, heterogeneous KV heads, K=V projection, and multimodal encoders. It explains how these mechanisms differ across model sizes and provides practical recommendations for export validation, mechanism-combination testing, quantization, memory budgeting, and multimodal pipeline decoupling.

    1. Background: A Model Series Covering All Scenarios with Multiple Sizes

    In recent years, open-source large models have gradually moved from a “single large parameter scale” approach toward “multi-size coverage across scenarios”: from small on-device models deployable on phones to desktop-level models with tens of billions of parameters, using one architectural philosophy to cover the full spectrum from mobile devices to servers. The benefits are clear: developers can use the same ecosystem, the same fine-tuning and deployment workflow, and obtain as consistent capability performance as possible across devices with different compute tiers.

    One detail that is easy to overlook is that different sizes within the same series are often not simple parameter scaling. To reduce memory and bandwidth overhead on low-compute devices, small models usually enable different combinations of architectural mechanisms from large models, such as hybrid local and global attention, cross-layer KV Cache sharing, and lookup-table-based embedding injection. This imposes higher adaptation requirements on inference engines: an engine not only needs to support multiple operators, but also must correctly handle mechanism differences across sizes.

    From the perspective of inference engine adaptation, this article reviews the key mechanisms and evolution logic of such on-device large models and provides practical recommendations.

    2. Evolution of Three Architecture Generations

    To understand the latest generation of models, it is necessary to look back at the evolution path of the previous two generations. Taking an open-source model series as an example, its architecture evolution has roughly gone through three stages:

    Feature First generation Transitional generation (on-device specific) Latest generation
    Attention mechanism Hybrid attention (local + global) Hybrid attention Hybrid attention
    KV Cache Independent per layer Cross-layer sharing (~10 layers) Cross-layer sharing (18–20 layers)
    Embedding One shared set across the model PLE (direct lookup injection) PLE (lookup + projection fusion)
    QKV Norm Q/K normalization only Q/K/V normalization Q/K/V normalization + attn_scale=1.0
    V projection Independent v_proj Independent v_proj Some variants use K=V (omit v_proj)
    KV Head Uniform Uniform Heterogeneous KV heads
    Vision encoder Lightweight ViT Mobile-friendly encoder Lightweight ViT + Pooler
    Audio support None Audio encoder introduced Upgraded streaming audio encoder
    MoE None None Some larger variants introduce sparse experts

    The table shows a clear evolution logic: the memory-saving mechanisms introduced specifically for on-device deployment in the transitional generation are retained, strengthened, and extended to larger models in the latest generation.

    3. Key Mechanism Breakdown

    1. PLE (Per-Layer Embeddings): A Lookup-Based Embedding Approach

    In traditional Transformer models, the input embedding and output projection usually share the same large matrix. For a vocabulary of hundreds of thousands of tokens, this matrix may occupy several GB of memory, which is very unfriendly to phones.

    The PLE idea is to equip some intermediate layers with their own lookup vectors, that is, “each layer has (part of) its own Embedding,” and directly inject the representation into the corresponding layer through lookup, thereby splitting the total size of the shared vocabulary across multiple layers. The benefits are:

    • Significant reduction in runtime memory: the peak memory of on-device inference is often determined jointly by weights and KV Cache, and splitting the Embedding directly lowers weight residency;
    • On-demand loading: lookup means that only the rows used by the current token are read, which naturally fits sparse activation.

    The cost is increased structural complexity: during export and deployment, three sets of logic need to be distinguished: “shared Embedding,” “in-layer lookup injection,” and “output projection.” A small mistake can cause accuracy issues.

    2. Cross-Layer KV Cache Sharing: The Key to Compressing Context Memory

    In autoregressive inference, KV Cache usage is proportional to the number of layers. Cross-layer sharing means that some layers no longer maintain independent KV, but reuse the KV of a certain group (a common approach is to group every few layers). From “independent per layer” in the first generation, to 10-layer sharing in the transitional generation, to 18–20-layer sharing in the latest generation, the sharing ratio is gradually increasing.

    For inference engines, this means:

    • Cache allocation is no longer a simple formula of “number of layers × sequence length”; it must be calculated by sharing group;
    • Sampling kernels need to correctly handle the case where “some layers are read-only and do not write”;
    • General optimizations such as paged cache need to be remapped on the grouping dimension.

    3. Heterogeneous KV Heads and K=V: Squeezing Bandwidth for Small Models

    Modern models commonly use GQA (grouped-query attention) to reduce the number of KV heads. The latest generation further introduces two aggressive optimizations:

    • K=V: in some variants, the K projection and V projection share the same matrix (omitting v_proj). This reduces one set of projection parameters and one matrix multiplication, but requires the engine to correctly distinguish which layers have identical K and V and which layers are independent when computing attention;
    • Heterogeneous KV heads: different layers use different numbers of KV heads, breaking the convention of “a uniform KV head count across the whole model.” This gives architecture search greater freedom, but during export and graph optimization, the configuration must be read layer by layer, and global consistency cannot be assumed.

    4. Multimodal: From Optional Capability to Native Support

    For audio, the shift from introducing a Conformer-like encoder to upgrading to an encoder capable of streaming inference further reduces the latency of on-device voice interaction. For vision, a lightweight ViT combined with a Pooler compresses the number of visual tokens, directly reducing prefill overhead and KV usage for multimodal input. The key points for engine adaptation are: the vision/audio encoders and the backbone LLM need to be exported and quantized separately, and connected at runtime through a unified pre- and post-processing pipeline.

    4. Practical Adaptation Recommendations

    Based on the mechanisms above, here are several actionable recommendations:

    1. Validate per-layer configuration during export. For parameters such as PLE, KV sharing groups, and heterogeneous KV heads, it is recommended to assert layer by layer in the export script to avoid accuracy regression caused by silent differences across variants.
    2. Build a test set with a “mechanism switch matrix”. For each mechanism combination (such as K=V + KV sharing + PLE), construct minimal test cases, perform numerical alignment with the reference implementation, and narrow issue localization down to a single layer.
    3. Treat quantization strategies differently. Lookup-type weights are more sensitive to quantization error; it is recommended to use higher precision or per-row quantization for vocabulary-related parameters, while attention projections can try more aggressive lower bit widths.
    4. Split the memory budget into three parts. During on-device deployment, estimate peak memory separately as “weights, KV Cache, and activations,” and calculate KV Cache by sharing group rather than by layer count.
    5. Decouple the multimodal pipeline. Deploy vision/audio encoders and the LLM backbone separately to facilitate independent upgrades and quantization, while reducing on-device package size.

    5. Conclusion

    The evolution direction of on-device large models is already clear: rather than simply stacking parameters, they use structural optimizations such as PLE, KV sharing, and heterogeneous attention heads to approach large-model experience on devices constrained by memory and bandwidth. For inference engine and application developers, understanding the design motivations behind these mechanisms is more important than memorizing a specific configuration—it determines whether your adaptation code can smoothly upgrade with minimal changes when the next generation of models is released.