Cross-Layer Index Reuse in Long-Context Sparse Attention: An Architecture Breakdown

    Long-context sparse attention shifts inference cost from attention aggregation to index selection. This article analyzes a cross-layer index reuse architecture in which a full top-k indexer runs only once every four layers while intermediate layers reuse the shared token indices. It covers the problem background, the mechanism, why index reuse works, engineering considerations such as caching, alignment, and causal masking, a cost model, and the applicability boundaries of the approach.

    Cross-Layer Index Reuse in Long-Context Sparse Attention: An Architecture Breakdown

    1. Background: Where the Cost of Long-Context Inference Is Shifting

    As long-context capability scales from tens of thousands of tokens to the million-token level, the compute and memory pressure of attention is no longer a single-dimension problem. With full attention, the attention matrix grows quadratically with sequence length, rapidly inflating both memory footprint and compute cost. To address this, common solutions introduce sparse attention: instead of letting every query token interact with the full context, an indexer first selects a small set of highly relevant tokens, and attention aggregation is performed only on the selected set.

    The core pipeline of such solutions typically involves two steps:

    1. Index selection: compute relevance scores between query representations and context representations, then select the top-k candidate token indices;
    2. Sparse aggregation: run attention only over the selected tokens, reducing effective compute.

    In short-context scenarios, the indexer’s overhead may not be significant. At the million-token scale, however, the indexer itself must scan a large candidate pool, maintain scores, and perform top-k selection. If every layer repeats the full indexing computation, this becomes a new cost bottleneck—especially in deep models, where layer-by-layer independent indexing means a large amount of redundant index construction.

    As a result, the optimization focus for long-context sparse attention is shifting from “how to sparsify” to “how to obtain sparse indices at low cost.”

    2. The Existing Foundation: Combining Multi-Head Latent Attention with Sparse Attention

    Public architecture discussions show that some long-context models combine multi-head latent attention (MLA) with sparse attention. MLA focuses on reducing the parameter count and compute of the attention block through latent representation compression and projection structures; sparse attention focuses on narrowing the context range each query actually aggregates over. Combined, they can preserve long-context modeling capability while keeping per-layer attention compute under control.

    But the combination still leaves an open question: where do the sparse indices come from, and can index computation be reused across layers?

    If every layer runs a full top-k indexer, the overall indexing cost grows roughly linearly with depth. With L layers and a per-layer indexer cost of C_index, layer-wise indexing costs about L × C_index. At million-token contexts, C_index is no longer negligible, and the indexer can become a major source of long-context inference overhead.

    Cross-layer index reuse targets exactly this bottleneck: since adjacent layers exhibit continuity in representation space, could some layers share already-selected token indices instead of recomputing them?

    3. The Cross-Layer Reuse Mechanism: Run the Full Indexer Once Every Four Layers

    The optimization discussed here is cross-layer index reuse: instead of recomputing the sparse attention top-k indexer at every layer, run a full indexer once every four layers and let the subsequent layers reuse the selected token indices.

    It can be summarized as a “layered scheduling + index caching” strategy:

    • Full-index layers: every few layers, run a full top-k indexer that generates candidate token indices for the current context window;
    • Reuse layers: the following layers skip the full indexer and read the most recently generated shared indices;
    • Sparse aggregation still runs per layer: reusing indices does not mean reusing attention outputs. Each layer still performs attention aggregation and subsequent transformations over the selected tokens using its own representations.

    The key to this design is separating “index selection” from “attention aggregation.” Index selection is the entry point of sparse attention—it decides which tokens to look at. Attention aggregation depends on each layer’s own query, key, and value representations. Cross-layer reuse only shares the index set; it never skips intra-layer attention computation. The basic idea of sparse attention is preserved, while the number of full indexer runs is dramatically reduced.

    With a full indexer once every four layers, full index computation drops from roughly L times to about L/4 times. Reuse layers still incur the cost of reading indices, aligning them, and performing sparse aggregation, but this is typically lower than a full indexer scan plus top-k selection. For million-token inference, this reduction is directly meaningful.

    4. Why Reuse Works: Index Stability and Cross-Layer Continuity

    Whether cross-layer index reuse holds up depends on whether indices are stable enough across adjacent layers. There are three ways to understand this:

    First, highly relevant tokens in a long context are usually determined jointly by the query topic, positional structure, and semantic segments. Although adjacent layers have different representations, when facing the same context, the core relevant regions usually do not change drastically. Reusing indices selected by a recent layer is therefore likely to still cover the main information.

    Second, sparse attention is itself an approximate mechanism. It does not require a globally optimal index set at every layer—only a sufficiently relevant candidate set at an acceptable cost. Cross-layer reuse is essentially a trade-off between index precision and index computation cost.

    Third, running a full indexer every four layers provides periodic refresh. Reuse layers do not use one index set permanently; they share it over a limited number of layers before recomputation. This is more robust than sharing one index set across the entire model, and more economical than recomputing at every layer.

    The mechanism is therefore not a naive omission of the indexer—it controls index drift risk through periodic refresh.

    5. Engineering Considerations: Caching, Alignment, and Boundary Handling

    In practice, cross-layer index reuse requires attention to the following points.

    5.1 Index Cache Lifecycle

    The shared index cache needs a clearly defined scope: it is generated by a full-index layer, read by subsequent layers, and refreshed at the next full-index layer. The cache typically stores the top-k indices, valid lengths, batch mappings, and related metadata. For variable-length batches, padding and sequence boundaries must be handled to avoid reusing out-of-bounds indices.

    5.2 Cross-Layer Index Alignment

    Different layers may have different head counts, head dimensions, or projection structures. When reusing indices, alignment must be ensured along the token dimension—representations are not shared along the hidden dimension. Indices are the result of token-position selection; each layer still uses its own key/value representations for aggregation.

    5.3 Causal Masks and Positional Constraints

    In autoregressive decoding, index selection must respect the causal constraint—future tokens must never be selected. When reusing indices, visibility must still be checked against the current layer and current query position, with mask filtering applied to the shared indices when necessary. For chunked or streaming inference, index invalidation caused by sliding cache windows must also be handled.

    5.4 Fallback and Monitoring

    Monitoring metrics can include index hit rate, overlap between shared and freshly recomputed indices, and the effective token count of sparse aggregation. When the context distribution shifts sharply or sequences within a batch differ widely, falling back to layer-wise indexing or shortening the reuse interval can help avoid quality degradation.

    Illustrative pseudocode:

    1. def sparse_attention_layer(layer_id, hidden, context, shared_index_cache):
    2. if layer_id % 4 == 0:
    3. # Full-index layer: recompute top-k token indices
    4. index = topk_indexer(hidden, context, k=K)
    5. shared_index_cache["index"] = index
    6. else:
    7. # Reuse layer: read indices from the most recent full-index layer
    8. index = shared_index_cache["index"]
    9. # Causal mask and boundary filtering still apply per layer
    10. index = apply_causal_and_boundary_mask(index, layer_id)
    11. # Sparse aggregation still uses this layer's own representations
    12. output = sparse_aggregate(hidden, context, index)
    13. return output

    This example only expresses the scheduling logic and does not involve specific interfaces or parameter settings. A real implementation must also account for tensor parallelism, batch layouts, and memory management.

    6. Cost Model and Applicability Boundaries

    In an abstract cost model, layer-wise full indexing costs about L × C_index; with a refresh every four layers, full indexing costs about ceil(L/4) × C_index, plus an index-reading and mask-filtering cost C_reuse on the reuse layers. As long as C_reuse is clearly smaller than C_index, overall indexing overhead drops.

    But the mechanism has boundaries:

    • The larger the reuse interval, the higher the index drift risk. Once every four layers is a cost-quality compromise, not a “bigger is better” setting;
    • Batches with highly diverse context distributions may need more frequent index refreshes;
    • Memory-access locality at extreme context lengths still matters—shared indices reduce indexer compute, but sparse aggregation still requires efficient gather/scatter;
    • Training–inference consistency deserves attention. If training uses layer-wise indexing while inference uses cross-layer reuse, the distribution gap may need to be mitigated through training strategies or calibration.

    7. Summary

    The core value of cross-layer index reuse lies in pushing long-context sparse attention optimization one step further—from “reducing the attention aggregation range” to “reducing redundant index construction.” It preserves the basic sparse attention pipeline: select indices first, then aggregate sparsely. But by running the full indexer only once every four layers and letting subsequent layers reuse the selected token indices, it cuts the cost of repeated top-k index computation in million-token inference.

    From an architecture design perspective, this is a typical form of hierarchical cost scheduling: periodic refresh keeps indices effective, cross-layer sharing removes redundant computation, and per-layer aggregation preserves model expressiveness. For long-context inference systems, the engineering significance is turning the indexer from a heavy module that “must run at every layer” into a schedulable module built on “periodic computation + cache reuse,” providing a more controllable cost structure for million-token scenarios.