Inference Engine Adaptation for On-Device Multimodal LLMs: PLE, Cross-Layer KV Cache Sharing, and MoE
This article describes the process of adapting an inference engine to a new family of open-source on-device multimodal large models. It reviews the architectural evolution from an earlier transitional multimodal model and details implementation considerations for per-layer embedding injection, cross-layer KV cache sharing, heterogeneous KV heads, K=V projection sharing, multimodal encoders, and a sparse MoE variant. It also offers practical guidance on weight export, layer-wise numerical validation, end-to-end generation comparison, performance benchmarking, and memory analysis across mobile, desktop, and server deployment targets.
Inference Engine Adaptation for On-Device Multimodal LLMs: PLE, Cross-Layer KV Cache Sharing, and MoE
Recent open-source on-device model series have shown a high density of architectural innovation. The new generation spans several-billion-parameter on-device specifications to desktop-class 30-plus-billion-parameter specifications, covering deployment scenarios from phones and tablets to servers. More importantly, these specifications are not simple parameter scalings; they combine different architectural mechanisms. That creates significant challenges for inference engine adaptation. This article records the complete process of adapting an inference engine to this model family, focusing on three distinctive mechanisms: per-layer embedding injection, cross-layer KV cache sharing, and multimodal support. It also provides practical recommendations for export and evaluation.
1. Architecture Evolution: Understanding Inherited and New Mechanisms
To adapt a model family, the first step is to understand its architectural evolution. The series did not appear from scratch. Its predecessor was a transitional multimodal model designed specifically for on-device devices, and it first introduced key mechanisms such as per-layer embeddings and KV sharing. The new generation inherits these mechanisms and extends them further:
- Per-layer embeddings evolved from direct lookup-table injection to lookup plus projection fusion.
- The number of layers sharing KV cache increased substantially.
- Some specifications introduced key-value shared projection, where K and V share weights and the independent V projection layer is removed.
- Heterogeneous KV head designs were introduced.
- Dual rotary position embeddings were added.
- The largest specification introduced a mixture-of-experts structure.
For an inference engine, this means it cannot assume that all models in the same series follow a single inference path. Instead, each mechanism should be implemented as a pluggable module and combined dynamically according to the model configuration.
2. Adapting Per-Layer Embedding (PLE)
Mechanism
In a traditional Transformer architecture, a token first passes through a unified embedding layer and is converted into a vector, which is then passed through subsequent layers. Per-layer embedding allows the model to perform additional lookups at several intermediate layers and inject or fuse new embedding information into the hidden state of that layer. The new generation upgrades this to a lookup-plus-projection fusion approach: the vector obtained from the lookup table first passes through a projection matrix and is then added to the current hidden state with a weight.
Engine Adaptation Points
For an inference engine, this mechanism breaks the assumption that the embedding layer is executed only once at the beginning of the network. Adaptation requires the following:
- Operator scheduling: Embedding lookup and projection operators must be allowed to be inserted into intermediate layers, not only at the start of the graph. During computation graph construction, fusion nodes need to be inserted after specified layers according to the configuration.
- Memory management: Per-layer embedding tables significantly increase model size. For on-device scenarios, it is recommended to quantize the embedding tables separately, such as with low-bit integer quantization, and decouple their quantization strategy from that of the backbone weights.
- Weight export: The export tool must use distinct names for per-layer embedding weights and the main embedding table to avoid confusion during conversion.
3. Cross-Layer KV Cache Sharing
Value
KV cache is the main source of memory overhead in autoregressive inference. This model series allows adjacent layers to share the same KV cache. The number of shared layers increased from 10 in the previous generation to 18–20. For on-device devices, this can nearly halve cache occupancy in long-context scenarios and is key to enabling long-text on-device inference.
Engine Adaptation Points
- Cache layout restructuring: The engine’s KV cache manager can no longer allocate memory on a per-layer basis. It must support the concept of cache groups: a group of layers points to the same cache block, and all layers in the group read the same K and V during attention computation.
- Heterogeneous KV heads: Some model specifications use different numbers of KV heads in different layers. Cache allocation must query the head count and dimensions per layer rather than using a single global configuration.
- K=V special form: For specifications where K and V share weights, export can directly eliminate half of the KV projection computation and cache writes. However, the attention operator must support a calling mode where K and V use the same pointer to avoid unnecessary memory copies.
- Compatibility with sliding-window attention: When shared cache is combined with hybrid attention, such as alternating local-window and global attention, the rolling update logic of the cache must be carefully verified. It is recommended to compare long-sequence generation results against a reference implementation using a fixed random seed.
4. Multimodal Support
This model series natively supports visual and audio inputs. The vision side uses a ViT-like encoder plus a pooling layer, while the audio side uses a Conformer-like encoder. Key adaptation points include:
- Encoder-decoder concatenation: The outputs of the vision and audio encoders must pass through a projection layer and be mapped into the language model’s embedding space as prefix tokens. The engine must support mixed concatenation of multimodal embeddings and text embeddings.
- Pooling layer optimization: After pooling, the number of visual tokens is greatly reduced, which directly lowers subsequent attention computation. During export, confirm that the pooling window configuration is correct; otherwise both accuracy and performance will be affected.
- On-device compute considerations: The visual encoder usually accounts for a large share of first-token latency on device. It is recommended to apply an independent quantization and backend scheduling strategy to it, for example by using a compute backend optimized for convolution and matrix multiplication.
5. Adapting the Mixture-of-Experts (MoE) Specification
The largest specification uses a sparse mixture-of-experts structure with 128 experts and Top-8 routing. Although the total parameter count is large, only about 4B parameters are activated per step, so inference cost is close to that of a small model. Adaptation points include:
- On-demand expert weight loading: When on-device memory is limited, expert weights can be placed in flash storage and swapped in on demand, with the routing result determining which experts to load.
- Batch scheduling: After routing, tokens are grouped by expert and processed with grouped matrix multiplication, avoiding the scheduling overhead of a per-expert loop.
- Quantization strategy: Experts can use more aggressive low-bit quantization than attention layers because MoE layers are relatively less sensitive to quantization error.
6. Export and Evaluation Recommendations
A complete adaptation process should include the following validation steps:
- Layer-wise numerical alignment: Use small-scale inputs to compare the exported intermediate-layer outputs with those of the reference framework and locate the source layer of any accuracy deviation.
- End-to-end generation comparison: Fix the temperature and seed, and compare the consistency of long-sequence generation results.
- Performance benchmarking: Measure first-token latency and per-token generation time separately across different context lengths and hardware backends.
- Memory usage analysis: Focus on whether the cache savings from KV sharing match theoretical expectations.
For enterprise users with deployment requirements, a hybrid approach combining cloud inference services and on-device inference can be considered: complex requests use cloud compute, while lightweight requests are completed locally on device. General cloud capabilities such as object storage, container platforms, and monitoring and alerting can support model distribution and runtime status observation, helping balance cost and user experience.
7. Conclusion
The architecture design of this generation of on-device multimodal large models reflects a “designed for inference efficiency” approach: per-layer embeddings reduce activation memory, KV sharing compresses cache, K=V reduces projection computation, and sparse experts control inference cost. For inference engine developers, the key to adaptation is modular design: implement each mechanism as an independent, composable component and drive computation graph assembly through model configuration. This allows a single engine to support deployment requirements across the full series and all specifications.
