LLM Architecture Evolution: Cross-Layer KV Cache Reuse and Inference Optimization

    This article explores the evolution of Large Language Model (LLM) architectures, focusing on Cross-Layer KV Cache reuse as a strategy to optimize inference. It details why KV cache becomes a bottleneck in long-context scenarios, explains the mechanism and benefits of cross-layer sharing, and clarifies its trade-offs compared to other optimization techniques like quantization and Mixture of Experts (MoE). Finally, it provides a reliable evaluation framework for developers to assess these architectural improvements in real-world deployments.

    1. Focus of Architecture Evolution: Beyond Parameter Count to Resource Allocation

    The deployment cost of large models is not solely determined by parameter count. Model weights, intermediate inference states, context length, concurrent requests, and hardware communication capabilities collectively determine actual service efficiency. When understanding model architecture evolution, it’s crucial to recognize that model quality, computational overhead, and memory consumption are interrelated but not equivalent metrics. Smaller models aren’t always faster on all devices; high single-generation speed doesn’t always suit high-concurrency, long-context services.

    From a deployment perspective, common goals generally fall into three categories:

    • Edge and embedded deployment: Prioritizes memory, power consumption, and response time constraints.
    • Local efficient inference: Balances model capability, throughput, and deployment complexity under limited hardware resources.
    • High-quality service and post-training: Focuses on capability limits, task adaptation, and training process controllability.

    These goals drive different architectural choices. Cross-layer KV cache reuse addresses an increasingly prominent bottleneck: as context lengthens, the memory consumed by inference states expands continuously, often becoming the primary constraint on service capacity.

    2. Why KV Cache Becomes an Inference Bottleneck

    1. The Role of Cache: Avoiding Recomputing Historical States

    In autoregressive generation based on causal self-attention, generating a new token requires information from preceding text. For each attention layer, relevant states can be summarized as Query, Key, and Value. New tokens generate queries, match with historical keys, and aggregate historical values based on these matches.

    Without saving historical KV states, the model would repeatedly process preceding content when generating subsequent tokens. KV caching retains computed historical states, reducing redundant work. Thus, caching is essentially a “space-for-compute” mechanism. However, as context grows, the space cost grows with it.

    2. Estimating Cache Capacity

    Assuming a standard dense KV cache, uniform layer configurations, and ignoring management overhead, capacity can be roughly expressed as:

    M ≈ 2 × L × B × T × Hkv × D × S

    Where:

    • L: Number of attention layers requiring independent cache storage;
    • B: Number of sequences in a batch;
    • T: Cache length per sequence;
    • Hkv: Number of KV heads;
    • D: Dimension per head;
    • S: Bytes per cache element;
    • Coefficient 2: Corresponds to Key and Value respectively.

    This formula reveals several direct optimization directions: reducing independent cache layers, reducing KV heads, lowering storage precision, or limiting retained history length. Note that real-world request lengths vary, and cache may include paging indexes, memory alignment, fragmentation, and other auxiliary information. Thus, the formula serves better as a starting point for capacity planning rather than precise prediction of total process memory.

    3. Cross-Layer KV Cache Reuse: From “Per-Layer Cache” to “Shared Layers”

    1. Core Concept

    In conventional designs, different attention layers usually maintain their own Key and Value states. These states derive from hidden representations at varying depths, carrying different levels of information. Cross-layer reuse changes this: certain subsequent layers no longer independently generate and store full KV states but instead use states provided by designated preceding layers. Subsequent layers still perform their own query computations and use these queries to read shared KV information.

    The two organizational methods can be summarized as:

    Conventional approach:
    Layer 1 → Cache 1
    Layer 2 → Cache 2
    Layer 3 → Cache 3
    Layer 4 → Cache 4

    Illustrative cross-layer sharing approach:
    Layer 1 → Cache A
    Layer 2 → Reads Cache A
    Layer 3 → Cache B
    Layer 4 → Reads Cache B

    This grouping is purely for illustrating the principle; actual models don’t necessarily use fixed adjacent layer pairs. Sharing scope, provider layer selection, and whether to retain local independent states are architectural designs determined through training and experimentation.

    2. How It Saves Cache

    The most direct effect of cross-layer sharing is reducing the number of independent KV state groups stored. Assuming original L layers of independent cache, modified to only G groups of shared cache with identical configurations, the main cache capacity ideally scales to roughly G/L of the original.

    For example, if the number of independent cache groups is halved, the theoretical capacity of the main cache could nearly halve. However, this doesn’t mean total VRAM will necessarily halve, because model weights, temporary workspaces, activations, and runtime management structures don’t disappear simultaneously. Therefore, when evaluating benefits, three metrics must be distinguished:

    • Reduction in the KV cache itself;
    • Reduction in peak VRAM of the entire inference process;
    • Increase in effective concurrent requests on the same hardware.

    Separating these metrics prevents mistaking local optimization for system-wide gains.

    3. Cache Reduction ≠ Proportional Attention Compute Reduction

    Cross-layer sharing reduces some KV projections and cache writes, but subsequent layers still typically execute their own query computations, attention matching, and result aggregation. If multiple layers read the same cache sequentially, identical memory addresses don’t guarantee proportional reductions in device memory reads. Actual data movement depends on execution order, on-chip cache hits, and underlying operator implementations.

    Therefore, cross-layer reuse is primarily a state compression and structural sharing concept; its latency benefits require empirical testing and cannot be directly deduced from cache compression ratios.

    4. Why It Isn’t a Simple Inference Switch

    KV states from different layers aren’t naturally equivalent. Shallow layers may lean toward local patterns, while deeper layers form more abstract semantic representations. Forcing subsequent layers to read preceding layers’ KV states actually alters the model’s information flow.

    Therefore, applying this directly to a fully trained model originally using per-layer caches by arbitrarily deleting caches and forcing shares will likely break learned representation relationships. Reliable implementations require explicit handling of the following issues during architecture design and training:

    1. Representation Space Compatibility

    Layers sharing KV states must be compatible in head count, dimensions, and attention computation conventions. If incompatible, additional mappings may be needed, introducing parameter, compute, and maintenance costs.

    2. Position Information Consistency

    Attention computation typically includes positional information. During cross-layer sharing, the positional processing of the shared state must match the reading layer; otherwise, positional relationships may be misinterpreted.

    3. Appropriate Sharing Intensity

    Greater sharing scope yields higher potential cache benefits but imposes stricter limits on independent modeling freedom per layer. A reasonable approach balances quality and resources rather than merely minimizing cache. Evaluation should pay special attention to long-text localization, multi-turn information retention, complex reasoning, and structured generation tasks, as these tasks may expose issues hidden in standard short-text tests.

    5. Relationship with Other Cache Optimization Techniques

    Cross-layer reuse isn’t the only optimization direction. Understanding which dimension each technique targets helps avoid conceptual confusion.

    1. Reducing KV Heads

    Letting multiple query heads share fewer KV heads (e.g., Grouped-Query Attention) reduces per-layer cache scale. This primarily targets Hkv in the formula, whereas cross-layer reuse primarily targets L (independent cache layers). They can be combined, but resulting quality and performance cannot be judged solely by theoretical capacity estimates.

    2. Lowering Cache Storage Precision

    Cache quantization compresses capacity by reducing bytes per element (S). However, it may introduce numerical errors and requires handling scaling information, data layout, and dequantization overhead. For long-context tasks, whether errors affect critical information retrieval must be verified separately.

    3. Limiting Historical Visibility

    Methods like sliding windows lower costs by shortening retained or accessible history. This changes the model’s directly readable information scope, a different trade-off than cross-layer sharing. Cross-layer sharing can preserve longer historical coverage but doesn’t guarantee equally rich independent historical representations per layer.

    4. Optimizing Cache Allocation and Scheduling

    Paged management, on-demand allocation, and request scheduling primarily solve fragmentation, utilization, and concurrency organization issues. They usually don’t directly alter the model semantics carried by each valid cache element. Real-world deployment often requires optimizing both architecture (reducing necessary states) and runtime (improving state management efficiency).

    6. Dense vs. Mixture of Experts (MoE) Architectures: A Different Resource Problem

    Cross-layer cache sharing primarily optimizes attention states, whereas differences between Dense and MoE architectures mainly manifest in parameter organization and compute activation methods. Dense architectures usually have regular computation paths, with relatively straightforward deployment and post-training processes. However, actual efficiency still depends on model size, numerical precision, and hardware adaptation.

    MoE architectures typically use routing mechanisms to select a subset of experts for computation per token. This allows expanding total parameter capacity while controlling per-token activation compute, but introduces challenges like expert weight storage, load balancing, routing overhead, and cross-device communication.

    Crucially: sparser expert layer computation does not automatically mean a smaller attention cache. A model can employ MoE while still maintaining a large KV cache. Post-training difficulty shouldn’t be generalized either. MoE models may require extra attention to routing stability and expert utilization, but actual difficulty depends on training objectives, data distribution, and implementation.

    7. How Developers Can Build a Reliable Evaluation Workflow

    1. Describe Real Workloads First

    Before evaluation, clarify input length, output length, concurrency scale, and request type. Short Q&A, long-document analysis, and multi-turn dialogue have vastly different cache and compute requirements. It is also necessary to distinguish between prefill (processing input context) and decode (repeatedly utilizing historical cache); architectural optimizations may yield different benefits in these two phases.

    2. Record Performance and Quality Separately

    It is recommended to record at least:

    • Time to First Token (TTFT);
    • Inter-token latency during generation;
    • Peak memory usage;
    • Effective throughput under latency constraints;
    • Accuracy on long-context tasks;
    • Tail latency under concurrent pressure;
    • Ratios of timeouts, Out-of-Memory (OOM), and abnormal outputs.

    Don’t ignore quality degradation for higher throughput, nor mask severe delays of a few requests with average latency.

    3. Control Experimental Variables

    When comparing schemes, maintain consistent hardware, input/output lengths, batching strategies, and precision settings, explaining any misaligned conditions. If a tested model simultaneously changes cache structure, training data, and parameter size, all benefits cannot be attributed solely to cross-layer reuse. Engineering reports should distinguish between “the whole solution performs better” and “how much a specific mechanism contributed.”

    8. Conclusion: Architecture Value Requires Complete System Validation

    Cross-layer KV cache reuse represents a vital concept: not all inference states between different model layers must be entirely independently stored. Through constrained sharing, the state storage pressure in long-context and high-concurrency scenarios can be reduced.

    However, these benefits come with trade-offs in representation capability, training methodology, and execution implementation. It is neither a lossless switch universally applicable to existing models, nor a guarantee that cache reductions translate directly to proportional inference speedups.

    For developers, a more effective route is identifying bottlenecks first, then selecting techniques: focus on parameter storage if weight usage is too high; study state compression if cache pressure is prominent; optimize execution paths if compute or communication is constrained. Ultimately, judging architectural value through real task quality, service latency, and resource cost transforms technical evolution into stable, verifiable deployment benefits.