Weighted Pooling Compression for Sparse Attention Indexer Caches
This article examines the cache overhead of sparse attention indexers in ultra-long-context inference and presents weighted pooling as a practical compression approach. It explains why multi-route indexer caches improve recall but increase memory use and bandwidth pressure, describes how indexer caches fit into hybrid linear-attention and sparse-attention architectures, and details the weighted pooling principle, implementation pseudocode, error evaluation, and deployment trade-offs. Readers will learn how to compress four cache routes into one aggregated vector, what to monitor during evaluation, and how to roll out the method with controlled recall risk.
Weighted Pooling Compression for Sparse Attention Indexer Caches
1. Background: Indexer Cache Overhead in Ultra-Long Contexts
When context length expands from tens of thousands of tokens to millions, the quadratic compute of standard full attention and the linearly growing key-value cache both increase latency and memory usage. Sparse attention mitigates this problem through a “recall first, compute later” approach: a lightweight indexer rapidly scores the relevance of the global context, and only a subset of tokens with higher scores participates in subsequent attention computation. This keeps the main attention workload within an acceptable range, but the indexer itself still needs to maintain a reusable cache representation.
In engineering implementations, the indexer usually does not store only one key-side representation. Instead, it stores multiple cache vectors for evaluating relevance from different projection directions, statistical dimensions, or confidence perspectives. Multi-route caching can improve recall quality, but it introduces two costs. First, cache capacity grows linearly with context length, and at million-token scale the memory footprint cannot be ignored. Second, each scoring operation must read multiple cache routes, making memory bandwidth and access latency new bottlenecks. In large-scale inference services in particular, indexer caches are read very frequently, and their bandwidth cost may even exceed the compute savings from sparse attention.
Therefore, the goal of compressing indexer caches is not simply to “delete data.” The goal is to reduce cache routes and read volume while preserving the relevance-scoring signal as much as possible. Weighted pooling is a direct approach: aggregate multiple cache vectors at the same token position into a single vector according to weights, compressing the cache scale to one quarter of the original while retaining the main scoring information.
2. Locating the Indexer Cache in Hybrid Attention Architectures
In hybrid architectures that combine linear attention and sparse attention, the two branches serve different roles. Linear attention captures local dependencies and sequential information through recursive states. Its state update has fixed overhead and is suitable for continuous context. Sparse attention relies on a lightweight indexer to recall key tokens from the global context, compensating for the limitations of recursive states in precise long-distance recall.
The indexer cache serves the sparse branch, not the main attention output path. It is usually built during the prefill phase and is repeatedly read by query vectors during decoding for scoring. Its core purpose is to avoid re-executing key-side projections for every scoring operation, thereby reducing the cost of “global recall” to one cache build plus multiple lightweight queries. For this reason, the layout, number of routes, and precision of the indexer cache directly affect the end-to-end performance of sparse attention.
The motivation for multi-route caching is that a single vector may not simultaneously express semantic similarity, positional proximity, modality differences, and statistical salience. For example, in multimodal scenarios, text tokens and visual tokens have quite different distributions. In long documents, tokens at different levels may require summary representations at different granularities. Storing four cache routes provides richer signals to the scorer, but reading four vectors also means four times the cache bandwidth. Weighted pooling compresses four routes into one. In essence, it moves “multi-view scoring” forward into “single-view scoring after multi-view fusion,” trading a small amount of expressiveness for significant cache savings.
3. Core Principle of Weighted Pooling Compression
The basic form of weighted pooling is as follows: assign weights (w_1, w_2, w_3, w_4) to multiple cache vectors (c_1, c_2, c_3, c_4) at the same position, and aggregate them into a single vector:
[
c’ = \sum_{i=1}^{4} \alpha_i c_i,\quad \alpha_i = \frac{w_i}{\sum_j w_j}
]
The weights can be static learnable parameters, or they can be generated dynamically based on the norm, entropy, confidence, or block statistics of the cache vectors. After aggregation, scale normalization is usually required to prevent a shift in vector norm after pooling from causing drift in the scoring distribution. The compressed cache retains only one route, reducing capacity and read bandwidth to one quarter of the original.
The effectiveness of this approach depends on two preconditions. First, there is high information redundancy among the multiple cache routes, and the main relevance signal can be preserved through linear combination. Second, the weights can distinguish the importance of different cache routes, avoiding simple averaging that mixes weak and strong signals with equal weight. If the multiple cache routes differ greatly from one another, pooling introduces approximation error, so recall evaluation and a necessary fallback mechanism are required.
Compared with quantization and low-rank projection, weighted pooling does not change the dimension of a single vector. Instead, it reduces the number of routes, making the hardware access pattern simpler: instead of reading four contiguous cache segments, it reads only one. It can also be used orthogonally with quantization, but attention must be paid to error accumulation. Pooling before quantization usually makes numerical ranges easier to control than quantizing before pooling.
4. Implementation Path and Pseudocode
For implementation, it is recommended to organize the cache in blocks, with each block containing multiple route vectors. Pooling is completed during the build phase, and only the compressed cache is read during the query phase. The following pseudocode is framework-agnostic.
def weighted_pool(cache_block, weights, eps=1e-6):# cache_block: [num_routes, dim]# weights: [num_routes]w = weights / (weights.sum() + eps)return sum(w[i] * cache_block[i] for i in range(len(w)))def build_compressed_index(cache_blocks, weight_fn):compressed = []for block in cache_blocks:w = weight_fn(block) # static or dynamic weightsvec = weighted_pool(block, w)vec = normalize(vec) # scale normalization for stable score distributioncompressed.append(vec)return stack(compressed)def sparse_recall(query, compressed_cache, top_k):scores = matmul(query, transpose(compressed_cache))indices = topk(scores, top_k)return gather(compressed_cache, indices)
In engineering implementations, weight generation should be as lightweight as possible. Static weights can be learned during training and fixed afterward. Dynamic weights can be computed based on norms or variance within a block, but the additional compute must be controlled. The cache layout should ensure that compressed results for the same block are stored contiguously, which facilitates paged loading and coalesced access. For million-token contexts, it is advisable to build the compressed cache block by block during the prefill phase, avoiding materialization of all multi-route caches at once and the resulting peak memory spike.
5. Error Evaluation and Design Trade-offs
The main risk introduced by compression is a decline in recall quality. The pooled single-route vector may lose some fine-grained discriminative signals, causing top-k recall to miss key tokens. Evaluation should not rely only on end-to-end perplexity. It should also examine recall@k, long-distance retrieval accuracy, long-document question answering, and cross-modal alignment tasks. In production, the consistency between score rankings from the compressed cache and the original multi-route cache can be monitored as a proxy metric for recall quality.
Design trade-offs center on three points: compression ratio, weight expressiveness, and access efficiency. A 4:1 compression ratio delivers clear benefits in most scenarios. Further increasing the compression ratio requires finer-grained grouped pooling or stronger weight modeling, and error will also rise. Dynamic weights are more expressive but increase build overhead. Static weights are lighter and better suited to high-throughput services. Grouped pooling can be chosen between “grouping by head” and “grouping by modality” to adapt to different token distributions.
6. Deployment Recommendations
For deployment, offline validation should come first, followed by a canary rollout. In the offline phase, compare recall and long-context task metrics before and after compression to determine the weighting strategy and normalization method. In the online phase, monitor indexer cache read bandwidth, peak memory, P99 latency, and recall proxy metrics. For multimodal inputs, calibrate weights by modality or layer to prevent a single weight from failing across distributions. A low-frequency fallback path can be retained: when scoring confidence is low, fall back to the uncompressed cache or recompute the key blocks. Through block-wise compression, asynchronous construction, and contiguous layout, weighted pooling can bring the latency and memory overhead of indexer caches under million-token contexts into a more controllable range without changing the main attention path.
