Recent LLM Architecture Advances: KV Cache Compression and MoE Selection
This article explores recent advancements in Large Language Model (LLM) architectures, focusing on KV Cache compression techniques and Mixture of Experts (MoE) model selection. It covers memory cost estimation, cross-layer KV tensor reuse, tiered model deployment strategies (edge, local MoE, and dense models), and practical guidelines for evaluating and deploying these architectures.
I. Background: Long Context Turns Cache into a Bottleneck
Large Language Model (LLM) inference consists of two phases: prefilling (computing the input prompt in a single pass) and generation (producing new tokens sequentially). When generating a new token, the model reads the Keys and Values of all previous tokens. To avoid redundant computation, these tensors are stored as the KV Cache.
The longer the context and the higher the concurrency, the more GPU memory the KV Cache consumes. In many deployment scenarios, it consumes more memory than the model weights themselves. Consequently, a significant portion of recent architectural improvements revolves around a single goal: reducing the amount of data that needs to be cached.
II. Calculating KV Cache Memory Overhead
Under standard Multi-Head Attention, the KV Cache size for a single request can be estimated using the following formula:
KV Memory ≈ 2 × layers × KV heads × head dimension × sequence length × batch size × bytes per element
The coefficient 2 accounts for the two separate tensors (K and V). The pseudo-code below illustrates the estimation:
function kv_cache_bytes(layers, kv_heads, head_dim, seq_len, batch, bytes_per_elem):return 2 * layers * kv_heads * head_dim * seq_len * batch * bytes_per_elem
Example: A model with 32 layers, 8 KV heads, a head dimension of 128, a sequence length of 32768, a batch size of 1, using FP16 (2 bytes per element). Plugging these into the formula yields 2 × 32 × 8 × 128 × 32768 × 1 × 2 = 4,294,967,296 bytes, or 4 GiB. A single request at the 40k-token level consumes 4 GiB of memory, which quickly exhausts VRAM under high concurrency.
The formula highlights four variables for optimization:
- Layers: Reduce the number of layers requiring separate caches, e.g., sharing a single cache across multiple layers.
- KV Heads: Allow multiple query heads to share fewer KV heads via Grouped-Query Attention (GQA) or Multi-Query Attention (MQA).
- Head Dimension: Compress the representation dimension of each head using techniques like low-rank projection.
- Bytes per Element: Apply low-bit quantization to KV, dropping from FP16 down to INT8 or INT4.
This article focuses on the first variable: cross-layer reuse.
III. Cross-Layer Reuse of KV Tensors
3.1 Basic Principle
The idea of cross-layer reuse is that several adjacent layers share the same set of K and V. The first layer in the group computes and writes the cache, while the remaining layers read directly from it. Each layer’s Query is still computed independently, so every layer completes its own attention computation; only the number of cache entries changes.
The pseudo-code below demonstrates sharing one set of KV per 2 layers (omitting positional encoding and masking):
kv_store = {}for i, layer in enumerate(layers):q = layer.q_proj(hidden)group = i // share_size # Share one set of KV per share_size layersif i % share_size == 0:kv_store[group] = (layer.k_proj(hidden), layer.v_proj(hidden))k, v = kv_store[group]hidden = layer.attention(q, k, v, hidden)
3.2 Benefits and Costs
The benefit is straightforward. When share_size is 2, cache entries are theoretically halved. The actual savings depend on the number of layers, sequence length, and physical cache layout, requiring measurement on specific models.
The costs must also be acknowledged. Shared K and V restrict the information each layer can express, requiring the model to adapt to this limitation during training. Thus, architectural changes usually require training or fine-tuning to achieve optimal results. Furthermore, quality changes after compression cannot be judged by memory numbers alone; benchmark validation is essential.
3.3 Validation Methods
When evaluating cross-layer reuse or other KV compression schemes, compare the following metrics under the same input and hardware:
- Peak memory and maximum supported concurrency
- Time To First Token (TTFT) and tokens generated per second
- Quality metrics on target tasks, such as accuracy or human evaluation
All three metrics are indispensable. Looking only at memory may lead to selecting a solution that fails quality standards.
IV. Tiered Model Morphologies: Edge, Local Efficient, and High-Quality Dense
Recent open-source models are often categorized into tiers based on deployment targets.
4.1 Small Models for Edge and Embedded Devices
These models target resource-constrained devices like smartphones, smart speakers, and industrial IoT gateways. Design constraints include:
- Memory Budget: Typically limited to a few GBs, requiring careful management of both weights and KV Cache.
- Power and Heat: Prolonged inference causes thermal throttling, degrading user experience.
- Offline Availability: No network dependency, keeping private data on-device.
Common techniques include controlling parameter scale, applying low-bit quantization, and streamlining the architecture. Evaluation should focus on TTFT, steady-state tokens per second, peak memory, and temperature changes during continuous operation. Typical use cases include on-device command understanding, offline summarization, and local voice interaction.
4.2 MoE Models for Local Efficient Inference
Mixture of Experts (MoE) models contain multiple expert feed-forward networks per layer, with a router selecting a small subset of experts for each token. The total parameter count is large, but only a fraction is activated per token, keeping the compute cost per token closer to that of a smaller model while offering greater knowledge capacity.
Three easily overlooked issues when deploying MoE:
- Compute Savings ≠ Memory Savings: All expert weights must be loaded into VRAM/RAM, meaning memory requirements are still dictated by total parameters.
- Load Imbalance: If the router consistently assigns tokens to a few experts, they become bottlenecks while others sit idle.
- Low Small-Batch Utilization: With small batch sizes, the benefits of expert parallelism are hard to realize.
4.3 Dense Models for Quality and Fine-Tuning Convenience
In dense models, every token passes through all parameters. The structure is regular, making memory and compute predictable, and inference framework optimizations are more mature.
Dense models are also more straightforward in the post-training phase. MoE post-training is generally more difficult for three main reasons:
- During fine-tuning, the router’s allocation strategy tends to drift, disrupting the originally learned expert division of labor.
- On small-scale datasets, expert loads easily become imbalanced, leaving some experts with almost no training signal.
- In preference optimization and reinforcement learning-style training, gradient distribution across multiple experts is more complex, increasing tuning costs.
Therefore, if a team needs to perform frequent instruction fine-tuning or domain adaptation, dense models are typically the safer starting point.
V. Selection Decision Framework
The table below summarizes the main differences across the three morphologies:
| Dimension | Edge Small Models | Local MoE Models | Dense Models |
|---|---|---|---|
| Primary Goal | Offline, low power | Balance local throughput and knowledge capacity | Stable output quality, easy fine-tuning |
| Memory Bottleneck | Weights and KV Cache | All expert weights and KV Cache | Weights and KV Cache |
| Post-Training Difficulty | Low | Relatively high | Low |
| Typical Risks | Lower capability ceiling | Routing imbalance, high memory usage | Higher compute per token |
When selecting a model, follow this sequence:
- Determine hardware limits first, including device memory, power, and network connectivity. If hardware is insufficient, further comparisons are meaningless.
- Determine the quality baseline, i.e., the minimum acceptable metrics for target tasks.
- If frequent fine-tuning is required, prioritize dense models.
- If deploying on a local server or workstation with a focus on throughput and model capacity, evaluate MoE models.
- Regardless of the choice, conduct stress testing with real request distributions rather than relying solely on theoretical parameters.
VI. Practical Implementation Recommendations
6.1 Estimate Cache Using Real-Length Distributions
Estimating KV Cache based on average length will underestimate peak usage. You should analyze the input and output length distributions of production requests and use the P95 or P99 values as the basis for estimation.
6.2 Reserve Concurrency Space in Memory Budgeting
Maximum concurrency can be roughly estimated using the following relationship:
Available Memory for Cache ≈ Total VRAM − Weights Footprint − Runtime Overhead
Maximum Concurrency ≈ Available Memory for Cache ÷ KV Cache Size per Request
