TL;DR
LeanSparse is a memory-efficient serving system designed for native sparse-attention LLMs (like DeepSeek-V4) that enables processing massive contexts up to 1M tokens. By implementing layer-wise prefill streaming and a coarse-to-fine indexing strategy for decoding, it achieves nearly 3x higher request concurrency and reduces median Time to First Token (TTFT) from 21.6 seconds to just 0.6 seconds.
What Problem Does This Paper Address?
As Large Language Models (LLMs) move toward million-token context windows, GPU memory (HBM) has become the primary bottleneck. Native sparse-attention models attempt to solve this by only attending to a small, learned subset of historical tokens. However, existing serving systems face two major hurdles:
- Persistent Indexer Residency: Even if the actual Key-Value (KV) cache is offloaded to host RAM, the "indexer keys"—used by the model to decide which tokens to attend to—typically remain on the GPU. As shown in Figure 1, at 512K tokens, these indexer keys can occupy 7.2x more space than the active KV buffer, severely limiting how many requests a GPU can handle simultaneously.
- Prefill Memory Spikes: The prefill phase (processing the initial prompt) requires significant temporary memory. In shared environments, a new request often has to wait for existing decoding tasks to finish and release memory before it can even start prefilling, leading to massive delays in responsiveness.
Methods
LeanSparse introduces two primary architectural innovations to break these bottlenecks:
1. Layer-wise Prefill Streaming
Instead of keeping a request's entire prefix history in GPU memory during prefill, LeanSparse recognizes that the model processes data one layer at a time. The system uses a double-buffering approach: while the GPU computes one layer using "Buffer A," it simultaneously streams the next layer's prefix data from host memory into "Buffer B." This overlaps data transfer with computation, keeping the memory footprint constant regardless of the number of layers.
2. Coarse-to-Fine Decode Indexing
To avoid keeping all indexer keys on the GPU during decoding, LeanSparse uses a two-stage search:
- Coarse Pass: It stores highly compressed versions of indexer keys on the GPU using Product Quantization (PQ). This reduces the memory footprint of the indexer history by roughly 4x (e.g., from 132 bytes to 32 bytes per entry). The system performs a fast search on these compact codes to identify a set of promising candidates.
- Fine Pass: It fetches the original, full-precision indexer keys from host memory only for these candidates to perform an exact reranking.
To make this efficient, LeanSparse maintains separate, fixed-size GPU caches for both indexer keys and KV entries, exploiting the fact that successive decoding steps often attend to overlapping sets of tokens.
Datasets
The authors evaluated LeanSparse using:
- DeepSeek-V4-Flash: A state-of-the-art native sparse-attention model.
- NVIDIA Open-SWE-Traces: 128 long-context multi-turn sessions used to measure real-world serving performance.
- LongSWE-Bench: Used to construct synthetic contexts ranging from 200K to 950K tokens for stress-testing throughput.
- Accuracy Benchmarks: GSM8K (reasoning), Multi-key Needle-in-a-Haystack (retrieval), LongBench v2 (understanding), and OpenAI MRCR (coreference resolution).
Key Insights and Ideas
- Decoupling Indexing from Attention: The core "aha moment" is treating the indexer keys and the KV cache as separate entities with different lifecycle requirements. By compressing the indexer keys, you can keep the "search map" of a million-token history on-device while offloading the heavy data.
- Hiding Latency via Pipelining: The prefill bottleneck isn't just about total capacity; it's about timing. By streaming layers, LeanSparse allows prefill to start almost immediately, even when the GPU is nearly full of decoding requests.
- Approximation is Sufficient for Filtering: You don't need perfect accuracy when searching the history; you just need a high "recall." As long as the true top tokens are in the candidate set, the second "fine" pass will fix the ranking.
Key Results
LeanSparse was compared against state-of-the-art baselines like HiSparse and ECHO on NVIDIA H100 GPUs:
- Concurrency: At 950K context length, LeanSparse supports 2.95x as many concurrent requests as HiSparse.
- Throughput: It achieves 2.14x higher decode throughput at the same 950K context limit.
- Responsiveness: In multi-turn scenarios, median TTFT dropped by 97.2% (from 21.6s to 0.6s) because requests no longer had to wait for massive memory blocks to clear.
- Accuracy: The system maintains model quality, with scores on benchmarks like GSM8K and NIAH remaining within 0.5% of the unoptimized baseline.
Limitations and Future Work
While LeanSparse significantly pushes the boundaries of long-context serving, some limitations remain:
- Linear Growth: Although the memory per token is reduced, the PQ-compressed indexer keys still grow linearly with context length. Eventually, even these will exhaust GPU memory.
- Coarse Pass Overhead: At shorter context lengths (e.g., 200K), the overhead of the coarse-to-fine screening can slightly increase step time compared to simple exact scoring.
- Future Directions: The authors suggest exploring more aggressive compression or hierarchical indexing structures to scale beyond the 1M token mark.
For more details, you can find the full paper at arXiv:2611.04671v1.
Summary updated