Sparse Attention and Cross-Layer Index Reuse: Reducing Long-Context LLM Inference Costs

    Long-context inference requires more than a smaller KV cache or sparse attention alone. This article explains how Multi-head Latent Attention (MLA), sparse attention (DSA), and the IndexShare mechanism work together to control memory and computation costs. It examines how reusing token indices across layers reduces indexing overhead, outlines the quality–efficiency trade-off, and provides illustrative pseudocode for the approach.

    1. Why Long-Context Inference Is Expensive

    As large language models move toward context windows of one million tokens, inference costs become increasingly difficult to manage. In a standard Transformer, full attention over a sequence has quadratic computational complexity with respect to sequence length.

    Expanding a context window from tens of thousands of tokens to a million creates two distinct pressures. The KV cache grows linearly with sequence length, increasing GPU memory requirements, while full-attention computation becomes substantially more expensive. Together, these factors can push latency and operating costs beyond what enterprise applications can reasonably support.

    The architectural goal is therefore clear: reduce attention-related computation and memory consumption while preserving model quality as much as possible. Two established approaches address different parts of the problem:

    • KV compression, including low-bit storage and low-rank latent-attention designs, reduces cache memory requirements.
    • Sparse attention limits attention computation to a selected subset of relevant tokens.

    Combining these approaches addresses both memory capacity and computational cost.

    2. The Foundation: Combining MLA and DSA

    The publicly presented architecture diagram describes a model that retains the overall design of its two preceding generations. Its attention subsystem combines two key components: Multi-head Latent Attention (MLA) and sparse attention (DSA).

    Multi-head Latent Attention (MLA)

    MLA uses joint low-rank compression of keys and values. Rather than caching complete key and value representations for every attention head, the model stores a compressed latent vector. Up-projection matrices provide the corresponding per-head key and value representations during inference.

    This design substantially reduces the size of the KV cache. Under the same GPU memory budget, the model can accommodate longer contexts. It also helps alleviate memory-bandwidth pressure during decoding.

    Sparse Attention (DSA)

    DSA adds an indexer to the MLA-based attention system. For each query token, the indexer selects the top-k most relevant tokens from the available context. The subsequent attention operation runs only over those selected positions.

    Because k is typically much smaller than the full sequence length, the attention computation for an individual query depends on k rather than on every token in the context. This makes the attention stage more manageable for very long sequences.

    However, selecting those tokens is not free. The indexer introduces its own computational overhead, which becomes important as both context length and model depth increase.

    3. IndexShare: Reusing Token Indices Across Layers

    The most notable addition in the described architecture is IndexShare, a mechanism that targets the cost of the indexer itself.

    The Problem: Repeated Indexing

    Consider a model with roughly a hundred attention layers. If each layer independently scores all historical tokens and selects its own top-k set, the indexing cost accumulates across layers.

    At a context length of one million tokens, this overhead can become substantial. Sparse attention reduces the cost of the main attention operation, but repeatedly deciding where to attend can consume a meaningful share of the savings.

    The Solution: Share Indices Across Layer Groups

    IndexShare reuses the selected token indices across multiple layers. In the architecture diagram, the model runs a full indexing operation once every four layers. The following layers reuse that selection instead of repeating the scoring and top-k process.

    The rationale is that adjacent layers often exhibit similar attention patterns. Tokens considered important at layer n are likely to remain relevant at layers n+1 and n+2.

    If this similarity holds sufficiently well, one indexing operation can support several attention layers with limited disruption to model quality. With a four-layer sharing interval, the number of indexer calls falls to approximately one-quarter of the original count.

    Importantly, IndexShare reuses the token selection, not the attention output. Each layer still performs its own sparse attention computation over the shared positions.

    4. Estimating the Cost Savings

    A simplified calculation illustrates the potential benefit. Assume:

    • The model has L attention layers.
    • Running the indexer once costs C.
    • One set of indices is reused across N layers.

    Without sharing, total indexing overhead is:

    1. L × C

    With cross-layer reuse, the approximate overhead becomes:

    1. (L / N) × C

    For N = 4, this corresponds to an approximately 75% reduction in indexing overhead.

    This figure applies to the indexing component, not to total inference cost. Overall savings also depend on the costs of sparse attention and the rest of the model.

    For an individual query, DSA reduces the attention operation from considering n context positions to considering k selected positions: from O(n) to O(k) for that stage. IndexShare then reduces how often the selection process must run across layers. Together, these mechanisms provide the architectural rationale behind the reported reduction in inference costs for one-million-token contexts.

    The Quality–Efficiency Trade-Off

    Sharing indices also reduces the granularity of token selection. A layer may have to use a token set selected by an earlier layer rather than the set it would choose independently.

    The resulting trade-off is straightforward: lower indexing overhead in exchange for less layer-specific selection. Based on the public description, the design favors an engineering balance between model quality and practical inference cost.

    The simplified calculation does not establish the size of any quality change. That depends on how well the shared selection serves the layers that reuse it.

    5. Illustrative Pseudocode

    The following pseudocode shows where IndexShare fits into the inference flow:

    1. def forward_layers(hidden_states):
    2. shared_indices = None
    3. for i, layer in enumerate(layers):
    4. if i % 4 == 0:
    5. # Run the full indexer every four layers to select top-k token indices
    6. shared_indices = indexer_topk(hidden_states, k=K)
    7. # Reuse the indices and apply sparse attention only to selected tokens
    8. hidden_states = layer.sparse_attention(hidden_states, shared_indices)
    9. return hidden_states

    This example captures the central idea: compute a token selection at the start of each four-layer group, then reuse it throughout that group.

    A production implementation must also handle details such as the GPU memory layout of cached indices and the isolation of index selections between different requests in a batch. These considerations do not change the core reuse mechanism, but they matter for an efficient and correct implementation.

    6. What Developers Can Learn

    1. Optimize the Overhead of the Optimization

    Sparse attention is not the end of the optimization process. Its selection mechanism also consumes resources.

    IndexShare highlights a broader systems principle: an optimization should be evaluated together with the overhead it introduces. Reducing the main computation is valuable, but the supporting machinery must remain efficient as well.

    2. Cross-Layer Redundancy Is an Optimization Opportunity

    Adjacent layers in deep networks can exhibit correlated behavior. Index reuse, KV reuse, and the reuse of intermediate states in speculative decoding all point toward the value of examining redundant work.

    For IndexShare, the practical opportunity is specific: avoid recomputing token selections when nearby layers can use the same indices effectively.

    3. Lower Long-Context Costs Can Expand Application Feasibility

    More affordable million-token inference could lower the deployment barrier for applications such as:

    • Repository-wide code analysis
    • Review of very long contracts
    • Question answering across multiple documents

    The business value still depends on the workload, but reducing the cost of processing long contexts makes these applications easier to evaluate and deploy.

    Conclusion

    The architecture follows a three-part approach to long-context efficiency:

    1. MLA compresses the KV cache, reducing memory requirements.
    2. DSA makes attention sparse, limiting computation to selected tokens.
    3. IndexShare amortizes indexing overhead across layers, avoiding repeated token selection.

    Together, these mechanisms form a coordinated cost-control strategy for million-token inference. The central lesson for model developers and inference-platform teams is that cross-layer similarity can be used to reduce redundant work—not only in attention itself, but also in the mechanisms that make attention efficient.