LLM Architecture Evolution: KV Cache Compression and Efficient Inference

    This article explains how LLM architecture evolution targets inference cost by separating parameter organization, attention-state management, and runtime optimization. It details why KV cache becomes the main long-context bottleneck, how capacity scales with context length and concurrency, and how cross-layer sharing, KV-head reduction, cache quantization, sliding-window attention, paged management, and prefix reuse address different constraints. It also compares dense and mixture-of-experts architectures and outlines an evaluation and rollout approach that ties quality checks to resource measurements for reasoning and agent workloads.

    1. Architecture Evolution Priorities: Improve Capability and Reduce Runtime Cost

    When discussing large language model (LLM) architecture, parameter scale often receives the most attention. In real deployments, however, whether a model can run reliably depends not only on weight size but also on context length, concurrent request count, generation length, and the intermediate state that must be retained during inference.

    For short question answering, model weights may be the main source of GPU memory usage. For long-document analysis, multi-turn dialogue, and agent tasks, the key-value cache often becomes another major bottleneck. Even when model weights fit into device memory, a continuously growing cache can still limit the context length and concurrency that can be handled.

    LLM architecture evolution can therefore be understood through three interrelated directions:

    • Parameter organization: Adjust model capacity and per-inference computation through dense structures or mixture-of-experts structures.
    • Attention-state management: Reduce the key-value state that must be stored, lowering memory pressure for long-sequence inference.
    • Runtime optimization: Improve cache allocation, batching, and execution scheduling to reduce resource waste in actual serving.

    These directions solve different problems. Reducing parameter computation does not necessarily make the cache smaller, and lower cache usage does not mean end-to-end latency will fall by the same proportion. Technical selection first requires identifying the actual bottleneck.

    2. Why KV Cache Becomes the Core Cost of Long Context

    2.1 The Role of Cache: Avoid Recomputing Historical State

    Autoregressive language models usually generate tokens one at a time. When generating a new token, attention computation needs to access the keys and values corresponding to historical positions.

    If the key-value state for all historical positions were recomputed at every step, a large amount of duplicate work would result. The key-value cache, or KV cache, retains these states so that later generation can reuse information that has already been computed.

    It is important to note that the KV cache reduces duplicate computation such as historical key-value projection; it does not eliminate attention computation between the new query and historical state. As context grows, the historical state that each new token must read and include in computation may still increase.

    2.2 A Convenient Capacity Estimate

    For a standard implementation that stores key-value state independently per layer, the following approximation can be used to estimate cache capacity:

    Cache bytes ≈ 2 × B × T × L × Hkv × Dh × S

    Where:

    • B: number of concurrently resident sequences;
    • T: cache length per sequence;
    • L: number of layers that independently store key-value state;
    • Hkv: number of key-value heads per layer;
    • Dh: dimension of each head;
    • S: bytes per element;
    • 2: corresponds to keys and values.

    This formula does not include memory alignment, paged management, quantization metadata, or runtime temporary buffers, so it can only serve as a basic estimate.

    For example, in a purely hypothetical configuration, if a single sequence has 32 layers, 8 key-value heads, a head dimension of 128, a cache length of 32768, and 2 bytes per element, the theoretical KV cache capacity is about 4 GiB. This number is only used to show the growth pattern and does not represent the actual configuration or performance of any specific model.

    The most important factor is the multiplicative relationship: when context length and concurrency rise together, cache pressure is amplified by both.

    3. Cross-Layer KV Cache Sharing: Reducing the Number of Independent States

    3.1 From “Independent Storage per Layer” to “Reuse Across Some Layers”

    In conventional attention structures, different layers usually generate keys and values from their own hidden states, so each layer must maintain its own cache.

    The idea of cross-layer key-value state sharing is that some layers produce key-value representations, and other layers directly use those representations to perform attention computation, reducing the number of independent cache sets.

    This can be abstracted as:

    1. State-producing layer:
    2. Generate the key and value for the current token
    3. Write them to the shared cache for this layer group
    4. State-consuming layer in the same group:
    5. Generate the query for this layer
    6. Compute attention using keys and values from the shared cache
    7. Continue with the remaining transformations for this layer

    What is shared here is not the entire layer output, nor does it mean that multiple layers have exactly the same computation process. Queries, output transformations, and other sublayers can still retain their own parameters and behavior.

    3.2 Main Benefits and Boundaries

    If multiple layers share one cache set, the number of independent cache layers in the formula may decrease. All else being equal, idealized key-value storage capacity falls with the number of independent cache sets.

    In addition, if consuming layers no longer generate key-value state separately, some key-value projection computation and cache write overhead may be reduced. This benefit cannot be directly equated with overall inference speedup, however, because attention reads, feed-forward computation, data transfer, and execution scheduling still remain.

    Two concepts must be distinguished:

    • Storing fewer copies of state directly affects cache capacity;
    • Executing fewer computations and moving less data affects actual latency and throughput.

    The two are related, but they are not a simple one-to-one correspondence.

    3.3 Why It Is Not a Switch for Arbitrary Models

    Hidden representations at different layers have different semantic roles. Letting later layers use key-value state generated by earlier layers changes the information interface of attention and may limit the independence of representations across layers.

    Therefore, cross-layer sharing usually needs to be coordinated during architecture design and training. It cannot be achieved by simply deleting caches from any already-trained model.

    A specific design needs to answer:

    • Which layers produce shared state?
    • How many layers are in each group?
    • Are only some layers shared?
    • Is adaptation needed between queries and shared keys and values?
    • Does information retrieval capability remain intact under long-context conditions?

    A larger sharing scope usually brings more obvious potential storage benefits, but model expressiveness and training stability must be validated more carefully.

    4. Cache Optimization Has More Than One Path Beyond Cross-Layer Sharing

    4.1 Reduce KV Heads: Compress Repeated State Along the Head Dimension

    Grouped-query attention lets multiple query heads share one set of key-value heads, reducing the number of key-value heads. Multi-query attention goes further by using a single set of key-value heads.

    These methods mainly reduce Hkv in the formula; cross-layer sharing mainly reduces the number of independent cache sets. They act on different dimensions and can in principle be combined, but quality after combination must be re-evaluated.

    The fact that two methods are individually effective does not mean that stacking them will preserve the same accuracy.

    4.2 Lower Cache Precision: Reduce Storage Cost per Element

    Cache quantization reduces the number of bytes occupied by each element by lowering the storage precision of key-value state.

    The actual benefit depends on the quantization method, auxiliary metadata, dequantization overhead, and execution implementation. Keys and values may also differ in sensitivity to error, so the same strategy should not be mechanically applied to all states.

    For long-document localization, exact numeric extraction, and structured output, specifically check whether low-precision cache introduces hard-to-detect errors.

    4.3 Limit Visible History: Reduce Cache Length

    Sliding-window attention accesses only historical positions within a certain range, which can limit cache growth and some attention computation cost.

    It differs fundamentally from shared cache: shared cache changes how state is organized, while window limits directly change the range of information the model can access. If information outside the window has no other retention mechanism, later positions cannot directly attend to it.

    Therefore, “being able to accept a very long input” and “being able to perform full attention access over all history” should not be conflated.

    4.4 Paged Management and Prefix Reuse: Optimize Waste at the Serving Layer

    Paged cache management organizes state into smaller storage blocks, which can improve memory allocation under dynamic request lengths and reduce waste caused by some preallocation strategies.

    Prefix reuse targets requests with the same input prefix by reusing the corresponding historical state, reducing duplicate processing.

    These two methods mainly improve runtime management and inter-request duplication; they do not automatically reduce all key-value information contained in a single full sequence. Prefix reuse must also ensure compatibility of the model, input, and relevant execution conditions, while enforcing tenant isolation and access control to prevent cross-user information exposure.

    5. Dense and Mixture-of-Experts Architectures: Solving Another Class of Efficiency Problems

    5.1 Dense Architecture: A More Direct Execution Path

    A dense architecture usually passes every token through all relevant parameter modules. Its computation path is relatively regular, making it easier to establish a consistent engineering baseline for training, deployment, and post-training workflows.

    But “a more direct workflow” does not mean “cost is always lower.” At the same total parameter scale, a dense structure usually needs to activate more parameters; the specific cost still depends on layer count, dimensions, precision, and execution implementation.

    5.2 Mixture-of-Experts Architecture: Expand Capacity with Sparse Activation

    A mixture-of-experts architecture usually places multiple experts in some feed-forward modules and uses a routing mechanism so that each token accesses only some experts. Total parameter count and activated parameter count therefore need to be discussed separately.

    This design has the opportunity to increase model capacity while controlling per-token computation, but it also introduces new engineering challenges:

    • Load across experts may be imbalanced;
    • Distributed execution may introduce additional communication;
    • Small batches may not fully utilize all devices;
    • Post-training needs to monitor the distribution of routing and expert updates.

    At the same time, a mixture-of-experts structure does not automatically compress attention cache. For long-context serving, the storage method for key-value state still needs to be designed separately.

    6. Evaluation Methods for Reasoning Tasks and Agent Applications

    Reasoning tasks may produce longer outputs, while agent workflows may continuously accumulate tool results, environment feedback, and historical decisions. Once this content enters the model context, it increases cache length and attention access cost.

    Evaluation should therefore not rely only on a single short question-answering run. It should build a test matrix close to real business workloads.

    6.1 Divide Tests by Sequence Length and Concurrency

    At minimum, cover short, medium, and long inputs, as well as short and long outputs, and test at different concurrency levels.

    Focus on observing:

    • Time to first token;
    • Subsequent token generation speed;
    • Peak GPU or memory usage;
    • Stable throughput;
    • High-percentile request latency;
    • Out-of-memory and request failure rates.

    The bottleneck in the input processing stage and the token-by-token generation stage may differ, so they must be analyzed separately.

    6.2 Bind Quality Validation to Resource Validation

    A smaller cache is only an engineering result, not the final goal. Check whether the optimized system can still perform:

    • Precise information localization in long documents;
    • Integration of constraints across paragraphs;
    • Condition retention in multi-turn dialogue;
    • Generation of numbers, code, and structured fields;
    • Consistency of tool-call parameters.

    In particular, note that a similar overall score does not mean there is no degradation in critical business scenarios.

    6.3 Use a Progressive Rollout Strategy

    Establish a quality and resource baseline before optimization, then introduce optimizations one by one to make the source of benefits clearer.

    If architecture, cache precision, context strategy, and scheduling are changed at the same time, even if performance improves, it is difficult to determine which change produced the benefit, and even harder to locate the cause of quality degradation.

    After rollout, continue monitoring the actual request length distribution, cache usage, latency, and task success rate, and retain rollback configurations.

    7. Conclusion: Drive Architecture Choices by Bottlenecks and Quality Boundaries

    Efficient LLM inference is the combined result of parameter structure, attention design, and runtime management.

    The core value of cross-layer KV cache sharing is to reduce state repeatedly stored per layer; KV-head reduction and cache quantization compress head count and element size, respectively; window mechanisms control accessible history; paged management and prefix reuse improve resource utilization in serving. Dense and mixture-of-experts structures mainly adjust parameter capacity and computation paths.

    For developers, a reasonable decision order is: first identify the GPU memory, computation, bandwidth, or communication bottleneck; then select the corresponding optimization method; finally validate quality and cost on real tasks. Only within this loop can architecture improvements translate into sustainable long-context capability, more stable concurrent serving, and more controllable inference cost.