Sparse Attention Index Cache Compression: Weighted Pooling Explained

    This article breaks down index cache compression for sparse attention in long-context LLM inference. It explains why the indexer becomes a bottleneck as sequences grow to millions of tokens, how weighted pooling merges four index cache vectors into one to cut memory and bandwidth by 75%, and the resulting gains in VRAM usage, latency, and batching throughput. It also covers practical guidance for measuring bottlenecks, validating recall quality, coordinating with KV cache strategies, and elastic deployment.

    1. Background: The Indexer Bottleneck in Long-Context Inference

    As context length grows from a few thousand tokens to the million-token range, the cost of attention computation scales quadratically, making full attention impractical in production. The common industry approach is a hybrid architecture that combines linear attention with sparse attention: linear attention captures local dependencies cheaply through recurrence (state compression), while sparse attention uses a lightweight indexer to retrieve a small set of genuinely relevant segments from the global token pool and then applies exact attention to them.

    This architecture reduces the bulk of the compute from “full” to “a small subset,” but it introduces a new hidden cost: the indexer itself has to maintain a cache. Because the indexer scores, ranks, and retrieves over all historical tokens, it must keep a set of index state vectors for the entire sequence. The longer the sequence, the larger this cache grows, the more read bandwidth it demands, and the more noticeable the latency of the indexing stage becomes. In other words, sparsification lowers the attention compute but shifts the pressure onto index cache access.

    When a cloud vendor open-sourced a multimodal model with roughly 320B total parameters, it introduced an index cache compression mechanism (commonly referred to in the industry as an IndexPool-style technique) specifically to further reduce indexer latency and memory overhead at million-token context lengths. The approach merges the indexer’s four cache vectors into one via weighted pooling, shrinking the cache to one quarter of its original size.

    2. Core Idea: Weighted Pooling That Folds Four into One

    The essence of the technique is weighted downsampling. The naive approach is to drop three vectors and keep only one, but that loses information; a simple average, on the other hand, flattens the importance differences across slots. Weighted pooling is the middle ground:

    • It preserves the semantic contribution of all four slots while fusing them with a set of weights that are either learned or determined by a fixed rule.
    • The fused single vector approximates a sufficient statistic of the original four vectors in terms of information content, cutting storage and bandwidth to one quarter while keeping retrieval quality nearly unchanged.

    Illustrative pseudocode (conceptual only, not a specific product API):

    1. # Original index cache: [B, L, 4, D] -> compressed: [B, L, 1, D]
    2. def index_pool(cache, weights):
    3. # weights: [4] normalized weights, either learned during training or given by a decay rule
    4. w = weights / weights.sum()
    5. return (cache * w.view(1, 1, 4, 1)).sum(dim=2)

    The key questions are where the weights come from and whether they stay stable. If the weights are updated dynamically during training, inference must remain consistent with training. If a fixed decay is used (for example, giving more weight to more recent slots), its behavior under long-sequence extrapolation needs to be validated.

    3. Three Dimensions of Engineering Gains

    1. VRAM usage: The index cache is a resident overhead that grows linearly with sequence length. Compressing it to one quarter directly raises the ceiling on supported context length, or frees up more VRAM for the KV cache and activations at the same length.
    2. Memory bandwidth and latency: The indexing stage is memory-bound rather than compute-bound, so cutting reads by three quarters typically yields a close-to-linear latency reduction. This matters especially for time to first token (TTFT).
    3. Batching throughput: A smaller cache means larger batches or longer sequence combinations fit on the same GPU, making it easier for the scheduler to saturate VRAM and raising overall throughput.

    4. Practical Recommendations

    • Quantify the bottleneck first: Use monitoring alerts and log services to confirm how much of total latency the indexing stage accounts for, so you do not optimize in the wrong direction.
    • Validate quality in layers: Align with the baseline on short contexts, then extend progressively to the million-token range, watching for drift in retrieval hit rate and downstream task metrics.
    • Coordinate with KV cache strategy: Index cache compression needs to work alongside KV optimizations such as paged management and quantization, so that a local gain is not canceled out by an overall bottleneck.
    • Deploy elastically: Long-context inference is sensitive to VRAM, so consider combining container platform autoscaling with object storage to externalize session state, and schedule “long sessions” and “high-concurrency short requests” in separate pools.

    5. Summary

    Folding four index cache slots into one through weighted pooling is a typical example of trading a minimal amount of information for several times the resource savings. It is a reminder to developers that in long-context systems the real bottleneck is often not the most visible attention matrix, but the auxiliary caches that swell linearly with sequence length. Baidu AI Cloud, in engineering similar technical solutions, likewise emphasizes a methodology of locating the bottleneck first, validating in layers, and then coordinating with overall resource scheduling.