Cross-Layer KV Cache Reuse: LLM Architecture Evolution and Inference Efficiency Optimization
This article examines how large language model architecture evolution is increasingly shaped by resource efficiency rather than parameter scale alone. It explains why the key-value (KV) cache becomes a major bottleneck in long-context inference, how cross-layer KV cache reuse reduces independently stored historical states, and what trade-offs this introduces. It also distinguishes cross-layer reuse from sparse expert architectures and other cache optimizations, and outlines a practical validation workflow for measuring quality, latency, memory, and throughput under realistic workloads.
1. The Focus of Architecture Evolution: Not Just Larger Models, but More Rational Resource Use
The practical capability of a large model depends not only on parameter scale and benchmark scores, but also on whether it can deliver stable service under limited resources. For mobile devices, local workstations, and enterprise inference clusters, whether model weights fit into memory is only the first deployment threshold.
As input length, output length, and concurrent request count increase, the inference process also needs to store growing intermediate states. Among them, the key-value cache, or KV cache, often becomes a major resource bottleneck for long-context inference.
Therefore, understanding large model architecture evolution requires separating several different questions:
- How much storage space model weights occupy;
- How much computation is required to generate each token;
- How much cache historical context requires;
- How resources are allocated when multiple requests run concurrently;
- Whether architecture changes increase training and deployment complexity.
Cross-layer cache reuse mainly targets the third question and may also affect the second. Sparse expert architectures mainly adjust the relationship between parameter capacity and per-token computation. These techniques are not replacements for one another; they act on different resource dimensions.
2. Why Long Context Amplifies the KV Cache Problem
2.1 What the KV Cache Stores
In causal self-attention, each token forms query, key, and value vectors. When generating a new token, the current query needs to match keys from previous positions and then perform weighted aggregation over the corresponding values.
Because historical tokens cannot see future tokens, under deterministic inference conditions their already-computed keys and values generally do not need to be recomputed as subsequent tokens are generated. The inference system can store these states for later steps. This is the basic role of the KV cache.
Note that the cache eliminates repeated computation of historical key-value states; it does not mean that a new token no longer needs to read historical context. For standard full attention, as context grows, each decoding step still needs to process more historical key-value data.
2.2 Which Variables Affect Cache Capacity
Under a simplified condition where all layers have the same configuration and the cache is not quantized or compressed, KV cache capacity can be approximated as:
M ≈ 2 × B × T × L × Hkv × D × S
Where:
- B: number of sequences cached simultaneously;
- T: number of tokens cached per sequence;
- L: number of layers that need to store KV states independently;
- Hkv: number of KV heads;
- D: vector dimension per head;
- S: bytes occupied per element;
- The coefficient 2: corresponds to the key cache and value cache respectively.
This is not a complete service memory formula. Real deployment also needs to consider weights, temporary tensors, cache allocation granularity, memory fragmentation, and runtime workspace.
However, this expression reveals a key fact: even if model weights remain unchanged, cache grows approximately linearly with context length and concurrency. Reducing the number of KV heads, lowering cache precision, limiting retained history length, and reducing the number of independent cache layers are optimizations along different directions.
3. Cross-Layer Cache Reuse: Reducing Independently Stored Historical States
3.1 From “One Copy per Layer” to “Partial Layer Sharing”
Traditional designs usually generate and store KV states separately for different attention layers. Cross-layer reuse allows certain later layers to directly use the keys and values produced by a specified earlier layer, rather than maintaining fully independent caches for those later layers.
A conceptual structure can illustrate this:
Conventional structure:
Layer 1 → independent KV state A
Layer 2 → independent KV state B
Layer 3 → independent KV state C
Layer 4 → independent KV state D
Shared structure:
Layer 1 → generates KV state A
Layer 2 → uses KV state A
Layer 3 → generates KV state B
Layer 4 → uses KV state B
This is only a principle illustration and does not mean an actual model must group adjacent layer pairs. The sharing range, source layer selection, and inter-layer mapping need to be determined through architecture design and training experiments.
If the number of independent cache layers is reduced from L to Lc, while other cache dimensions and data types remain unchanged, the main KV cache capacity can be approximately reduced by a ratio of Lc/L. What is reduced here is the main cache body, not all memory in the entire inference process.
3.2 Shared KV Does Not Mean Sharing the Entire Attention Layer
After reusing historical keys and values, later layers can still generate query vectors from their own hidden states. That is, different layers can use different query methods to extract information from the same set of historical states.
In addition, feed-forward computation, residual connections, and other transformations within a layer may still exist independently. Therefore, cross-layer cache sharing does not mean eliminating later layers, nor does it mean that all shared layers produce identical computation results.
A more accurate meaning is: while retaining some differences in layer-level computation, reduce duplicate storage of historical context representations.
3.3 Arbitrary Existing Models Cannot Simply Be Converted to Shared Cache
Keys and values from different layers come from different hidden representations. Directly making later layers of an already-trained model use another layer’s cache changes the original computation relationships and may degrade output quality.
Therefore, cross-layer reuse usually needs to be considered during architecture design and training, or its feasibility needs to be verified through dedicated adaptation training.
Engineering implementation also needs to satisfy compatibility conditions such as positional encoding, vector dimensions, and attention connectivity. Two cache tensors having the same shape does not prove that they can be safely interchanged.
4. Benefits and Costs of Cross-Layer Reuse
4.1 The Most Direct Benefit Is Lower Cache Capacity
In long-context and high-concurrency scenarios, reducing the number of independent cache copies can help lower memory pressure. The freed space can be used for more requests, longer contexts, or reduced dependence on devices with larger memory.
However, these benefits need to be evaluated against service goals. If the system is mainly limited by model weight capacity, cache reduction may not be enough to change the deployment specification. If it is mainly limited by compute throughput, reducing cache may not significantly improve generation speed.
4.2 It May Reduce Some Projection Computation but Does Not Eliminate Historical Reads
If later layers directly use existing KV states and the architecture no longer requires generating corresponding independent key-value projections, that part of computation may be reduced.
However, each layer may still need to perform attention computation separately between its queries and the historical keys and values. Sharing one cache does not mean multiple layers read the cache only once, nor does it mean attention computations can be automatically merged.
Actual latency gains depend on operator implementation, data layout, memory access patterns, and hardware characteristics. Smaller cache is a relatively clear structural benefit; faster inference needs to be proven by measurement.
4.3 Representational Capacity Must Be Evaluated
Different layers usually handle features at different granularities. Letting multiple layers read the same set of KV states constrains how they represent historical information.
This constraint may bring efficiency benefits and may also affect performance on certain tasks. Particular attention should be paid to long-range information retrieval, complex reasoning, code understanding, multi-turn dialogue, and long-document summarization.
The higher the sharing ratio, the more obvious cache compression usually is, but there is no universally valid conclusion about whether quality remains stable. The reasonable goal is not to maximize sharing, but to find an acceptable balance between task quality and resource cost.
5. Dense Architectures vs. Sparse Expert Architectures: Another Optimization Axis
Dense architectures usually let every token pass through a fixed main computation module. The execution path is relatively stable, making compute volume easier to understand, post-training easier to implement, and runtime optimization easier to perform.
Sparse expert architectures set up multiple expert modules and use a routing mechanism to select some experts for each token to participate in computation. The core idea is to expand total parameter capacity while controlling the parameter scale actually used per token.
However, “fewer activated parameters” does not equal “lower consumption of all resources.”
Expert parameters not activated by a given token still need an available way to be stored and accessed. In distributed deployment, expert allocation may also introduce data communication, load imbalance, and scheduling overhead.
Post-training complexity also depends on the specific scheme. If training needs to update the router or multiple experts, it may increase the difficulty of load balancing, gradient distribution, and parameter management. It is not accurate to simply classify all sparse expert models as “hard to tune,” but these additional factors should be included in evaluation.
Cross-layer cache reuse and sparse expert architectures can coexist: the former mainly adjusts attention historical states, while the latter mainly adjusts computation allocation across expert modules. They address different problems.
6. How to Combine with Other Cache Optimization Methods
6.1 Reduce the Number of KV Heads
Letting multiple query heads share fewer KV heads can reduce cache capacity along the head dimension. Cross-layer reuse reduces the number of independent cache copies along the layer dimension.
In principle, the two can be combined, but the combined quality and performance must be evaluated as a whole. Final results cannot be inferred only from the benefit of each individual item.
6.2 Use Low-Precision Cache
Reducing the storage precision of cache elements can further reduce capacity and data transfer volume. However, quantization may introduce errors, and additional metadata plus quantization and dequantization computation need to be considered.
If the architecture already shares cache, quantization errors may also be received jointly by multiple consuming layers, so stability under long context should be validated more carefully.
6.3 Adopt Local or Sparse Attention
Reducing the historical positions that need to be accessed at each step can affect both cache management and attention computation volume. However, it changes the range of context the model can directly access and cannot be regarded as an unconditional equivalent replacement for full attention.
6.4 Optimize Cache Management and Request Scheduling
Block-based cache allocation, timely release of states for finished requests, reuse of identical prefixes, and scheduling based on request length are all inference-system-level optimizations.
Among them, identical-prefix reuse and cross-layer reuse are two different concepts: the former occurs across different requests, while the latter occurs across different layers of the same model.
7. How Developers Should Build a Validation Workflow
Step 1: Identify Resource Bottlenecks
Record weight occupancy, cache occupancy, temporary workspace, and peak memory separately. Do not only observe device utilization or total memory.
Also distinguish the prefill phase from the token-by-token decoding phase. The former processes the entire input, while the latter continuously reads historical states. Their performance bottlenecks may differ.
Step 2: Build Realistic Workloads
Tests should cover short input with long output, long input with short output, multi-turn accumulated dialogue, and concurrent requests with mixed lengths.
Testing only a single short request makes it difficult to reflect the value of cache optimization in actual service.
Step 3: Measure Quality and Performance Together
At minimum, consider:
- Time to first token;
- Per-output-token generation latency;
- Total throughput;
- Peak memory;
- Request completion rate;
- Long-context task quality;
- High-percentile latency under concurrency.
If a throughput improvement is accompanied by obvious quality degradation or worse high-percentile latency, it cannot be directly treated as a deployment benefit.
Step 4: Run Component-by-Component Comparisons
Validate cross-layer sharing, low-precision cache storage, and scheduling optimization separately, then test combined schemes. This helps identify the source of benefits and avoid conflating the effects of multiple mechanisms.
Comparisons should use the same hardware, input and output lengths, concurrency conditions, and generation settings; otherwise, test results lack comparability.
8. Conclusion: Architecture Optimization Must Translate into Verifiable System Gains
The core of large model architecture evolution is not adding more structural names to a model, but reorganizing the relationship among representation, computation, and storage.
Cross-layer KV cache reuse provides a clear path: reduce independent storage of historical states across different layers and alleviate resource pressure in long-context inference. But it is not a universal runtime switch, nor can it guarantee equal benefits across all tasks.
For developers and enterprise technical teams, the truly effective selection method is to start from business workloads and jointly evaluate model quality, cache capacity, compute overhead, and operational complexity. Only when the potential advantages of an architecture are translated into repeatable, measurable system gains is efficiency optimization truly complete.
