LLM Architecture Evolution and KV Cache Compression: A Practical Guide

    Over the past year, architectural changes in mainstream large language models have converged on a single goal: reducing the memory and compute cost per unit of context. This article explains why KV Cache has become the central constraint of that evolution, how its memory footprint is calculated and what drives it, which attention-level optimizations are most effective, and how cross-layer KV sharing, MoE versus Dense designs, and model size tiers shape practical selection decisions. It closes with engineering advice for estimating KV Cache memory, prioritizing optimizations, accounting for post-training cost, and validating choices with measurable load testing.

    1. Why KV Cache Compression Became a Core Architectural Problem

    Over the past year or so, mainstream large language models have followed a clear architectural trajectory: nearly every meaningful change has been aimed at lowering the memory and compute cost of a unit of context. This is not coincidence. It is driven by a shift in how these models are actually used.

    In the early days of chat-style applications, context windows were typically on the order of a few thousand tokens, and KV Cache memory usage was manageable. The reasoning-model and AI Agent era changed the picture fundamentally. Multi-turn tool calling, long-document comprehension, repository-level code analysis, and chain-of-thought reasoning over long horizons can all push the effective context of a single session into the hundreds of thousands of tokens. At that point, KV Cache stops being a secondary concern and directly determines questions that affect cost and availability: whether the model can run at all, and how many concurrent requests a single deployment can serve.

    Understanding what causes KV Cache growth and how to compress it has therefore become a key dimension for evaluating whether any modern model architecture is well designed.

    2. What Makes Up KV Cache Memory, and Why It Becomes the Bottleneck

    During autoregressive generation in a Transformer, each layer caches the Key and Value tensors for historical tokens so that already-generated tokens do not have to be recomputed. This is the KV Cache. Its memory footprint can be approximated as follows:

    1. # Conceptual estimate of KV Cache memory usage
    2. def kv_cache_size(num_layers, num_kv_heads, head_dim,
    3. seq_len, batch_size, bytes_per_element):
    4. # Factor of 2: separate storage for the Key and Value tensors
    5. return (2 * num_layers * num_kv_heads * head_dim
    6. * seq_len * batch_size * bytes_per_element)

    The formula shows that KV Cache size scales with the number of layers, the number of Key/Value heads, the head dimension, the sequence length, the concurrent batch size, and the data precision. The product of sequence length and concurrency is often the direct trigger of memory exhaustion: a long-context workload combined with high concurrency can easily make KV Cache memory exceed the model weights themselves.

    This also explains why the industry has focused on reworking the attention mechanism. Reducing any of num_layers, num_kv_heads, or the precision yields a substantial improvement. Common general-purpose techniques include multi-query attention (multiple Query heads sharing one set of KV), grouped-query attention (KV shared within groups), attention variants that compress KV into a low-rank latent space, and strategies such as KV quantization, sliding windows, and KV eviction.

    3. Cross-Layer KV Sharing: An Approach Now Adopted by Mainstream Open-Source Architectures

    One architectural change worth attention is the reuse of KV tensors across layers. The core idea is that not every layer needs to compute and hold a complete Key-Value state of its own. Later layers can reuse KV already computed by earlier layers, reducing both total cached data and redundant computation without a significant loss in quality.

    It is worth noting that this idea was explored in the research literature some time ago. Work on Cross-Layer Attention, for example, already demonstrated the feasibility of sharing KV between layers. What is genuinely new is that it is now being integrated at scale into mainstream open-weight architectures, moving from a technique described in papers to a default engineering option.

    A conceptual implementation looks roughly like this:

    1. # Conceptual cross-layer KV sharing: some layers reuse Key/Value from upstream layers
    2. kv_store = {}
    3. for layer_idx in range(num_layers):
    4. if layer_idx in shares_from_layers: # this layer does not recompute KV
    5. keys, values = kv_store[shares_from_layers[layer_idx]]
    6. else: # only "anchor" layers compute and cache KV
    7. keys, values = compute_kv(hidden_states)
    8. kv_store[layer_idx] = (keys, values)
    9. hidden_states = attention(hidden_states, keys, values)

    The critical design decision is which layers act as “anchor” layers that compute KV and which layers reuse it. A higher sharing ratio saves more memory, but sharing too aggressively costs representational capacity. In practice, some layers are usually left to compute KV independently to strike a balance between compression and quality. This also introduces an engineering constraint: once the sharing structure is fixed, it affects fine-tuning and downstream training workflows, so it needs to be evaluated early in the selection process.

    4. Architecture Trade-offs: Where MoE and Dense Each Fit

    To balance quality against engineering controllability, mainstream open-source families typically offer both a Mixture-of-Experts (MoE) and a Dense route. Neither is inherently better. They are trade-offs against different constraints:

    • Mixture of Experts (MoE): A routing mechanism activates only a subset of expert parameters per token, keeping compute per token low even with a large total parameter count. This gives strong inference cost-efficiency. The cost is greater complexity in training and deployment, more difficult post-training (such as instruction tuning and alignment tuning), and higher demands on memory and distributed communication.
    • Dense: All parameters participate in every forward pass, so behavior is more predictable and the post-training and tuning workflows are more mature and stable. This suits scenarios that prioritize controllable, iterative quality improvement. The cost is generally higher inference compute for the same quality level.

    The point of understanding this trade-off is practical. If the goal is fast domain-specific post-training and rapid iteration, Dense is usually the lower-friction starting point. If the goal is high-throughput, low-inference-cost service at scale, MoE delivers more output per unit of compute.

    5. Choosing a Model Size by Scenario

    Modern model families are typically tiered to cover requirements from edge devices to the cloud:

    • Small on-device/embedded (IoT) models: Targeted at phones, wearables, and local devices, with emphasis on very low latency, offline availability, and low power consumption. These models are often the first to adopt memory optimizations such as KV sharing, because they are extremely sensitive to memory.
    • Mid-sized efficient models (for example, in the 20–30B range): Aimed at efficient local inference, often using an MoE structure to provide strong general capability under single-machine resources.
    • Larger high-quality models (for example, 30B-class Dense and above): Aimed at higher quality and a smoother post-training workflow, suitable as a foundation for deep customization and complex reasoning tasks.

    The right approach to selection is not “bigger is always better.” Instead, work backward from four dimensions: context length, concurrency, hardware budget, and post-training plans. For long-context scenarios, look first at KV Cache compression capability. For high concurrency, look first at throughput. For heavy customization, look first at how post-training-friendly the architecture is.

    6. Engineering Recommendations

    When translating architectural evolution into a real system, a few points are worth attention:

    1. Measure before optimizing. Estimate KV Cache memory from the token-length distribution and concurrency profile of your actual workload rather than selecting by intuition.
    2. Examine the attention structure first. KV sharing, grouped-query attention, and KV quantization are the highest-leverage optimizations.
    3. Factor post-training cost into selection. The difference in iteration cost between Dense and MoE directly affects long-term maintenance effort.
    4. Validate on a mature platform. During the deployment validation stage, you can use general-purpose capabilities commonly offered by major cloud providers — model serving platforms, container platforms, logging services, and monitoring and alerting — to load-test and make memory usage, latency, and throughput observable. For example, general-purpose engineering capabilities on a platform such as Baidu AI Cloud can be used to support elastic scaling and stability observation for inference services, so that architecture choices rest on measurable data.

    Ultimately, KV Cache compression, the MoE-versus-Dense question, and model size tiering are different facets of the same problem: under a given compute and memory budget, supporting inference workloads that are longer, more complex, and higher in concurrency. Whoever crosses the KV Cache memory barrier more effectively is better positioned to deliver services that are competitive on both quality and cost in the era of reasoning and AI Agents.