Architecture Evolution and Inference Adaptation of Open-Source Multi-Scale Edge-Cloud LLMs

    Open-source large language models (LLMs) are increasingly released as multi-scale series rather than single flagship versions to meet diverse hardware requirements ranging from edge devices to cloud servers. This article explores the architecture evolution of these edge-cloud collaborative models, breaking down key mechanisms such as Per-Layer Embeddings (PLE), cross-layer KV Cache sharing, and native multimodal support. Furthermore, it provides practical methodologies for adapting inference engines, covering weight export, graph modification, regression testing, and performance optimization to help developers effectively deploy these heterogeneous model series.

    1. Background: The Trend of Edge-Cloud Integrated Model Releases

    In recent years, the release of open-source large models has shown a clear trend: single flagship models are gradually being replaced by “multi-scale model series.” A single release often provides versions with different parameter scales—from billions to tens of billions of parameters—covering full-scenario needs from mobile edge devices and desktops to servers. This approach is driven by two main factors:

    • Hardware Fragmentation: There are significant differences in memory and computing power among mobile SoCs, consumer-grade GPUs, and cloud acceleration cards. A single model cannot cover all these scenarios, making multi-scale releases a necessity.
    • Inference Cost Control: Edge models can run offline without network latency, while cloud models handle complex reasoning. Edge-cloud collaboration has become the mainstream architecture for real-world deployment.

    Notably, these multi-scale series are often not simple parameter scalings. Different specifications may employ combinations of different architectural mechanisms: small models may introduce more aggressive cache sharing and embedding optimizations to save memory, while large models might introduce Mixture of Experts (MoE) to improve expressive power per unit of compute. This “heterogeneous series” poses real engineering challenges for inference engines—different specs within the same series may require distinct computational graphs and optimization paths.

    This article will outline the core architectural mechanisms of such edge-cloud collaborative models from a general technical perspective, and provide reusable methodologies and recommendations based on inference engine adaptation practices.

    2. Architecture Evolution: Inheritance and Innovation Across Three Generations

    Taking a common industry evolution path as an example, edge-specific models typically go through three stages:

    1. General Basic Version: Adopts the standard Transformer structure and hybrid attention (some layers use sliding window local attention, while others use global attention) to balance long-context capability with computational overhead. The KV Cache is stored independently per layer.
    2. Edge Transition Version: Designed specifically for mobile devices, it introduces multiple cost-reduction and efficiency-enhancing mechanisms for the first time, such as Per-Layer Embeddings (PLE), cross-layer KV sharing, and native support for visual and audio inputs.
    3. Latest Series Version: Evolves further based on the transition version’s mechanisms by expanding the number of KV shared layers, introducing heterogeneous KV Heads, dual position encoding, and other mechanisms. Large-scale versions can also introduce MoE structures.

    The table below summarizes the typical architectural differences across the three generations of models:

    Feature Basic Version Edge Transition Version Latest Series Version
    Attention Mechanism Hybrid Attention Hybrid Attention Hybrid Attention
    KV Cache Per-layer independent Cross-layer shared (~10 layers) Cross-layer shared (18~20 layers)
    Embedding Global shared embedding PLE (lookup table direct injection) PLE (lookup table + projection fusion)
    QKV Norm Q/K Norm Q/K/V Norm Q/K/V Norm + attn_scale adjustment
    V Projection Independent v_proj Independent v_proj Partial spec K=V (omit v_proj)
    KV Head Unified Unified Heterogeneous KV Head
    Vision Encoder Standard ViT Lightweight mobile network ViT + Pooler
    Audio Support None Conformer Enhanced Conformer
    MoE None None Large scale: 128 experts Top-8

    The core logic of this evolution is to “maximize the compression of edge memory and compute overhead while minimizing accuracy loss.” Below is a breakdown of the three most critical mechanisms.

    3. Core Mechanism Breakdown

    3.1 Per-Layer Embeddings (PLE)

    In traditional Transformers, all Transformer layers share the same word embedding matrix. For models with vocabularies often exceeding tens of thousands and high embedding dimensions, this matrix itself consumes a large amount of edge memory. The PLE approach involves:

    • Each Transformer layer holding a small, independent embedding matrix;
    • During computation, tokens are directly injected into the corresponding layer via a lookup table, avoiding the loading of the full global embedding;
    • On the output side, the lookup result is fused with a projection matrix, reducing one explicit transformation.

    In practice, this mechanism can reduce embedding-related memory overhead by an order of magnitude with almost no impact on generation quality, offering significant benefits for mobile phones with only a few GBs of memory. The key adaptation point is that the inference engine must support a “lazy loading per layer” or “chunked reading per layer” memory layout for embedding tables; otherwise, the optimization benefits will be offset by full loading.

    3.2 Cross-Layer KV Cache Sharing

    KV Cache is the primary memory consumer during long-context inference. Cross-layer KV sharing allows a group of Transformer layers to share the same KV cache:

    • The edge transition version shares one KV cache per several layers;
    • The latest series version expands the sharing scope to 18~20 layers, further compressing KV memory overhead;
    • Combined with heterogeneous KV Head design, different layer groups can have different numbers of KV heads, allowing for finer-grained control over cache size.

    For inference engines, this changes the KV Cache allocation model: memory can no longer be allocated linearly based on “layers × heads × dimensions.” Instead, it must be managed by layer groups, and the shapes of different groups may be inconsistent. During implementation, it is recommended to abstract a “KV group” concept to support cache pools with heterogeneous shapes.

    3.3 Native Multimodal Support

    Edge multimodality typically involves three input streams:

    • Vision: A lightweight vision encoder (such as a compact ViT or mobile convolutional network) encodes images into token sequences, which are concatenated with text tokens and fed into the language model;
    • Audio: An audio encoder based on a Conformer-like structure outputs speech feature tokens;
    • Text: The standard word embedding path.

    The adaptation challenge lies in the heterogeneity of the preprocessing pipeline: preprocessing operators such as image scaling and normalization, as well as audio framing and windowing, have inconsistent operator coverage on mobile NPUs. They often need to fall back to CPU implementations, becoming one of the bottlenecks for end-to-end latency.

    3.4 Other Notable Mechanisms

    • K=V Projection: Some small-scale models omit the independent value projection matrix, allowing K and V to share the projection result, which is a typical “accuracy for memory” trade-off.
    • Dual RoPE: Different Rotary Position Embedding (RoPE) parameters are used for different attention ranges (local/global layers) to adapt to hybrid attention mechanisms.
    • MoE: Large-scale versions adopt Mixture of Experts structures (e.g., 128 experts Top-8 routing). While the total parameter count is large, the number of activated parameters per inference is kept low, making it the mainstream route for cloud models to improve cost-effectiveness.

    4. General Methodology for Inference Engine Adaptation

    Based on adaptation practices for such heterogeneous model series, the following general workflow can be summarized:

    1. Weight Export and Graph Modification

    It is recommended to first complete weight export using mainstream community conversion toolchains, and then perform graph modifications for proprietary engines. Typical points to handle include: PLE lookup table fusion, cache shape changes caused by KV sharing, and attn_scale constant folding. An illustrative pseudo-code approach:

    1. # Cache allocation illustration for KV shared layer groups (pseudo-code)
    2. kv_groups = group_layers(model.layers, shared_kv_config)
    3. cache_pool = {}
    4. for gid, layers in kv_groups.items():
    5. cache_pool[gid] = alloc_kv(
    6. num_heads=layers.kv_heads, # Heterogeneous: head count varies per group
    7. head_dim=layers.head_dim,
    8. max_seq_len=ctx_len,
    9. )

    2. Spec-Specific Regression Testing

    Because the combination of architectural mechanisms differs across specs, an independent regression test suite must be established for each spec, covering: short text generation, long context (to verify KV sharing correctness), multimodal input (to verify encoder alignment), and streaming decoding consistency. For alignment metrics, it is advisable to look at both logits cosine similarity and end-to-end generated text diff.

    3. Performance Optimization Focus

    • Prefill Phase: Parallel prefilling of images and long prompts is key to first-token latency. On mobile devices, NPUs can be leveraged to accelerate vision encoders.
    • Decoding Phase: For small batch sizes, attention operators are memory-bandwidth bound. The cache compression brought by KV sharing can directly improve token generation speed.
    • Memory Layout: The chunked loading strategy for embedding tables and KV caches determines whether the model can run on low-memory devices.

    5. Recommendations and Summary

    For developers looking to deploy these open-source models on edge devices or in the cloud, the following recommendations are provided:

    • Model Selection: For mobile devices, prioritize small-scale versions with PLE and KV sharing, as memory footprint is usually the decisive factor. For server-side batch inference scenarios, prioritize MoE versions, as fewer activated parameters mean lower service costs.
    • Quantization: For edge devices, start with weight quantization (e.g., 4-bit integer quantization). PLE and KV sharing mechanisms have good compatibility with quantization; however, KV Cache quantization needs to be verified separately for shared layer groups.
    • Toolchain: Prioritize official or mature community conversion and inference solutions. The custom adaptation workload for heterogeneous architectural mechanisms is often underestimated.
    • Evaluation: Do not solely look at general benchmark scores. Edge scenarios should focus on evaluating first-token latency, generation speed, peak memory, and end-to-end multimodal latency.

    Overall, these multi-scale open-source model series for edge-cloud collaboration represent a significant direction in the open-source community. By innovating at the architectural level (PLE, KV sharing, MoE, heterogeneous attention heads) rather than merely stacking parameters, they achieve optimal cost-effectiveness across different hardware scenarios. For inference engine developers, understanding the design motivation behind these mechanisms is more important than adapting operators one by one—only by grasping the design logic can they quickly adapt when facing the next generation of models.