Adapting and Evaluating Heterogeneous Architectures for Edge-Side Multimodal Large Models
Multimodal large models spanning from edge to server environments often rely on diverse architectural mechanisms rather than simple parameter scaling. This article explores the evolution of these architectures, breaks down key mechanisms such as per-layer embeddings, grouped KV cache sharing, and heterogeneous attention heads, and provides a reusable methodology for inference engine adaptation and evaluation.
Adapting and Evaluating Heterogeneous Architectures for Edge-Side Multimodal Large Models
I. Background: Multiple Specifications Are Not Just Parameter Scaling
For large model series targeting edge devices to servers, a common practice is to offer multiple parameter specifications: an edge version with hundreds of millions of active parameters, a mobile/desktop version with billions of parameters, and a server version with tens of billions of parameters. Intuitively, these specifications seem to be merely a scaling of layers, hidden dimensions, and attention heads. However, in actual inference adaptation, the real engineering complexity often arises not from the parameter scale, but from the fact that different specifications employ different combinations of architectural mechanisms.
For example, to control memory bandwidth and time-to-first-token latency, edge specifications might introduce per-layer embeddings, grouped KV cache sharing, lightweight vision encoders, and activation sparsity. Desktop specifications might retain a more complete vision encoder with a pooler. Server specifications might use a Mixture of Experts (MoE) to increase capacity while adopting heterogeneous KV heads, K=V shared projection, and dual positional encoding to balance throughput and VRAM. Consequently, the inference engine cannot assume that “all specifications share the same graph structure and memory layout.” Instead, it must treat model export, operator fusion, KV management, multimodal preprocessing, and quantization strategies as configurable modules.
This article does not target any specific product. Instead, it abstractly discusses the general architectural patterns of this class of multi-specification multimodal large models and provides a reusable approach for inference engine adaptation and evaluation.
II. Architecture Evolution Abstraction: From Unified Structure to Mechanism Combination
From early multimodal models to edge-optimized versions, and then to the new multi-specification forms, a clear evolution path can be observed: attention mechanisms move from a single structure to mixed attention; KV Cache moves from independent per-layer to grouped sharing; word embeddings move from globally shared to per-layer lookup injection, and then to a fusion of lookup and projection; normalization expands from Q/K normalization to Q/K/V normalization, introducing explicit attention scaling; some structures begin to adopt K=V shared projection; KV head counts are no longer unified across the entire model but become heterogeneous per layer or module; vision encoders evolve from general Vision Transformers to a hybrid of lightweight convolutions and Transformers with poolers; audio encoders adopt a hybrid structure of convolutions and self-attention; server specifications introduce sparse experts.
| Mechanism Dimension | Phase A: General Form | Phase B: Edge-Optimized Form | Phase C: New Multi-Spec Form |
|---|---|---|---|
| Attention | Mixed attention | Mixed attention | Mixed attention + explicit scaling |
| KV Cache | Per-layer independent | Grouped sharing | Finer-grained grouped sharing |
| Embeddings | Shared embedding | Per-layer lookup direct injection | Lookup + projection fusion |
| Normalization | Q/K normalization | Q/K/V normalization | Q/K/V normalization + scaling factor |
| V Projection | Independent V projection | Independent V projection | Partial K=V, no independent V projection |
| KV Heads | Unified across model | Unified across model | Layer/module heterogeneous |
| Vision Encoding | General Vision Transformer | Lightweight Conv encoder | Vision Transformer + pooler |
| Audio Support | None | Conv self-attention encoder | Improved audio encoder |
| Expert Structure | None | None | Sparse Mixture of Experts |
| Specific Mechanisms | — | Aux modules, activation sparsity | K=V, heterogeneous KV heads, dual positional encoding |
The significance of this table is that inference engine adaptation should shift from “single-model adaptation” to “mechanism matrix adaptation.” Each mechanism corresponds to different operator combinations, memory layouts, and numerical strategies. You cannot simply reuse the same implementation based solely on parameter scaling.
III. Key Mechanism Breakdown and Adaptation Strategies
3.1 Per-Layer Embeddings: From Lookup Direct Injection to Projection Fusion
Traditional shared embeddings usually perform a lookup only at the input layer, after which all layers share the same hidden representation. Per-layer embeddings inject the vocabulary lookup results per layer, allowing each layer to obtain embedding information relevant to its current depth. A common practice in the edge-optimization phase is “lookup direct injection,” where the lookup result is added directly to the hidden state. The new form further introduces a small projection, mapping the lookup result to the current layer’s hidden space before fusion.
This mechanism impacts the inference engine in three main ways. First, the embedding table can be very large, requiring sharding, low-bit compression, and on-demand prefetching to avoid excessive memory peaks on edge devices. Second, per-layer injection changes the graph structure; you cannot simply fold the embedding layer into the first layer. You must insert lookup and fusion operators into each layer or layer group. Third, projection fusion introduces small matrix multiplications, which should be fused with adjacent normalization and residual addition as much as possible to reduce kernel launch overhead.
# Pseudocode: Lookup and projection fusion for per-layer embeddingsdef inject_per_layer_embedding(hidden, token_ids, layer_id, table_shard, proj):e = table_shard[token_ids] # Lookup, can be low-bit compressed or shardeddelta = proj(e, layer_id) # Small projection mapping to current layer spacereturn hidden + delta # Intra-layer additive injection
During adaptation, it is recommended to split the per-layer embedding table by layer groups, combined with memory prefetching and asynchronous copying. For edge specifications, prioritize low-bit quantization and verify the impact of lookup quantization errors on generation quality.
3.2 KV Cache Sharing and Heterogeneous KV Heads
KV Cache is the primary consumer of VRAM and bandwidth during the decoding phase. The core idea of grouped sharing is that multiple layers share the same set of K/V caches instead of each layer allocating its own. The more layers sharing the cache, the lower the cache footprint, but the inter-layer representational differences might be compressed. Therefore, a “layer-to-cache-group” mapping must be established based on the model configuration.
Heterogeneous KV heads further break the assumption of a unified head count across the entire model: different layers or modules may use different numbers of KV heads. The inference engine cannot allocate a single block of cache based on one head count; it must record the head count, head dimension, and sharing relationships per layer group. If a structure adopts K=V shared projection, only one copy of K needs to be saved during writing, and it is mapped to both K and V during reading, significantly reducing cache bandwidth.
# Pseudocode: Managing KV cache by layer group, compatible with sharing and K=Vclass LayerGroupKVCache:def __init__(self, layer_to_group, group_head_num, head_dim, max_len, dtype, share_kv=False):self.layer_to_group = layer_to_groupself.share_kv = share_kvself.k = [alloc((group_head_num[g], max_len, head_dim), dtype)for g in range(len(group_head_num))]self.v = None if share_kv else [alloc((group_head_num[g], max_len, head_dim), dtype)for g in range(len(group_head_num))]def write(self, layer_idx, pos, k, v=None):g = self.layer_to_group[layer_idx]self.k[g][:, pos, :] = kif not self.share_kv:self.v[g][:, pos, :] = vdef read(self, layer_idx, start, end):g = self.layer_to_group[layer_idx]k = self.k[g][:, start:end, :]v = k if self.share_kv else self.v[g][:, start:end, :]return k, v
In engineering, it is recommended to use paged or block-based KV management, isolating cache groups per request. Shared cache groups require reference counting and lifecycle management to prevent mutual pollution among concurrent requests.
3.3 Mixed Attention, Normalization, and Dual Positional Encoding
Mixed attention typically combines local and global attention across different layers or heads to balance long context and computational efficiency. Dual positional encoding may use different positional encoding strategies for different frequency bands or modules. During adaptation, positional parameters must be passed correctly to avoid positional offset errors under cache reuse and dynamic shapes.
Q/K/V normalization and explicit attention scaling are critical for numerical stability. The inference engine should fuse normalization and pre-attention scaling into the same operator chain to reduce intermediate tensor writebacks. During low-bit quantization, the activated range after normalization must be calibrated to prevent conflicts between the scaling factor and the quantization scale. For the K=V structure, the attention kernel must also handle the index mapping of “reading one cache, logically two views” to avoid additional copying.
3.4 Multimodal Encoders and Sparse Experts
Multimodal support typically includes a vision encoder and an audio encoder. The vision side might be a Vision Transformer with a pooler, while the audio side might be a hybrid of convolution and self-attention. The adaptation focus is not on the main model but on the preprocessing pipeline: image resizing, patching, positional encoding, pooling, as well as audio resampling and feature extraction should all be executed asynchronously with the main model decoding to prevent end-to-end time-to-first-token latency from being dragged down by preprocessing.
Sparse Mixture of Experts introduces routing, load balancing, and expert caching issues. The inference engine needs to support dynamic expert selection, expert merging computation under batched requests, and hot expert caching. For edge specifications, deterministic expert routing should be prioritized to avoid frequent graph recompilation caused by dynamic branching.
IV. Engineering Methods for Inference Engine Adaptation
First, establish a mechanism description file. Write layer groups, KV sharing relationships, KV head counts, whether K=V is used, per-layer embedding table sharding, vision/audio encoder structures, and expert routing parameters into verifiable configurations. Perform consistency checks during the export phase.
Second, perform operator fusion and memory planning. Lookup and projection for per-layer embeddings, normalization and scaling, K=V read mapping, and vision poolers should all be fused as much as possible. KV cache should be allocated by layer groups to reduce fragmentation.
Third, formulate quantization strategies per module. Embedding tables, vision encoders, audio encoders, attention, and expert layers have different sensitivities to precision and should be calibrated separately. Edge specifications prioritize low-bit weight and KV quantization, while server specifications prioritize maintaining numerical stability for attention.
Fourth, build an evaluation pipeline. Fix input length, output length, batch size, and concurrency. Record time-to-first-token, decoding throughput, peak memory, KV cache footprint, operator fallback count, and precision differences. During the export phase, also track the number of graph splits and unsupported operator counts.
Fifth, implement canary releases and observability on the deployment side. If deploying on cloud platforms like Baidu AI Cloud, you can leverage general-purpose services such as container platforms, object storage, and logging services to build a cohesive pipeline for model export, evaluation, canary release, and observability. For edge devices, prioritize verifying memory peaks and long-context stability. For desktop and server specifications, focus on verifying heterogeneous KV head layouts, expert load balancing, and asynchronous multimodal pipelines.
V. Usage Recommendations and Conclusion
For edge specifications, it is recommended to prioritize enabling per-layer embedding table compression, grouped KV cache sharing, and low-bit quantization. Control the concurrency of vision/audio preprocessing to avoid compounding memory peaks. For desktop specifications, focus on optimizing the memory layout of heterogeneous KV heads and K=V to reduce cache read/write copies. For server specifications, treat sparse expert routing, dual positional encoding, and mixed attention as independent observable modules, conducting stress testing and regression separately.
Overall, the adaptation difficulty for multi-specification multimodal large models has shifted from “parameter scaling” to “mechanism combination.” The inference engine needs to organize its implementation around layer groups, cache groups, and module configurations, breaking down per-layer embeddings, KV sharing, heterogeneous heads, K=V, dual positional encoding, and multimodal encoders into composable capabilities. These are then verified for performance and precision through a unified evaluation methodology. Only by explicitly modeling architectural differences can you achieve predictable latency, memory, and throughput performance across all scenarios from edge to server.
