# Open-Source On-Device LLM Architecture Evolution: An Engineering Practice Guide

    This guide explains how open-source on-device large language models have evolved architecturally and what that means for engineering teams. It covers the three-stage evolution from text-enhanced to next-generation multimodal on-device models, and examines four mechanisms that define the new generation: layered embeddings with per-layer injection, KV cache sharing and heterogeneous caching, native multimodal support, and their combined effect on quantization and deployment. It then walks through the four main challenges inference engines face (operator coverage, irregular memory layout, inconsistent quantization precision, and dynamic shapes), a reproducible evaluation framework spanning functional correctness, performance, quality and pre/post-quantization comparison, a five-step export and adaptation workflow, scenario-specific guidance for on-device, desktop and lightweight server deployments, and five common pitfalls to avoid.

    1. Background: On-Device LLMs Have Entered a Phase of Intensive Architectural Innovation

    In the past, whether a large model was suitable for on-device or edge deployment was often judged primarily by parameter count. In real engineering work, however, parameter count is only one factor that determines resource requirements. For on-device, desktop, or lightweight server scenarios, efficient execution also depends on the attention structure, caching strategy, embedding approach, multimodal input handling, operator support, and quantization friendliness.

    In recent years, a class of “on-device friendly” model families has appeared in the open-source LLM space. These models are not chasing larger parameter counts alone; they focus on delivering fuller text understanding, visual understanding, and audio understanding under constrained memory, compute, and power budgets. Their characteristics typically include:

    • A multi-tier model family spanning small mobile sizes up to mid-to-large desktop sizes;
    • Different sizes that are not simple parameter scaling, but different combinations of architectural designs;
    • Native multimodal input support rather than bolt-on concatenation;
    • Notable differences in inference engine compatibility, requiring targeted optimization.

    The arrival of such models raises the bar for inference frameworks and engineering teams. The more advanced the model, the less an inference engine can afford to be a mere “generic operator executor”: it must understand the special designs inside the model structure. Otherwise, even a very capable model can deliver a poor experience because of mismatched cache layouts, unsupported operators, excessive memory consumption, or degraded quantization accuracy.

    This article takes open-source on-device LLMs as its subject and covers architecture evolution, key mechanisms, inference engine adaptation, export and evaluation, and usage recommendations, forming an engineering practice guide aimed at developers.


    2. From the Previous Generation to the Next: The Architecture Evolution Logic

    The evolution of on-device LLMs does not happen in isolation. It typically passes through three stages: a text-enhanced version, an on-device transitional version, and a next-generation multimodal on-device version. Each stage solves different engineering problems and emphasizes different architectural priorities.

    The following abstract evolution table illustrates this:

    Design dimension Early text-enhanced design On-device transitional design Next-generation on-device design
    Attention structure Global or local attention combination Hybrid attention Hybrid attention with stronger cache reuse
    KV cache Independent cache per layer Partial layers share cache Multi-layer sharing, even heterogeneous cache heads
    Embedding Shared input embedding Layer-wise embedding injected directly Layer-wise embedding plus projection fusion
    Attention normalization Q/K normalization Q/K/V normalization Q/K/V normalization with stabilized scaling
    V projection Independent projection Independent projection Some sizes use K=V to reduce projection cost
    KV heads Uniform structure Uniform structure Heterogeneous KV heads
    Vision encoder None or basic vision encoder Lightweight vision encoder Image-text contrastive vision encoder with pooling
    Audio encoder None Streaming audio encoder Enhanced streaming audio encoder
    Sparse expert structure None None Optional sparse mixture-of-experts structure
    Positional encoding Uniform positional encoding Uniform or simple extension Modality- or layer-specific positional strategies

    The table shows that the core change in next-generation on-device LLMs is not “bigger” but “finer-grained”. These models try to solve several key on-device deployment problems inside the model structure itself:

    1. Reducing memory consumption: KV cache sharing, heterogeneous cache heads, and partial projection reuse lower peak inference memory.
    2. Improving representation efficiency: Layer-wise embedding injection means shallow input information does not act only at the bottom of the model, but continues to participate in computation across different depths.
    3. Strengthening multimodal adaptation: Vision, audio, and other modalities are integrated more naturally into the language model backbone rather than relying on bolt-on concatenation.
    4. Improving quantization and deployment compatibility: Normalization, stabilized scaling, and shared structures make low-bit inference easier to keep accurate.

    For engineering teams, understanding this evolution logic matters more than simply asking “how many parameters does the model have”. What actually determines the on-device experience is usually whether the cache strategy, operator coverage, quantization accuracy, and modality processing pipeline are complete.


    3. Key Mechanism 1: Layered Embeddings and Per-Layer Information Injection

    3.1 What layered embeddings are

    Traditional language models use text embeddings only at the input layer, mapping tokens to vectors that are then passed forward layer by layer. As depth increases, the information in the original input tokens is continually compressed or transformed by intermediate representations. Deeper networks can build more complex semantic relationships, but they may also weaken the direct contribution of the original input.

    The basic idea of layered embeddings is to not restrict embedding information to the bottom of the model, but to inject or fuse it at multiple network layers. This lets original input information participate in computation continuously at different depths, improving the representational ability of models with respect to local details, short contexts, and small on-device models.

    3.2 Engineering value

    In on-device scenarios, models are often shallow and capacity-limited. If they rely on bottom embeddings only, they may need more layers to recover and retain input information. Layered embeddings act as a denser information path within a limited depth, helping improve:

    • Short-text understanding;
    • Low-resource language tasks;
    • Few-shot instruction following;
    • Alignment between visual or audio tokens and text tokens;
    • Semantic retention in small-parameter models.

    3.3 Inference engine adaptation challenges

    Although the effect of layered embeddings is clear, it increases engineering complexity:

    1. Additional embedding table overhead
      Layered embeddings may require different embedding tables or projection matrices at different layers. Storing all of them at high precision increases memory consumption.

    2. Per-layer fusion operators
      Each layer may perform embedding injection, addition, gating, or projection fusion. The inference engine must support these fusion operators, otherwise they can only be decomposed into many small operators, hurting performance.

    3. Memory layout management
      If every layer must read original input tokens or modality tokens, the engine needs a unified data layout to avoid repeated copies.

    4. Quantization difficulty
      Embedding tables are usually the largest memory consumers. Poorly quantized layered embeddings can amplify error, with a more visible effect on small models.

    3.4 Practical recommendations

    In real adaptation work, the following strategies are worth applying:

    • Store embedding tables grouped by layer to avoid repeated runtime conversion;
    • Apply low-bit quantization to embedding tables, but evaluate its impact on first-layer and deep-layer outputs separately;
    • Fuse “embedding lookup + projection + fusion” into a single composite operator wherever possible;
    • On-device, prioritize short-context performance instead of blindly extending context length;
    • If device memory is tight, consider keeping high-precision embeddings only for critical layers and using quantized versions for the rest.

    Illustrative pseudocode:

    1. for layer in model.layers:
    2. hidden = transformer_forward(layer, hidden)
    3. if layer.uses_layer_embedding:
    4. layer_emb = lookup(layer.embedding_table, input_tokens)
    5. layer_emb = project(layer_emb, layer.projection_matrix)
    6. hidden = fuse(layer, hidden, layer_emb)

    This logic looks simple, but in a real engine, memory access patterns and operator fusion are where the optimization effort must go.


    4. Key Mechanism 2: KV Cache Sharing and Heterogeneous Caching

    4.1 Why KV cache matters

    In autoregressive generation, each step produces a new token. To avoid recomputing historical context, the inference engine normally caches the Key and Value of each layer. That cached state is the KV cache.

    For on-device devices, the KV cache is one of the main sources of memory consumption. The longer the context, the larger the batch, and the more layers there are, the more visible the KV cache footprint becomes. Compressing, sharing, and reusing the KV cache is therefore a central problem in on-device LLM inference optimization.

    4.2 From per-layer independent caches to multi-layer sharing

    Early models typically use an independent cache per layer. This is simple to implement but carries higher memory overhead. On-device transitional models began letting some layers share a KV cache to reduce duplicate storage.

    Next-generation on-device models extend the sharing scope further and introduce more sophisticated designs, such as:

    • Multiple layers sharing the same cache group;
    • Different layers using different numbers of KV heads;
    • Some layers caching only Keys without a separate Value cache;
    • Some structures using a simplified K=V projection;
    • Cache layouts that are no longer uniform regular tensors, but heterogeneous structures.

    These designs can substantially reduce memory consumption, but they also make inference engine implementation considerably more complex.

    4.3 Engineering challenges of heterogeneous KV caches

    Heterogeneous caching means different layers may have different cache dimensions, head counts, sharing arrangements, or storage formats. If the engine still assumes that “all layers have the same cache structure”, the following problems appear:

    1. Difficult memory alignment
      When layer cache sizes differ, paging or pooling strategies must be redesigned.

    2. Reduced batching efficiency
      If some layers share caches and others do not, cache management for batched requests becomes much more complicated.

    3. Harder prefix reuse
      In multi-turn conversations, prefix KV caches can be reused. But if cache structures differ per layer, reuse logic must be modeled per layer.

    4. Inconsistent quantization strategies
      Some layers may suit 8-bit caching while others need higher precision. The engine must support mixed-precision caches.

    4.4 Implementation recommendations

    For shared and heterogeneous caches, the recommendation is to introduce a “cache layout abstraction layer” for unified management:

    1. cache_spec = {
    2. layer_id: {
    3. num_kv_heads,
    4. head_dim,
    5. cache_dtype,
    6. shared_group,
    7. store_value
    8. }
    9. }

    The engine builds the cache specification at initialization and allocates memory according to it. During execution, the attention layer only cares about the current layer’s cache logic, while a cache manager handles physical storage.

    Specific recommendations include:

    • Maintain reference counts or lifecycle management for shared caches;
    • Split cache allocation into static reservation and dynamic growth;
    • For on-device scenarios, prefer fixed-size block caches to reduce fragmentation;
    • For high-concurrency serving, use paged cache management;
    • Use independent quantization parameters per layer cache instead of a single global setting;
    • During accuracy evaluation, separately check how first-layer, last-layer, and shared-layer caches affect output quality.

    5. Key Mechanism 3: Native Multimodal Support

    5.1 Multimodality is not simple concatenation

    Early multimodal designs attached vision and audio encoders as external modules and concatenated their features into the language model. This is easy to implement, but it has several clear drawbacks:

    • Weak deep fusion between modalities;
    • High peak memory on device;
    • Long inference chains and complex scheduling;
    • Difficulty applying quantization and optimization in a unified framework.

    Next-generation on-device LLMs lean toward native multimodal architectures, handling text, vision, and audio tokens uniformly inside the model. After each modality passes through its own encoder, it is mapped into a shared representation space and then enters the language model backbone.

    5.2 The typical vision pipeline

    Vision input typically involves these steps:

    1. Image preprocessing, including resizing, normalization, splitting, or chunking;
    2. The vision encoder extracting local and global features;
    3. A pooling or compression module reducing the number of visual tokens;
    4. A projection layer mapping visual features into the language model’s hidden space;
    5. Concatenation with text tokens before entering the language model.

    On device, the number of visual tokens cannot be too large, otherwise first-token latency rises sharply and memory consumption grows. The vision encoder therefore often has to balance accuracy and efficiency.

    5.3 The typical audio pipeline

    Audio tends to emphasize streaming far more than vision. A typical flow includes:

    1. Audio framing and feature extraction;
    2. Streaming audio encoding;
    3. Temporal alignment or downsampling;
    4. Mapping into the language model’s representation space;
    5. Joint modeling with the text instruction.

    The engineering difficulty for audio lies in real-time behavior. If the inference engine cannot support streaming input, audio tasks suffer from high latency and a poor experience.

    5.4 Key issues in multimodal adaptation

    Multimodal inference is not as simple as “connecting three models together”; it requires solving unified inference graphs, modality routing, resource scheduling, and accuracy control.

    Common problems include:

    • The vision encoder’s operator set is incompatible with the language model’s;
    • The audio module cannot work with the cache mechanism;
    • Positional encoding rules are inconsistent across modalities;
    • Modality fusion layers lack efficient operator support;
    • Accuracy drops noticeably for vision or audio tasks after quantization.

    5.5 Practical recommendations

    For on-device multimodal deployment, follow these principles:

    • Export vision and audio encoders as separate subgraphs, then connect them to the language model backbone graph;
    • Set an upper bound on the number of visual tokens to avoid excessive peak memory on device;
    • Evaluate streaming latency for audio tasks separately rather than looking only at offline accuracy;
    • Keep higher precision on the encoders’ output projection layers during quantization;
    • Build modality-specific evaluation sets so that text metrics alone do not represent overall capability;
    • Define a unified input description structure for multimodal inputs to make scheduling and caching easier.

    Illustrative pseudocode:

    1. text_tokens = tokenize(text_prompt)
    2. vision_tokens = vision_encoder(image)
    3. audio_tokens = audio_encoder(audio_stream)
    4. multimodal_tokens = merge_by_modal_priority(
    5. text_tokens,
    6. vision_tokens,
    7. audio_tokens
    8. )
    9. hidden = language_model.forward(multimodal_tokens)

    The key point here is that merge_by_modal_priority must match the modality fusion approach used during training, otherwise output quality will drift.


    6. Four Major Challenges of Inference Engine Adaptation

    Open-source on-device LLMs are not the same as traditional small vision models or classic NLP models. They combine language modeling, multimodality, caching, and layered embeddings in one structure. Adaptation typically runs into four classes of challenges.

    6.1 Insufficient operator coverage

    The model structure may contain:

    • Grouped attention;
    • Rotary positional encoding;
    • Layered embedding fusion;
    • Dynamic pooling;
    • Streaming audio convolution;
    • Vision chunking;
    • Sparse expert routing;
    • Multimodal fusion normalization.

    If the inference engine lacks these operators, it can only fall back to stitching together basic operators, which reduces performance and increases memory copies.

    The recommended approach is to maintain an “operator whitelist” and a “fallback mechanism”. Fuse core operators, provide generic fallback for non-core ones, and generate an operator coverage report at the export stage.

    6.2 Irregular memory layout

    Shared caches, heterogeneous head counts, layered embeddings, and vision pooling all make memory layouts irregular. If the engine assumes every tensor is contiguous, regular, and uniformly formatted, extra reordering and copying follow.

    Optimization directions include:

    • Use structured memory pools;
    • Manage caches in blocks or pages;
    • Store tensors of different dtypes separately;
    • Prefetch or keep frequently accessed tensors resident;
    • Reduce implicit reshapes and transposes inside operator implementations.

    6.3 Hard to unify quantization accuracy

    LLM quantization generally involves weights, activations, KV cache, and embedding tables. On-device models want low-bit quantization to save memory, but sensitivity varies widely across modules.

    Broadly speaking:

    • The language model backbone is relatively sensitive to weight quantization;
    • Attention output projections are relatively sensitive to quantization;
    • Embedding tables are relatively sensitive to low-bit quantization;
    • KV cache clearly affects context-heavy tasks;
    • Vision and audio encoder output layers should not be over-compressed.

    For this reason, applying one quantization strategy to every module is not advisable. A more reasonable approach is layer-wise, category-wise, and task-wise evaluation.

    6.4 Dynamic shapes causing performance fluctuation

    On-device applications frequently see varying input lengths, and multimodal tasks add dynamic dimensions such as image size, audio duration, and the number of visual tokens. If the engine handles dynamic shapes poorly, you may see:

    • Frequent recompilation;
    • Memory allocation jitter;
    • Reduced batching efficiency;
    • Unstable first-token latency.

    The recommendation is to group common length ranges into shape buckets, discretizing continuous variation into a few fixed tiers, which balances flexibility and performance.


    7. How to Evaluate the On-Device Experience of an Open-Source LLM

    For developers, judging whether an open-source on-device LLM is usable should not rely on the capability claims in its marketing material. A reproducible evaluation system is needed, covering the following dimensions.

    7.1 Functional correctness

    Functional correctness comes first. Verify that the model can complete the following on the target device:

    • Text continuation;
    • Instruction following;
    • Short-text question answering;
    • Image description;
    • Joint image-text question answering;
    • Audio recognition or audio understanding;
    • Context retention across multiple turns.

    If the exported model works only on simple tasks and clearly degrades on complex instructions or multimodal tasks, that points to problems in operator mapping, cache management, or quantization strategy.

    7.2 Performance metrics

    Performance evaluation should cover multiple metrics, not a single speed number.

    Recommended to record:

    1. First-token latency: time from completed input to the first generated token;
    2. Generation speed: tokens generated per second;
    3. Peak memory: maximum memory consumption during execution;
    4. Resident memory: memory used while idle;
    5. Power behavior: average and instantaneous peak power during sustained inference;
    6. Thermal behavior and throttling: whether performance decays over long runs;
    7. Concurrency stability: whether latency jitters under multiple requests or continuous conversations;
    8. Cold start time: model loading, cache initialization, and graph compilation cost.

    7.3 Accuracy and quality metrics

    For text tasks, consider:

    • Instruction adherence rate;
    • Summarization completeness;
    • Factual consistency;
    • Multi-turn context consistency;
    • Correctness of code or structured output;
    • Recall of key information in long contexts.

    For multimodal tasks, evaluate separately:

    • Image description accuracy;
    • Visual question answering correctness;
    • Audio content recognition accuracy;
    • Instruction following under mixed multimodal input;
    • How the proportion of different modalities affects results.

    7.4 Pre- and post-quantization comparison

    Quantization is an important step in on-device deployment, but it must be evaluated carefully. Build a comparison table covering pre- and post-quantization results across:

    • Different context lengths;
    • Different input modalities;
    • Different decoding strategies;
    • Different layer cache strategies;
    • Different vision or audio input lengths;
    • Different precision formats.

    If short-text tasks stay stable after quantization but long-text or multimodal tasks degrade clearly, the places to check are KV cache quantization, embedding table quantization, and the precision of modality fusion layers.


    For teams that want to deploy an open-source on-device LLM in their own application, the following sequence is recommended.

    8.1 Step 1: Analyze the model structure

    First, identify which structures the model contains:

    • Number of attention layers;
    • Whether KV cache is shared;
    • Whether heterogeneous KV heads exist;
    • Whether layered embeddings are used;
    • Whether there is a vision encoder;
    • Whether there is an audio encoder;
    • Whether a sparse expert structure is included;
    • Whether custom normalization or positional encoding is included.

    Only after structure analysis can you determine whether the target inference engine needs additional adaptation.

    8.2 Step 2: Check operator coverage

    Before export, check whether all operators the model uses are supported by the target engine. For unsupported operators, assess whether an equivalent substitution is possible or whether a custom operator must be implemented.

    Key checks include:

    • Normalization;
    • Attention;
    • Positional encoding;
    • Cache updates;
    • Embedding lookup;
    • Modality projection;
    • Pooling;
    • Streaming audio convolution;
    • Sparse routing.

    8.3 Step 3: Design the cache strategy

    Based on the model’s cache structure, design a cache manager. For on-device scenarios, prioritize low memory for a single request; for server-side scenarios, prioritize batching and prefix reuse.

    The cache strategy should cover:

    • Cache allocation;
    • Cache release;
    • Cache sharing;
    • Cache quantization;
    • Cache paging;
    • Multi-turn reuse;
    • Failure recovery.

    8.4 Step 4: Quantization calibration

    Calibration should not rely on a single dataset. Include at least:

    • Pure text samples;
    • Long-text samples;
    • Image-text samples;
    • Audio samples;
    • Multi-turn conversation samples;
    • Boundary-length samples.

    After calibration, separately compare quality, memory consumption, and inference speed before and after quantization.

    8.5 Step 5: Performance stress testing

    Stress tests should cover different loads:

    • Short input, short output;
    • Long input, short output;
    • Short input, long output;
    • Long input, long output;
    • Single-modality input;
    • Multimodal input;
    • Continuous conversation;
    • Concurrent requests.

    Stress testing surfaces real-world problems such as peak memory, cache jitter, modality latency, and throttling over long runs.


    9. Recommendations by Scenario

    9.1 On-device scenarios

    On-device hardware is usually constrained by memory, power, and thermals. Prefer smaller model sizes and adopt these strategies:

    • Prioritize solid text capabilities;
    • Control visual input resolution;
    • Cap the number of visual tokens;
    • Use streaming input for audio tasks;
    • Use low-bit weights and moderately low-bit cache;
    • Avoid overly long context windows;
    • Build lightweight caching or result reuse for common intents.

    On-device models should not blindly pursue “large and all-encompassing”; they should be optimized specifically for high-frequency tasks.

    9.2 Desktop scenarios

    Desktop hardware usually has more memory and compute and can support richer multimodal capabilities. Recommended:

    • Enable mid-sized models;
    • Support higher-resolution image input;
    • Provide real-time audio transcription or understanding;
    • Enable prefix caching for multi-turn conversations;
    • Build indexing and retrieval-augmented mechanisms for frequently used documents;
    • Keep user privacy data protected on the local device as much as possible.

    The key for desktop applications is balancing capability against responsiveness, avoiding sacrifices in interaction fluidity in pursuit of higher capability.

    9.3 Lightweight server scenarios

    For internal services or lightweight cloud applications, throughput and concurrency can come first. Recommended:

    • Use batched inference;
    • Enable shared prefix caching;
    • Cache results for high-frequency requests;
    • Deploy vision and audio encoders independently or scale them independently;
    • Set reasonable limits for long-context requests;
    • Establish monitoring metrics including latency, memory, failure rate, and task quality.

    Server-side scenarios cannot focus only on single-request speed; peak stability, resource utilization, and degradation strategies matter too.


    10. Common Pitfalls and Cautions

    Pitfall 1: Looking only at parameter count

    Parameter count reflects model capacity, not adaptation difficulty on device. Some models are not large in parameters, yet their adaptation cost is higher because of cache sharing, heterogeneous structures, layered embeddings, and similar designs.

    Pitfall 2: Looking only at a single task’s results

    Good text performance does not mean multimodal tasks are stable. Vision and audio tasks are more sensitive to encoder operators, input preprocessing, and modality fusion layers.

    Pitfall 3: Over-quantization

    Lowering precision excessively to save memory can clearly degrade long-context, multimodal, or instruction-following tasks. Quantization must be evaluated together with the tasks it will serve.

    Pitfall 4: Ignoring cache management

    Many on-device model problems come not from the model itself but from unreasonable cache strategy. Poor design of cache allocation, sharing, reuse, and release leads to memory spikes or abnormal generation speed.

    Pitfall 5: Ignoring long-run stability

    Good results in short tests do not mean stable long-running behavior. Sustained inference can cause heat buildup, throttling, memory fragmentation, and cache growth, so long-duration stress testing is necessary.


    11. Summary

    The value of next-generation open-source on-device LLMs lies not in simply raising parameter count, but in improving model efficiency under limited resources through architectural designs such as layered embeddings, KV cache sharing, heterogeneous caching, and native multimodal input. These models open up more possibilities for on-device agents, local knowledge assistants, multimodal interaction applications, and privacy-sensitive scenarios.

    From an engineering perspective, however, these models are not “ready to use once exported”. Developers need to understand their internal structure and assess the inference engine’s operator coverage, cache management, quantization strategy, and multimodal scheduling capability. What truly determines the user experience is often not how capable the model is, but whether the inference pipeline is complete, resources are controllable, and accuracy stays stable.

    For teams, the recommended practice path is:

    1. First analyze the model structure and identify special mechanisms;
    2. Then check operator support and memory layout;
    3. Next design cache and quantization strategies;
    4. Then validate the real experience through multi-dimensional evaluation;
    5. Finally, optimize separately for on-device, desktop, or server scenarios.

    Only by evaluating model capability, hardware constraints, and engineering implementation together can you build on-device LLM applications that are genuinely reliable, deployable, and able to evolve over time.