Breaking the GPU Memory Bottleneck: Designing and Validating Cache Offloading and Prefetching for Sparse Attention Models
This article explains how Latent Cache growth limits decode batch size in long-context LLM inference under prefill-decode (PD) disaggregation. It shows why naive CPU offloading runs into PCIe bandwidth limits, and describes the ESS (Expanded Sparse Server) design, which combines cache offloading with micro-batch prefetching and pipeline overlap. It also reports simulation results for 32K and 128K contexts, gives deployment tuning guidance, and identifies the workloads where the approach fits best.
1. Overview: The GPU Memory Challenge in Long-Context Inference
Large language models are increasingly used for code generation, long-document analysis, and multi-turn dialogue. Context lengths are growing from a few thousand tokens to tens or hundreds of thousands of tokens. Longer context improves what the model can understand, but it also makes inference resource scheduling harder. In a PD-disaggregated architecture, the Prefill stage processes the input sequence and produces the KV Cache, and the Decode stage generates output one token at a time from that cache. Ideally, the two stages scale independently, so that resource utilization stays high. In practice, however, the Decode stage faces a structural conflict. The size of the Latent Cache (the key-value cache used in sparse attention) grows linearly with sequence length, while GPU memory capacity stays fixed. The longer the context, the sharper this conflict becomes.
Take a 32K context at batch size 1 as an example. The Latent Cache can occupy more GPU memory than the model weights themselves. When batch size increases, the cache quickly fills the available memory of the card. As a result, the GEMM operators cannot reach their full compute intensity. Decode throughput can be approximated as the ratio of batch size to the latency of generating one token. The memory ceiling caps the batch size, so GPU compute sits idle and cannot turn into generation speed. Breaking through this ceiling is not only a matter of adding hardware. The organization, storage, and scheduling of the cache must be rethought at the system architecture level.
2. Problem Analysis: Latent Cache Characteristics and Resource Constraints
2.1 Sparse Nature of Latent Cache and Memory Footprint Model
Traditional attention stores the KV Cache densely. Latent Cache, by contrast, uses the computational characteristics of sparse attention. During scoring, it keeps only the small number of key-value pairs that contribute most to the current query. This reduces the amount of computation significantly, but the cache data structure still has to preserve the semantic information of the full sequence. From a storage perspective, the memory footprint of Latent Cache scales approximately linearly with context length. The bytes needed per token depend on the model’s hidden dimension, the number of attention heads, and the sparsity configuration. In typical MoE models, the cache can reach several times the size of the weights, which makes it the largest single consumer of GPU memory.
2.2 Nonlinear Relationship Between Batch Size and Throughput
Simulation data shows that raising batch size from 8 to 16 increases Decode throughput by about 35%. Raising it from 32 to 64, however, yields much smaller gains, and throughput falls back at the edge of memory exhaustion. Two factors cause this nonlinearity. First, the compute intensity of GEMM operators rises with batch size, but beyond a certain threshold, memory bandwidth becomes the new bottleneck. Second, each doubling of batch size requires the cache capacity to double as well. The hard limit on GPU memory keeps batch size below a specific threshold. Simply increasing batch size to raise throughput therefore hits a ceiling, and external storage resources must be introduced.
2.3 Key Breakthrough: Coordinating Offloading and Prefetching
Moving Latent Cache to CPU memory relieves GPU memory pressure, but it introduces PCIe bandwidth limits. On a typical current server, the PCIe 5.0 x16 link between a GPU and the CPU provides about 64 GB/s of unidirectional bandwidth. An 8-GPU server has a total bandwidth of about 512 GB/s. At large batch sizes, each decode step must read the entire cache back from CPU memory to the GPU. The data volume can reach tens of gigabytes, far beyond what the link can carry. A naive offloading scheme therefore sharply increases memory access latency and can cancel out the benefit of freeing GPU memory.
The key to solving this lies in when and how much to prefetch. Decode runs one token at a time, and each token depends on the full contents of the current cache. If the cache prefetch for all sequences in a batch is split into several micro-batches, the cache blocks needed for the next micro-batch can be fetched in parallel while the previous micro-batch is being computed. This creates a pipeline in which computation and transfer overlap. The core idea of this Offload-Prefetch mechanism is to move memory access latency off the critical path and turn it into background transfer time. The GPU can free memory and keep its compute cores busy at the same time.
3. ESS Design: A Systematic Approach to Decoupling Storage and Compute Paths
3.1 Overall Architecture and Core Idea
Based on the analysis above, Baidu Baige’s AI AK team designed the ESS (Expanded Sparse Server) system. The central idea of ESS is to fully separate the storage path of Latent Cache from its compute path. GPU memory holds only the working set of cache needed for the current computation, while the complete cache is kept in CPU memory. ESS uses three layers to achieve this:
- Cache Management Layer: Maintains a global cache directory. It records where each sequence’s cache blocks sit in CPU memory, along with their state and access frequency, and it handles the allocation and reclamation of cache blocks.
- Prefetch Scheduler: Generates an optimal prefetch plan based on fine-grained timing information from the model’s computation stages. The scheduler monitors the current GPU memory level, the number of completed token steps, and PCIe link utilization. It adjusts the prefetch batch size and concurrency dynamically.
- Transfer Engine: Uses asynchronous DMA channels to write prefetched data directly into a reserved buffer in GPU memory. The engine supports multiple concurrent streams, so it can handle cache block read requests for several sequences at the same time.
3.2 Compatibility with Mainstream Optimization Strategies
ESS was designed from the start to work alongside existing mainstream inference optimizations. Take MTP (Multi-Token Prediction) as an example. MTP lets the model predict several subsequent tokens in a single forward pass, which spreads the fixed cost of each token across more output. The ESS prefetch plan can align with the MTP prediction window. When the window contains K tokens, the prefetch scheduler issues cache read requests K steps in advance, so the data is ready when computation reaches it. ESS also naturally supports batch overlap. A batch is split into two sub-batches. While sub-batch A is computing, the cache for sub-batch B is prefetched. Communication and computation for the two sub-batches alternate, so compute resources stay busy.
3.3 Key Implementation Details
ESS uses fixed-size cache blocks, such as 32 KB to 128 KB, as the basic transfer unit instead of transferring entire sequences. This design offers two advantages. First, fine-grained transfers keep PCIe link utilization more even and prevent idle periods caused by large transfers. Second, block-level management enables an LRU eviction policy for cache blocks. When GPU memory usage exceeds its limit, the blocks least likely to be accessed soon are evicted first, which further improves memory flexibility.
For CPU memory management, ESS uses huge page allocation and NUMA-aware binding. These reduce TLB misses and cross-NUMA access latency. Measurements show that huge pages can lower the average memory access latency of cache reads by about 30%. ESS also sets up a multi-level buffer on the transfer path. After the CPU reads a cache block, the block is first stored in a user-space buffer. The DMA engine then writes it directly into GPU memory, which avoids extra memory copy overhead.
4. Simulation Validation: Building a High-Fidelity Simulator and Designing Experiments
4.1 Why a Simulator and What It Models
Building a high-fidelity simulator before implementing the system helps determine the potential gains of the approach before committing engineering effort. It also allows quick parameter sweeps across different configurations. The simulator models three key dimensions:
- Compute model: Estimates the GEMM compute time of each decode step from parameters such as the hidden dimension, the number of attention heads, and batch size. Compute time scales approximately linearly with batch size, and the model accounts for memory bottlenecks when compute intensity is limited.
- Communication model: Simulates the transfer time of cache data from CPU to GPU based on PCIe bandwidth, transfer block size, and concurrency. Transfer time depends not only on data volume but also on link switching overhead and DMA descriptor processing overhead.
- Dependency model: Describes the dependencies between compute and prefetch stages precisely. It distinguishes memory waits on the critical path from background transfers off the critical path, which allows the actual effect of pipeline overlap to be evaluated.
4.2 Experimental Setup and Baseline
The simulation experiments use an 8-GPU server as the baseline environment. Each GPU has 80 GB of memory. The server has 512 GB of CPU memory and PCIe 5.0 x16 links. The model configuration uses parameters comparable to mainstream sparse attention models: a hidden dimension of 7168, 128 attention heads, 61 layers, and a configurable MTP window. The evaluation metrics are end-to-end Decode throughput (tokens/s) and normalized throughput efficiency.
4.3 Results and Interpretation
Experiment 1: At a 32K context length, increasing the MTP window from 2 to 4 raises ESS end-to-end throughput by 123.4%. Attribution analysis shows that the larger MTP window alone contributes about 43% of the gain through improved computational efficiency. The remaining 57% comes from the Offload-Prefetch mechanism, which makes a larger batch size possible. With ESS enabled, the batch size limit rises from 16 to 48, which lets the GEMM operators use their compute intensity more fully.
Experiment 2: For ultra-long contexts, with MTP=2 and a 128K context length, the Offload-Prefetch mechanism increases throughput by 123%. The result matters most for long contexts. Without ESS, batch size at 128K is limited to 2 to 4, and memory access waits take up nearly all GPU time. With ESS enabled, batch size rises to 12 to 16. Prefetching also hides communication latency behind computation, so Decode throughput improves by an order of magnitude.
5. Deployment Guidance and Limitations
5.1 Parameter Tuning Guide
In a real deployment, the following parameters strongly affect the results of ESS:
- Prefetch window size: The prefetch window sets how many cache blocks each prefetch request includes. A window that is too small adds scheduling overhead, while one that is too large can waste GPU memory. Experiments show that setting the prefetch window to 1 to 2 times the number of MTP predicted tokens gives the best balance between bandwidth utilization and memory efficiency.
- CPU memory allocation: Use huge pages and bind processes to the NUMA node adjacent to the PCIe controller. With huge pages, the TLB miss rate can drop from above 0.1% to below 0.01%, which reduces CPU-side access latency.
- Transfer concurrency: At large batch sizes, spread cache block reads across several asynchronous transfer streams. Concurrency should stop at the point where the PCIe link reaches saturation. In this experimental environment, 4 to 8 concurrent streams reached more than 90% of link bandwidth.
5.2 Applicable Scenarios and Limitations
ESS is not suitable for every workload. When the context is short (under 8K tokens) and the batch size is small (under 4), the Latent Cache footprint may not become a bottleneck. In that case, the communication overhead of offloading can reduce performance. In shallow, small models with low compute density, the throughput ceiling stays low even after memory limits are lifted, so ESS offers limited gains there. The best fit is inference workloads with context lengths above 16K and model sizes in the tens of billions of parameters or more.
5.3 Conclusion: From Cache Offloading to Systematic Co-Optimization
ESS provides a systematic way to schedule cache resources. It treats GPU memory as fast but scarce working memory and CPU memory as the persistent main storage tier. Data prefetching and pipeline overlap close the performance gap between the two. This design addresses the memory access latency that cache offloading creates for Latent Cache, and it redefines the compute-to-storage resource balance in the Decode stage. It offers a new dimension for optimizing large-scale LLM inference deployments.
Future work could explore scheduling optimizations that account for PCIe link bandwidth, stronger links between cache block placement and access frequency, and combined data redundancy and remote storage across multiple nodes. That would allow cross-machine resource pooling and smoother scaling of compute. As models grow more capable and context lengths keep increasing, memory management has become a core technical factor in the cost and experience of LLM services, and it remains an area worth sustained investment.
