LLM Architecture Evolution: KV Cache Compression and Cross-Layer KV Sharing Explained

    A technical overview of why compressing the KV Cache has become the central theme in LLM architecture design. It covers where the KV Cache overhead comes from, the main compression routes — MQA/GQA, cross-layer KV sharing, windowed and sparse attention, KV cache quantization, and paging-based memory management — plus the tradeoffs between MoE and Dense architectures and practical advice on memory budgeting, technique stacking, and post-training cost. Read this to understand the design logic behind recent open-weight models and to make more informed choices when deploying and tuning them.

    Introduction: Why Current Architecture Design Is Focused on the KV Cache

    Over the past two years, one recurring theme has dominated LLM architecture evolution: compressing the KV Cache as much as possible. Whether it is a small model built for on-device deployment or a flagship model chasing long-context capability, many architecture-level changes ultimately serve the same goal — reducing memory consumption during inference. Understanding this thread makes it easier to explain the shared design tradeoffs in the recent wave of open-weight model releases.

    1. What the KV Cache Is and Where Its Overhead Comes From

    During autoregressive generation, producing every new token requires the Key and Value vectors of all previously generated tokens. Recomputing them at every step would be prohibitively expensive, so inference frameworks cache the Key/Value states of past tokens. This is the KV Cache. It trades memory for speed: GPU memory is spent to keep decoding fast.

    The problem is that KV Cache memory grows linearly with sequence length and batch size. A rough estimate is:

    1. KV memory ≈ 2 × L × H_kv × d_head × S × B × P
    2. where:
    3. 2 — two caches, K and V
    4. L — number of layers in the network
    5. H_kv — number of KV heads
    6. d_head — dimension of each attention head
    7. S — sequence length
    8. B — batch size
    9. P — bytes per element (2 for fp16)

    Sequence length S appears in the linear term. When the context window grows from 4K to 128K and the number of concurrent requests increases, the KV Cache can easily become the single largest consumer of memory — larger than the model weights themselves. This is the fundamental reason why “shrinking the KV Cache” has become a focus of architecture design: it directly determines how long a context you can support and how much concurrency you can serve.

    2. The Main Routes to Compressing the KV Cache

    The industry has developed a set of complementary techniques. Understanding them helps you judge how an architecture will actually perform on long context and throughput.

    1. Fewer KV heads: MQA and GQA
    In multi-head attention, query heads map one-to-one to key/value heads. Multi-Query Attention (MQA) lets all query heads share a single set of K/V; Grouped-Query Attention (GQA) lets several query heads share one set of K/V, as a compromise between quality and efficiency. Both approaches reduce H_kv in the formula and are now standard in mainstream architectures.

    2. Cross-layer KV sharing (cross-layer attention)
    This is an important recent change in small-model designs. Conventionally, each layer computes its own K/V. With cross-layer sharing, later layers reuse the Key-Value states already computed by an earlier layer, substantially reducing the effective number of layers L in the formula. The idea was first proposed in academic work (for example, cross-layer attention research) and largely remained experimental. Recent open-weight models are the first to bring it into mainstream architectures at scale.

    Illustrative pseudocode:

    1. shared_kv = None
    2. for layer_idx in range(num_layers):
    3. hidden = layers[layer_idx].input_norm(hidden)
    4. # The first layer of each group computes KV; the rest reuse it
    5. if layer_idx % kv_share_interval == 0:
    6. key = layers[layer_idx].k_proj(hidden)
    7. value = layers[layer_idx].v_proj(hidden)
    8. shared_kv = (key, value)
    9. else:
    10. key, value = shared_kv # reuse KV already computed by an earlier layer
    11. query = layers[layer_idx].q_proj(hidden)
    12. attn = scaled_dot_product_attention(query, key, value, ...)
    13. hidden = hidden + attn

    The cost of cross-layer sharing is a slight loss of representational capacity, since different layers could previously model different representations. It therefore suits small models where a degree of accuracy loss is acceptable and extreme lightweighting is the priority.

    3. Windowed and sparse attention
    Sliding-window attention keeps only K/V within a local range; history outside the window is discarded or compressed. It gives up modeling very long-range dependencies but delivers clear benefits on many practical tasks, and works well when mixed with global attention.

    4. KV Cache quantization
    Quantizing cached K/V from higher precision (for example, fp16) to lower bit widths (for example, int8/int4) directly reduces P in the formula. It is one of the cheapest techniques to adopt and is decoupled from the model structure, so it can be stacked with the methods above.

    5. Memory management and paging
    Even when a single request’s KV Cache has been compressed, a serving system still has to solve how multiple requests share memory. Management schemes borrowed from operating-system paging — allocating KV memory in blocks, reducing fragmentation — can substantially improve overall throughput. This is an engineering-side complement to the model-level techniques.

    3. Architecture Selection: MoE vs. Dense

    Recent open-weight releases often ship both architecture families, reflecting different positioning:

    • Mixture-of-Experts (MoE): routing activates only part of the parameters, so you can stack a much larger total parameter count for the same activated compute, giving good inference cost-efficiency. However, routing and expert scheduling add complexity to post-training and fine-tuning, making these models harder to tune and stabilize.
    • Dense: every parameter participates in computation at every step. The structure is simple and the training and post-training pipeline more mature, which makes high-quality instruction tuning and alignment easier.

    As a result, scenarios chasing extreme parameter efficiency tend toward MoE, while scenarios that emphasize controllability and ease of post-training favor Dense. In addition, small models aimed at on-device/IoT deployments often combine cross-layer KV sharing, lower resolution, and quantization to obtain usable long-context capability under a very narrow memory and compute budget.

    4. Practical Engineering Advice

    • Start with a memory budget estimate: use the formula above to estimate KV memory at different context lengths and concurrency levels, and determine whether the bottleneck is weights or cache.
    • Combine techniques rather than relying on one: MQA/GQA, cross-layer sharing, quantization, and windowed attention can be stacked. Typically, “structural compression + cache quantization” offers the best cost-performance tradeoff.
    • Make tradeoffs per scenario: on-device favors memory and compute savings and can tolerate some accuracy loss; server-side cares more about throughput and scheduling efficiency, where paging-based memory management and batching strategies matter just as much.
    • Account for post-training cost: if your team needs frequent domain fine-tuning, Dense is usually easier to manage; if inference cost-efficiency is the goal and you have tuning capability, MoE is the better fit.

    Conclusion

    From query-head sharing to cross-layer KV reuse, from windowed attention to cache quantization, the underlying logic of recent architecture evolution is highly consistent: reduce KV Cache memory and compute overhead as much as possible while keeping quality acceptable. Once you understand this “trade memory for long context” design philosophy, you can make more deliberate tradeoffs between quality and cost during model selection, deployment, and tuning.