KV Cache Compression and Mixture-of-Experts: Key Trends in LLM Architecture Evolution

    This article explores two major trends in modern LLM architecture design: cross-layer KV cache sharing, which reduces memory and bandwidth costs in long-context inference, and the trade-offs between mixture-of-experts (MoE) and dense architectures. It covers the KV cache capacity formula, shared-KV implementation patterns, benefits and costs, engineering deployment checklists, and evaluation methods for production systems.

    1. Background: In the Long-Context Era, KV Cache Becomes a Core Cost

    LLM inference cost is not determined by parameter count alone. During autoregressive generation, the model must store the Key and Value states of every processed token at every layer, forming the KV cache. As context windows scale from thousands to tens of thousands of tokens—or even further—and as agent applications increasingly involve multi-turn dialogue, tool calls, document retrieval, and long-term memory, the memory footprint and bandwidth overhead of the KV cache grow rapidly.

    From a capacity perspective, the KV cache approximately follows:

    1. KV bytes ≈ B × L_kv × H_kv × D × S × 2 × bytes_per_element

    Here, B is the batch size, L_kv is the number of layers that actually need to store KV, H_kv is the number of KV heads, D is the head dimension, S is the sequence length, 2 accounts for the Key and Value tensors, and bytes_per_element depends on the precision. Sequence length and batch size are multiplicative terms—growth in either directly raises memory usage—while layer count, KV head count, and head dimension determine the per-token cache cost.

    More importantly, the KV cache consumes not only memory but also memory bandwidth. During decoding, generating each token requires reading all historical KV states for attention computation. In long-context scenarios, bandwidth pressure can outweigh pure compute pressure. As a result, a common theme in recent LLM architecture evolution is “shrinking the KV cache”: reducing the per-token cache footprint while preserving model quality, thereby improving the feasibility of long-context, batched inference and agent applications.

    2. Cross-Layer KV Reuse: From Per-Layer Caching to Shared KV Tensors

    In traditional decoder architectures, every layer has an independent attention module and typically stores its own Key and Value tensors. The core idea of cross-layer KV reuse is that subsequent layers no longer compute and store a full set of KV states; instead, they reuse the KV tensors already computed by certain earlier layers. Query projections, output projections, and per-layer feed-forward networks remain independent.

    A common implementation introduces a “KV owner layer mapping”:

    1. # Pseudocode: cross-layer KV reuse
    2. for layer in range(num_layers):
    3. if layer in kv_owner_map:
    4. K_owner, V_owner = project_kv(hidden_states, layer)
    5. cache.store(kv_owner_map[layer], K_owner, V_owner)
    6. K_ref, V_ref = K_owner, V_owner
    7. else:
    8. K_ref, V_ref = cache.load(kv_owner_map[layer])
    9. Q = project_q(hidden_states, layer)
    10. attn_out = attention(Q, K_ref, V_ref, causal_mask)
    11. hidden_states = layer_norm(hidden_states + project_o(attn_out, layer))

    Here, kv_owner_map specifies which “owner layer’s” KV each layer references. Shared layers store only one copy of KV, and subsequent layers read from the same cache. This reduces L_kv in the formula from “total layers” to “effective KV layers,” significantly compressing cache capacity. Sharing granularity can group adjacent layers or reuse across groups; the wider the sharing scope, the greater the cache savings—but also the higher the demands on model expressiveness and training consistency.

    It is important to emphasize that cross-layer reuse does not mean all layers share attention entirely. Queries are still generated independently per layer, and output projections can remain independent, so different layers can still form different query patterns. What is shared is the historical Key and Value states—effectively letting multiple attention layers read the same context representation. This approach is orthogonal to reducing KV head counts, low-rank compression, quantization, and paged memory management, and can be combined with them.

    3. Benefits and Costs of Shared KV Cache

    On the benefits side, the first is reduced memory footprint. In long-context inference, the KV cache can occupy a substantial share of memory; reducing the number of effective KV layers shrinks per-request cache size, allowing longer contexts or larger batches under the same memory budget. Second, bandwidth pressure drops because decoding reads fewer historical KV states, lowering per-token memory access cost. Third, prefix caching in multi-turn dialogue and agent scenarios becomes easier to reuse, since the cache structure is more compact.

    The costs are also clear. Different layers do not have identical abstraction needs for context information; forced KV sharing may weaken inter-layer representational diversity and cause quality loss. The wider the sharing scope, the more the training stage must adapt the model to this constraint—for example, by fixing the sharing mapping during pretraining or continued training, or by recovering quality through distillation or lightweight post-training. Engineering-wise, one must also handle positional encoding consistency, cache layout, shared mappings across different requests within a batch, and cache eviction and migration.

    Therefore, the key to cross-layer reuse is not “share as much as possible,” but finding a stable operating point between cache compression ratio and model quality. For resource-constrained edge or local inference, more aggressive sharing may be appropriate; for quality-first server-side deployments, grouped sharing or combinations with other compression techniques may be preferred.

    4. Mixture-of-Experts vs. Dense Architectures: Not Mutually Exclusive, but a Trade-off

    Another major thread in recent architecture evolution is the trade-off between mixture-of-experts (MoE) and dense architectures. MoE activates a subset of experts via a routing mechanism, controlling per-token compute while keeping total parameter count large; dense architectures engage all parameters in every computation, offering simpler structure and more straightforward training and post-training pipelines.

    On the deployment side, MoE does not necessarily reduce memory capacity requirements, since expert parameters must still reside in memory or be loaded on demand; it mainly reduces the activated compute per token. Dense architectures, by contrast, are easier to handle with uniform batching, quantization, and post-training tuning. For scenarios that prioritize quality and convenient post-training workflows, dense architectures retain advantages; for scenarios that prioritize efficient local inference or server-side throughput, MoE is more attractive.

    Cross-layer KV reuse and MoE can be stacked: MoE reduces feed-forward activation compute, while cross-layer reuse reduces attention cache and bandwidth. Together they serve the goal of “supporting longer contexts and higher throughput under limited resources.”

    5. Engineering Deployment Checklist and Evaluation Methods

    When implementing these techniques, focus on the following checklist:

    1. Sharing mapping design: Whether using per-layer grouping, adjacent-layer reuse, or cross-group reuse, the mapping must be determined during training and kept consistent at inference.
    2. Cache layout: Store by owner layer; non-owner layers keep only references. Batching must support different requests sharing the same mapping.
    3. Prefix cache compatibility: Multi-turn dialogue and retrieval-augmented scenarios should reuse already-computed shared KV blocks to avoid redundant computation.
    4. Precision and quantization: Shared KV makes the cache more compact, but the impact of low precision on long-context retrieval and generation stability must still be evaluated.
    5. Monitoring metrics: Track peak memory, bytes read per token, cache hit rate, time-to-first-token, throughput, and long-context quality regressions.

    Evaluation should not rely solely on average perplexity; it should also cover long-context retrieval, multi-turn consistency, context retention after tool calls, batch throughput, and tail latency. It is advisable to gradually expand the sharing scope in small-scale ablations, observe the inflection points on the quality curve and resource curve, and then finalize the production configuration.

    6. Conclusion

    A common direction in recent LLM architecture evolution is rebalancing compute, memory, and bandwidth under the demands of long contexts and agent workloads. Cross-layer KV reuse, by sharing KV tensors to shrink the cache, is an effective means of reducing long-context inference cost; mixture-of-experts and dense architectures serve the respective trade-offs of efficient activation and convenient post-training. A truly deployable solution requires designing the sharing mapping, cache management, quantization, batching, and evaluation framework together—only then can one achieve longer context windows and more stable inference economics without significant quality sacrifice.