On-Device Multimodal LLM Architecture Evolution and Inference Adaptation Guide

    This article reviews key architecture mechanisms in recent open-source multimodal large models, including per-layer embeddings, cross-layer KV cache sharing, and heterogeneous KV heads, and explains how these mechanisms affect inference engine design. It also provides practical adaptation checkpoints, deployment strategies, and major risks for on-device and edge deployment.

    In recent years, architecture innovation in open-source large models has accelerated noticeably. Models no longer rely only on increasing parameter count to improve capability. Instead, they balance capability and resource footprint through mechanisms such as per-layer embeddings, cross-layer shared caches, and heterogeneous attention heads. For inference engine developers, these mechanisms introduce new adaptation work: operators must be redesigned, memory must be replanned, and validation methods must be stricter. This article reviews several key mechanisms, explains their impact on inference, and provides actionable checkpoints.

    One point should be clarified first: specific parameters differ considerably across model versions. The numbers of layers, experts, and other values mentioned in this article are not intended as universal conclusions. In actual deployment, the officially released model configuration files and the implementation of the corresponding inference framework should be treated as authoritative.

    1. Architecture Mechanism Analysis

    1.1 Per-Layer Embeddings (PLE)

    Per-layer embeddings mean that each layer can read an embedding representation associated with that layer. In early transitional versions, such mechanisms usually injected information directly into hidden states through table lookup. Newer versions add a linear projection after table lookup and then feed the combined result into the network. The purpose is to give layers at different depths more discriminative input features and reduce the risk of gradual information loss in deep networks.

    For an inference engine, the key is to fuse table lookup and projection into a single operator to reduce write-back and reads of intermediate tensors. Memory access often becomes a bottleneck before computation does, so this step has a significant impact on on-device devices.

    1.2 Cross-Layer KV Cache Sharing

    KV cache memory usage grows with context length. Sharing the same KV cache across multiple adjacent layers can significantly reduce this footprint and allow devices with small memory to handle longer contexts. The number of shared layers varies by model version and must be read from the configuration; it cannot be assumed to be a fixed value.

    The sharing mechanism introduces two types of runtime issues. First, during concurrent or streaming inference, the read and write order of multiple requests to the same cache must be controlled; otherwise, results may be inconsistent. Second, data dependencies exist among shared layers. If scheduling is improper, the compute pipeline will wait for cache readiness, and throughput will drop.

    1.3 Heterogeneous KV Heads and K=V Projection

    In conventional attention, all layers usually use the same number of KV heads. Heterogeneous designs allow different layers to use different numbers of KV heads so that capacity can be allocated across different depths. Some specifications may also omit a separate v_proj and let K and V share the same projection result. This approach can reduce weight size and computation, but whether it is used and which specifications it applies to must also follow the official configuration.

    The engine needs to read the KV head configuration layer by layer and determine the cache layout accordingly. To reuse the same memory block, first confirm that the computational semantics are truly equivalent, then compare element by element against the output of a reference implementation.

    1.4 Vision and Audio Encoding

    A common approach for the vision part is ViT plus a pooling module, used to align image features to the language model’s embedding space. Dynamic-resolution input changes the number of patches, so an input size range must be defined and memory must be preallocated according to that range.

    The audio part commonly uses Conformer-like structures, balancing local features and global modeling. For streaming input, chunk size directly affects first-packet latency and the accuracy of audio-text temporal alignment. A trade-off is needed between the two, and alignment results should be validated with timestamped samples.

    2. Inference Engine Adaptation Points

    2.1 QKV Norm and attn_scale

    If the model normalizes Q, K, and V and uses a fixed scaling factor, the framework can fold normalization and scaling into the weights of the preceding matrix multiplication, reducing the number of separate operator calls. However, folding changes the numerical computation path. Before implementation, confirm that the actual attn_scale value comes from the configuration file, and compare output errors before and after folding on multiple random inputs.

    2.2 Dual RoPE Positional Encoding

    The targets and frequency parameters of dual positional encoding must be confirmed from the model implementation. The fused operator should support both injection paths at the same time and avoid extra tensor copies caused by concatenating intermediate results. During validation, first generate layer-by-layer intermediate results with the reference implementation, then align them layer by layer.

    2.3 MoE Dynamic Routing

    Sparse activation models have a large total parameter count, but each token uses only a subset of experts. Performance bottlenecks usually appear in Top-K selection, expert grouping, and grouped matrix multiplication. The number of experts and the K value follow the configuration. During optimization, first microbenchmark the routing stage to confirm its proportion of total time, then decide whether to invest in instruction-level optimization, such as using NEON or AVX to accelerate Top-K computation.

    Checklist

    • Whether output errors on fixed inputs before and after operator fusion are within an acceptable range
    • Whether the KV cache layout changes with each layer’s head configuration and remains correct under dynamic shapes
    • Whether the read and write order of shared caches is covered by tests in multi-concurrency scenarios
    • Whether the precision drop on the target task evaluation set after quantization is acceptable
    • Whether benchmark metrics include first-token latency, throughput, and peak memory
    • Whether regression cases are rerun after framework or driver version upgrades

    3. Deployment Strategy

    Before deployment, determine three conditions: the device memory ceiling, the acceptable first-token latency, and the precision drop threshold. With these three conditions, model selection has a basis.

    • On-device mobile devices: prioritize small specifications. When quantizing to INT4 or INT8, first measure precision on the target task, then decide the quantization level. If memory is tight, shorten the context length first, then consider switching to a smaller model.
    • Desktop and edge nodes: larger specifications can be used. At this point, the main constraint is the number of concurrent sessions, which is limited by KV cache memory usage and must be estimated based on actual load.
    • Cloud-edge collaboration: complex cross-modal tasks are handled in the cloud, while lightweight understanding tasks are offloaded to the edge. Both ends should use the same model version and preprocessing pipeline; otherwise, results are difficult to align.

    Each plan should have a fallback path. For example, when an edge device has insufficient memory, automatically switch to a smaller specification or reduce the context limit.

    4. Major Risks

    • Quantization precision drop: This is not easy to notice on some tasks and requires a dedicated evaluation set.
    • Insufficient on-device memory: Dynamic-resolution images and long audio can suddenly increase memory usage.
    • Cross-modal temporal mismatch: Audio-text alignment errors often appear only on specific samples.
    • Framework version differences: The same model may produce slightly different numerical results across framework versions.

    Conclusion

    Mechanisms such as per-layer embeddings, cross-layer KV cache sharing, and heterogeneous KV heads make it possible to run models on resource-constrained devices, and they also make inference engine adaptation more complex. During adaptation, first read the official configuration and clarify the actual parameters of each mechanism; then use a reference implementation for layer-by-layer alignment; finally validate results with four metrics: latency, throughput, memory, and precision. Following this process, teams can find a suitable deployment approach between on-device and desktop environments.