Recent LLM Architecture Evolution: KV Cache Reuse and MoE Trade-offs
This article explains how recent large language model architecture changes aim to reduce inference cost. It covers how to estimate KV Cache memory, how cross-layer KV sharing lowers memory, compute, and bandwidth use, how dense and Mixture-of-Experts (MoE) models compare from an engineering standpoint, what on-device models need to consider, and how to test these choices in practice.
1. Background: Why Architecture Changes Focus on Inference Cost
After training, most of a large model’s cost comes from inference. Servers must handle many concurrent requests, while edge devices are limited by memory capacity and power consumption. For long-context workloads, inference-time GPU memory often becomes a bottleneck before model parameters do. As a result, most recent architecture changes pursue two goals: reducing the compute required per token, and compressing the intermediate state that must be kept during inference.
2. KV Cache Memory Composition and Estimation
During autoregressive generation, the model computes attention over all previous tokens at every step. To avoid repeated computation, the inference framework caches the Key and Value of each layer. This data is called the KV Cache. Its memory usage can be estimated with the following approximate formula:
KV Cache memory ≈ 2 × number of layers × number of KV heads × head dimension × sequence length × batch size × bytes per element
The factor of 2 accounts for the two tensors, K and V. As the sequence length grows to tens of thousands of tokens or more, the KV Cache grows linearly and competes with model parameters for GPU memory.
Consider a model with 48 layers, where each layer has a fixed number of KV heads and head dimension, and the batch size is 1. If every layer stores its own K and V, the cache size is denoted as 1. If every group of 4 layers shares one set of K and V, only 12 layers need storage, so the cache drops to about 1/4. This number only illustrates the calculation. The actual gain depends on the specific model architecture.
3. Cross-Layer KV Sharing: Mechanism and Benefits
The core idea of cross-layer sharing is that later layers no longer compute their own Key and Value. Instead, they read the results already computed by an earlier layer.
# Example code: reusing KV states across layerskv_store = {}for layer_idx, layer in enumerate(layers):if layer.is_kv_owner:# Only the owner layer computes and writes the KV cachek, v = layer.compute_kv(hidden_states)kv_store[layer.share_group] = (k, v)else:# Shared layers read the KV of their group directly,# without projection and without adding new cache entriesk, v = kv_store[layer.share_group]hidden_states = layer.attention(hidden_states, k, v)hidden_states = layer.ffn(hidden_states)
This design offers three benefits:
- Lower memory usage. Fewer layers store cache, so peak memory is lower in long-context scenarios.
- Less computation. Shared layers skip the linear projections for K and V.
- Less bandwidth pressure. During decoding, every generated token reads the KV Cache. Reducing the amount read eases the memory access bottleneck.
Cross-layer sharing also has costs. The more layers that share, the more the later layers’ context representations are limited by the expressive power of earlier layers. Therefore, practical designs must decide which layers act as owners and which layers reuse their KV. Teams should then measure the accuracy loss using perplexity and long-text tasks.
4. Trade-offs Between Dense and Mixture-of-Experts Architectures
Another major design choice is how parameters are organized. The table below compares the two architectures from an engineering perspective.
| Dimension | Dense Architecture | Mixture-of-Experts (MoE) Architecture |
|---|---|---|
| Parameters activated per token | All parameters | Only some experts |
| Compute per token | Positively correlated with total parameters | Positively correlated with activated parameters, usually lower |
| Total parameter capacity | Limited by compute cost | Can be made larger |
| Memory requirements | Relatively intuitive and easy to estimate | Must hold all experts, so memory pressure is high |
| Post-training and fine-tuning | Mature and relatively stable workflow | Unstable routing, harder to tune |
| Deployment complexity | Lower | Involves expert parallelism and load balancing |
MoE models offer high inference efficiency, but post-training is harder. There are three main reasons:
- The router may send most tokens to a small number of experts, causing expert collapse.
- When load is uneven across experts, distributed training throughput suffers.
- With small fine-tuning datasets, only the activated experts get updated, so the other experts are hard to train adequately.
For this reason, many teams complete alignment and fine-tuning with a dense model first, and only then consider converting to MoE for inference. For scenarios that require fast iteration on business capabilities, dense models are often easier to keep risk under control.
5. Design Considerations for On-Device and Local Small Models
Small models for phones, vehicles, and embedded hardware have different design priorities than server models. They usually need to address the following:
- Memory budget: model weights, KV Cache, and runtime overhead must all fit in device memory at the same time.
- Quantization compatibility: both weight quantization and KV Cache quantization affect accuracy, so each needs separate testing.
- Power and heat: long inference sessions cause thermal throttling, so performance must be tested under sustained load.
- Context length: on-device inputs are usually short, so the benefit of KV sharing should be evaluated against the actual request distribution.
On-device models often use smaller hidden dimensions and fewer layers, combined with KV reuse. This keeps context extension from quickly exhausting memory.
6. Practical Engineering Recommendations
In real projects, follow these steps:
- Estimate the KV Cache footprint for your target scenario first. Substitute the maximum sequence length, batch size, and concurrency into the formula to get the memory requirement.
- Choose candidate architectures and benchmark them on the same hardware. Track time to first token, tokens generated per second, peak memory, and accuracy on long-context tasks.
- Run ablation experiments on the sharing strategy. Compare how different numbers of shared layers affect accuracy and memory, then choose the option with the best cost-effectiveness.
- Connect these metrics to your general monitoring and alerting system. Set thresholds for memory usage and latency so capacity issues surface early.
- Keep a fallback plan. When an optimization clearly loses accuracy on a specific task, switch to the unshared configuration.
7. Conclusion
The shared direction of recent architecture changes is to let inference handle longer contexts within limited memory and compute. Cross-layer KV cache reuse directly reduces the storage overhead of long contexts. The dense versus MoE trade-off shows that inference efficiency, training difficulty, and deployment complexity must be weighed together. For developers, the most practical approach is to quantify resource constraints first, choose an architecture that fits them, and keep validating results with the same benchmark suite.
