LLM Architecture Evolution: KV Cache Reuse and Sparse Computing

    Explore the core optimization strategies driving Large Language Model (LLM) architecture evolution, focusing on Key-Value (KV) cache reuse, Mixture of Experts (MoE), and dense models. This guide explains how to balance model quality, computational overhead, and memory footprint in real-world applications. Learn how to identify bottlenecks based on specific deployment scenarios and establish a reproducible validation workflow to inform your architecture choices.

    1. The Core of Architecture Evolution: Beyond Scaling Up

    When discussing architectural changes in Large Language Models (LLMs), it is insufficient to merely compare parameter sizes. For practical applications, equally critical questions include: Can the model fit into the target device? Does long conversation history cause sustained memory growth? Can the system respond stably under multi-user concurrency? And can the model retain its original capabilities after domain adaptation?

    These challenges correspond to several distinct resources:

    • Weight Storage: Storing model parameters, which forms the baseline cost for model loading and deployment.
    • Runtime State: Includes the attention Key-Value (KV) cache, intermediate activations, and operator workspaces.
    • Compute Resources: Utilized for matrix multiplication, attention computation, and expert network execution.
    • Data Transfer Capacity: Encompasses device memory bandwidth and inter-device communication bandwidth.

    Therefore, architectural optimization should revolve around the trade-offs among “model quality, compute overhead, memory footprint, and deployment complexity,” rather than pursuing a single metric.

    Within this framework, cross-layer KV cache reuse primarily addresses the redundant storage of inference states; the Mixture of Experts (MoE) architecture improves the flexibility between total parameter capacity and per-token activated compute; while dense architectures offer advantages in execution path consistency and simplicity of training and deployment. These three approaches solve different problems and cannot simply replace one another.

    2. Understanding KV Cache: Why Long Conversations Consume More Memory

    1. What Does the Cache Actually Store?

    During the autoregressive generation process, the model predicts the next token based on existing content at each step. For models using causal self-attention, the keys and values of historical positions can be retained and read directly during subsequent generation, eliminating the need to recompute the key-value representations for all historical positions at every step. This state is commonly referred to as the KV Cache.

    It is important to note that the cache does not eliminate attention computation. The newly generated position still needs to access historical keys and values based on its query vectors. As the context grows, both the cache capacity and the read overhead increase.

    2. How to Estimate Cache Capacity

    Under simplified conditions where cache configurations are consistent across layers and standard full-context caching is used, the cache capacity can be estimated as follows:

    Cache Bytes ≈ 2 × num_layers × num_concurrent_sequences × cached_sequence_length × num_kv_heads × dimension_per_head × bytes_per_element

    The coefficient 2 represents the two components: keys and values.

    For example, assume a model has the following configuration:

    • 32 attention layers;
    • 8 KV heads;
    • 128 dimensions per head;
    • 2 bytes per cache element;
    • A cache length of 8192 for a single sequence.

    The KV cache for a single sequence would be approximately:

    2 × 32 × 8192 × 8 × 128 × 2 = 1 GiB

    This is a hypothetical example to explain the order of magnitude, not the parameters or measured data of any specific model. Actual services must also account for memory allocation fragmentation, cache management metadata, temporary workspaces, and additional overhead caused by varying request lengths.

    This illustrates a key point: Just because model weights can fit into a device does not guarantee that long-context, high-concurrency services will run stably.

    3. Cross-Layer KV Reuse: Reducing Redundant State, Not Blind Merging

    1. From Independent to Shared Caching

    In conventional designs, each attention layer typically maintains its own key-value representations and cache. The concept of cross-layer KV reuse allows a group of compatible attention layers to share the key-value representations generated by a source layer or a common computation path, while different layers can still use their own query representations for attention computation.

    The conceptual relationship is as follows:

    Independent Caching Approach:

    Layer 1 Query → Layer 1 KV Cache
    Layer 2 Query → Layer 2 KV Cache
    Layer 3 Query → Layer 3 KV Cache

    Cross-Layer Sharing Approach:

    Layer 1 Query ─┐
    Layer 2 Query ─┼→ Shared KV Cache
    Layer 3 Query ─┘

    Specific designs might only share among a subset of layers or use grouped sharing. This concept should not be misunderstood as “all layers unconditionally using the exact same cache.”

    2. Where Theoretical Savings Come From

    Under ideal conditions with identical layer configurations, if multiple layers in a group save only a single KV cache, the portion of cache capacity associated with independent cache layers decreases proportionally.

    However, overall system memory will not decrease by the exact same ratio because model weights, query computation, intermediate activations, and other runtime states still exist. If the architecture requires additional mapping or adaptation computation, these costs must also be factored in.

    Similarly, a reduction in cache capacity does not equate to a proportional increase in generation speed. Different layers may still need to read the shared cache separately, and actual gains depend on memory access patterns, cache hit rates, and underlying operator implementations.

    3. Why You Cannot Arbitrarily Modify Existing Models

    Different layers typically handle different levels of representational transformation, meaning their key-value distributions do not necessarily align. Directly replacing independent caches with a single shared state may cause a mismatch between queries and key-values, leading to a degradation in quality.

    Therefore, cross-layer KV reuse is fundamentally an issue of co-designing the architecture and training. It usually requires learning shared constraints during training, or undergoing specialized adaptation and thorough validation. It is not a universal deployment switch that can be enabled losslessly on any arbitrary model.

    4. Distinction from Other Cache Optimizations

    Several common optimizations target different dimensions:

    • Reducing the number of KV heads: Decreases the number of key-value representations that need to be saved per layer.
    • Cross-layer KV sharing: Reduces independently saved states across different layers.
    • Reducing cache precision: Decreases the number of bytes occupied by each cache element.
    • Local or sliding window attention: Restricts the historical range that certain layers need to retain or access.
    • Paged cache management: Improves memory allocation and fragmentation issues, generally without altering the actual size of each valid cache element.

    These methods can be combined when design-compatible, but the combined quality and performance cannot be inferred solely from individual results.

    4. Mixture of Experts: Expanding Capacity Without Engaging All Parameters Simultaneously

    1. Total Parameters vs. Activated Parameters

    The Mixture of Experts (MoE) architecture typically sets up multiple expert sub-networks at certain feed-forward network positions, using a routing mechanism to select a subset of experts for each token.

    Consequently, two concepts must be distinguished:

    • Total Parameters: All parameters contained within the model.
    • Activated Parameters: The parameters actually involved in computation when processing a single token.

    This design allows for increasing model capacity while controlling the partial computational overhead per token. However, fewer activated parameters does not mean all weights do not need to be stored. Expert parameters still need to reside in device memory, or be managed through tiered storage and dynamic loading.

    2. Why Sparse Computing Isn’t Necessarily Faster

    Actual inference also includes costs for expert selection, token dispatch, result aggregation, and load balancing. In multi-device deployments, data exchange between experts can also become a bottleneck.

    When request batches are small, expert weight access is scattered, or communication overhead is high, the theoretical computational savings may not fully translate into latency advantages. Therefore, inference speed cannot be judged solely based on activated parameter count, nor can the memory requirements brought by total weights be ignored.

    3. Additional Training and Post-Training Challenges

    Expert routing may experience load imbalance: a few experts are frequently selected, while others receive less training signal. After domain data adaptation, the input distribution changes, which can also alter routing behavior.

    Therefore, in addition to task loss, you should monitor expert utilization, load distribution, and routing changes before and after domain adaptation. MoE is not inherently difficult to tune, but it adds a layer of complexity regarding routing and expert coordination compared to a single-path network.

    5. Dense Architecture: The Engineering Value of Unified Execution Paths

    Dense models typically pass each token through the same primary network modules. Compared to structures with dynamic expert routing, the computation path is more consistent, making performance analysis and fault localization more straightforward.

    This characteristic has practical significance in the following scenarios:

    • Requiring frequent domain adaptation and regression validation;
    • Fixed deployment environments where simplified runtime management is desired;
    • High requirements for latency stability in small-batch requests;
    • Teams looking to reduce the operational complexity of distributed expert scheduling and communication.

    However, a dense architecture does not inherently guarantee higher quality, nor does it mean post-training will definitely be more successful. Model effectiveness still depends on data, training methods, parameter scale, and task characteristics. The sensible approach is to compare actual deployment costs under similar quality goals, rather than pre-assuming that one structure is universally superior.

    6. Deployment Scenarios Dictate Optimization Priorities

    1. Mobile and Embedded Devices

    These devices are typically constrained by memory, power consumption, thermal limits, and sustained operation capability. Evaluations should prioritize weight footprint, maximum cache capacity, and sustained generation speed, rather than just short-term peak performance.

    Even with a low model parameter count, long contexts can still make the cache a primary burden. You should set context budgets based on real tasks, combined with low-precision representations, cache optimization, or controlled historical information compression. Historical compression may lose details, requiring separate validation of key fact retention.

    2. Local Workstations and Single-Device Services

    The core issue in these scenarios is resource headroom. Beyond model weights, space should be reserved for target concurrency, input length fluctuations, and runtime workspaces.

    If daily tasks consist primarily of short requests, over-pursuing extremely long contexts may reduce overall resource utilization. A more robust approach is to differentiate between routine requests and ultra-long requests, establishing separate resource budgets and service policies.

    3. Multi-Device High-Throughput Services

    In large-scale services, weight sharding, expert distribution, request scheduling, and inter-device communication should be analyzed jointly. MoE may increase communication sensitivity, while cache optimization may boost the supportable concurrency; however, the final benefit still depends on whether the bottleneck lies in compute, memory, or network.

    7. Establishing a Reproducible Architecture Validation Workflow

    Step 1: Fix Quality and Load Conditions

    Before comparing different architectures, clarify the task suite, input-output length distributions, generation strategies, numerical precision, and concurrency methods. Otherwise, performance differences may stem from test conditions rather than the architecture itself.

    Quality evaluation should not only include short-text tasks but also cover long-text information retrieval, multi-turn constraint retention, complex reasoning, and domain-specific knowledge QA.

    Step 2: Test Input Processing and Token-by-Token Generation Separately

    The input processing phase digests existing context, while the token-by-token generation phase repeatedly reads historical states. The bottlenecks for these two phases may differ, so record them separately:

    • Time to First Token (TTFT) latency;
    • Subsequent token generation latency;
    • Total request duration;
    • Peak device memory;
    • Stable throughput;
    • High-percentile latency and failure rates.

    Averages cannot fully reflect user experience, making it particularly necessary to focus on tail latency under long-request and high-concurrency conditions.

    Step 3: Conduct Single-Variable Experiments

    Cache precision, sharing scope, batch size, and scheduling strategies should be adjusted individually wherever possible. If multiple configurations are modified simultaneously, even if performance improves, it becomes difficult to determine the source of the gains and potential quality risks.

    Step 4: Validate Post-Training Performance

    An architecture performing well on baseline tasks does not guarantee stability after domain adaptation. You should simultaneously check task-specific gains, general capability regression, and long-context performance. For MoE, expert loads should be re-examined; for cross-layer KV sharing designs, focus on observing whether shared constraints affect deep reasoning and long-range information access.

    8. Conclusion: Let Real Bottlenecks Drive Architecture Choices

    The evolution of LLM architectures is essentially about maintaining or enhancing effective capabilities within more constrained resources.

    Cross-layer KV reuse targets inter-layer state redundancy; MoE leverages sparse activation to adjust the relationship between model capacity and compute volume; while dense architectures retain the engineering advantages of a unified execution path. None of them is absolutely superior outside of a specific context.

    For developers, the reliable approach is: First, determine the task quality threshold. Next, identify the primary bottleneck among weights, cache, compute, and communication. Finally, validate optimization effects through reproducible experiments. Only when requirements for quality, latency, throughput, memory, and maintenance costs are simultaneously met do architectural improvements translate into deliverable system value.