Multi-Size Open-Source LLM Inference: Architecture Mechanisms and Engineering Challenges
This article explains why supporting a whole family of open-source LLMs is harder than making a single model work. It outlines the architectural evolution across early, transitional, and new-generation designs, then breaks down the mechanisms that put the most pressure on inference engine engineering — cross-layer KV cache sharing, per-layer embeddings, heterogeneous KV heads and K=V, hybrid attention with QKV normalization, multimodality, and mixture of experts. It also provides practical recommendations for export, staged validation, numerical alignment testing, and deployment across edge, desktop, and server scenarios.
1. Introduction: Why Supporting a Model Family Is Harder Than Supporting One Model
Open-source LLMs are evolving fast toward multiple sizes, multiple modalities, and heterogeneous architectures. A mature series usually spans everything from small on-device models to server-class large models, covering phones, desktops, and even data centers. On the surface, this looks like nothing more than a difference in parameter count. In practice, an inference team quickly discovers the key fact: these sizes are not proportional scalings of an isomorphic architecture. Instead, they combine different mechanisms in attention structure, KV cache strategy, word embedding, modality support, and expert routing.
This means the goal of the inference engine has shifted from “produce correct output for one model” to “run a whole family of structurally different models efficiently.” This article does not discuss any specific product. Instead, it takes a transferable methodology and breaks down several of the most representative mechanisms in modern open-source LLMs — the ones that stress engine engineering the most — along with general recommendations for export, evaluation, and deployment.
2. The Big Picture of Architectural Evolution
Ignoring naming conventions, these model families can roughly be grouped into three stages:
- Early stage: hybrid attention (alternating global and local attention), an independent KV cache per layer, shared word embeddings, and a vision side that relies on a lightweight convolutional or ViT encoder.
- Transitional stage: optimizations introduced for on-device scenarios, including cross-layer KV sharing, per-layer embeddings (PLE), Q/K/V three-way normalization, and activation sparsification, all aimed at “small models that are also multimodal.”
- New-generation stage: further evolution on top of the above — more layers sharing KV cache, word embeddings upgraded from “direct injection” to “lookup plus projection fusion,” attention head structure changing from uniform to heterogeneous, some sizes dropping the independent V projection, dual RoPE introduced, and mixture of experts (MoE) appearing.
This evolution matters because it explains the difficulty: the engineering challenge is that one engine must consume architectural conventions from several generations at once.
3. Key Architectural Mechanisms and How to Adapt Them
3.1 Cross-Layer KV Cache Sharing
Traditionally, each decoder layer keeps its own key-value cache, so memory usage grows linearly with layer count and sequence length. Cross-layer sharing lets several layers reuse one KV cache, significantly reducing cache size and improving memory efficiency at long context.
The difficulty for the engine: cache management is usually “allocate per layer, address per layer,” while sharing requires the engine to recognize which layers map to the same cache. At graph compilation time, this means building a “layer-to-cache-slot” mapping table, and ensuring that layers within a shared group have consistent attention computation logic — otherwise tensor shapes or numerical semantics will not match.
3.2 Per-Layer Embeddings (PLE)
In a conventional model, word embeddings happen once at the input and then flow forward through the layers. PLE instead gives each layer its own embedding lookup, which can then be fused with the hidden state before injection. Compared with the early “lookup and inject directly,” the new generation tends to use “lookup plus projection fusion”: the layer embedding is looked up first, then aligned and fused with the main hidden state via a projection layer.
Three adaptation points:
- The engine must support loading multiple embedding tables and indexing them per layer.
- The fusion operator (element-wise addition, projection matrix multiply) must be correctly wired into the compute graph.
- Pay attention to where the fusion happens — residual addition or replacement — since different conventions produce completely different outputs.
3.3 Heterogeneous KV Heads and K=V
The uniform KV head assumption states that all layers share the same key-value head layout, which makes vectorization easier. The new generation introduces heterogeneous KV heads, where different layers may have different head counts or dimensions, raising the bar for cache allocation and attention kernels. In the more extreme case, some sizes make K equal to V and drop the independent V projection entirely, saving one projection computation.
For the engine, this means determining KV head count and dimension dynamically per layer rather than hardcoding a uniform shape. When K=V holds, the engine should correctly reuse the same projection result, keeping numerics correct while avoiding wasted recomputation.
3.4 Hybrid Attention and QKV Normalization
Hybrid attention (alternating global/local) is relatively friendly to engines, but combining it with Q/K/V three-way normalization requires inserting extra normalization operators around attention. The new generation also adds conventions such as identity scaling, which means the engine must handle scale factors correctly at compile time to avoid precision issues.
3.5 Multimodality and Mixture of Experts
The multimodal part typically consists of a vision encoder (such as ViT plus pooling) and an audio encoder (such as a Conformer-like structure). The core challenge is modality alignment: image and audio features must be projected into the same embedding space as text, while positional encoding and sequence concatenation are handled correctly. MoE brings routing and sparse activation issues: each token activates only a subset of experts, so the engine must efficiently implement gating, expert dispatch, and result aggregation, while avoiding the waste of keeping all expert weights resident in memory.
4. Recommendations for Export and Evaluation
For a family of heterogeneous models, the recommended workflow is:
- Build a capability matrix: first inventory the mechanisms each size uses (cross-layer sharing, per-layer embeddings, heterogeneous KV, MoE), then assess the engine’s support gaps against that inventory.
- Validate in stages: get text-only, single-modality, short-sequence inference working first, then progressively add long context, multimodality, and MoE. This makes it easier to localize the failing layer.
- Set up a numerical alignment baseline: use the reference implementation’s layer-by-layer outputs as ground truth, compare tensor by tensor on key layers, and keep errors within an acceptable range.
- Track three performance metrics: measure time to first token, decode throughput, and peak memory separately, and pay special attention to whether KV sharing and MoE actually deliver the expected gains.
5. Deployment and Usage Recommendations
- Pick by scenario: on device, prefer small sizes and enable cache sharing to control memory; on desktop, a mid-size model balances quality and speed; for servers, consider large sizes with MoE.
- Quantize per module: attention, embeddings, and experts can use different precisions to balance accuracy and speed.
- Plan memory conservatively: full MoE expert weights are large, so weigh the trade-off between keeping them resident and swapping them in and out.
- Leverage general cloud capabilities: object storage can distribute model weights, container platforms can schedule inference services elastically, and logging, monitoring, and alerting can track latency and memory metrics.
6. Conclusion
Adapting to multi-size open-source LLMs is fundamentally an engineering challenge of “one inference engine supporting many architectural conventions.” Mechanisms such as cross-layer KV sharing, per-layer embeddings, heterogeneous KV heads, hybrid attention, multimodality, and MoE are both the key to performance and capability and the source of adaptation difficulty. Mastering a methodology of “capability matrix + staged validation + layer-by-layer numerical alignment,” and making differentiated deployment choices for device, desktop, and server, is how to get stable, efficient inference across a family of heterogeneous models.
