Large Model Attention Architectures: Gated Delta Linear Attention and Sparse Indexing

    This article covers architectural options for long-context large language models. It describes gated delta-rule linear attention, sparse attention with a pooled-block indexer, multi-head latent attention without positional encoding, and manifold-constrained hyper-connections. For each component, it outlines the problem it addresses, its main trade-offs, and the engineering points to check. It also shows how to estimate KV cache size for deployment planning.

    1. Background: Compute and Memory Pressure from Long Contexts

    Standard self-attention cost grows quadratically with sequence length n, giving a complexity of O(n²). During inference, the model must also cache the Key (K) and Value (V) tensors for every layer, the so-called KV cache. Its memory footprint grows linearly with sequence length. At sequences of hundreds of thousands of tokens, adding compute alone cannot sustain stable throughput and latency, so architectural optimization has become the main direction.

    Current industry approaches fall into three groups:

    1. Reduce the complexity of each step: Replace full softmax attention with linear attention or state-space structures.
    2. Reduce the number of tokens involved in computation: Use sparse selection so that each query attends to only a small subset of keys.
    3. Compress the cache: Use low-rank projections or latent representations to shrink the KV cache stored per token.

    The architecture described below covers all three paths. Its modules do not simply stack on top of each other. They are configured with a division of labor: global approximation, local precision, and cache compression.

    2. Gated Delta-Rule Linear Attention

    2.1 Core Idea

    Linear attention rewrites the softmax computation as a running sum of outer products of past keys and values. This turns attention into a recurrent state update. A naive accumulation only writes new information, so old information cannot be effectively overwritten. The delta rule draws on associative memory: before writing a new value, the model erases part of the old value associated with the current key.

    A simplified state update takes the following form:

    1. S_t = S_{t-1} · (I − β_t · k_t k_tᵀ) + β_t · v_t k_tᵀ
    2. o_t = S_t · q_t

    Here, β_t controls the write strength, and k_t, v_t, and q_t are the key, value, and query at the current step.

    2.2 Fine-Grained Gating

    Building on this, a channel-wise decay gate α_t lets different memory dimensions forget at different rates:

    1. S_t = Diag(α_t) · S_{t-1} · (I − β_t · k_t k_tᵀ) + β_t · v_t k_tᵀ

    Compared with a single scalar decay for the whole state, channel-wise gating lets some dimensions retain key information over long spans, while other dimensions refresh local context quickly. The cost is more gating parameters, and the model needs an efficient chunk-wise parallel algorithm to keep training throughput high.

    2.3 Engineering Notes

    • At inference time, the size of the state S_t does not depend on sequence length, so the decoding memory cost stays essentially fixed.
    • Pure linear layers have weaker retrieval ability than full attention, so they are usually interleaved with a small number of full attention layers.
    • During training, use the chunk-wise parallel form. Token-by-token serial computation slows training down.

    3. Sparse Indexing and Pooled Compression

    3.1 Problem Definition

    Full attention layers still handle precise retrieval. If the model can predict which past positions are relevant to the current query, it can compute attention over only those positions. These methods rely on a lightweight indexer that scores the historical keys and then selects the top-k positions.

    The indexer itself must scan all historical keys. If every key takes part in scoring, the indexing cost becomes quadratic again. Compressing the keys solves this.

    3.2 Pooled Compression Indexing (IndexPool Approach)

    Aggregate every B consecutive keys into one index entry. The indexer scores only these block-level entries. The highest-scoring blocks are then expanded back into real keys and values for exact attention. This reduces the indexing scale from n to n/B, and the exact computation processes only the tokens inside the k selected blocks.

    The following pseudocode illustrates the flow. It is written to explain the process and does not correspond to any specific implementation:

    1. def sparse_attention(query, keys, values, block_size, top_k_blocks):
    2. # 1. Pool keys block by block to get index entries
    3. pooled_keys = mean_pool(keys, block_size) # [n / B, d]
    4. # 2. A lightweight indexer scores the block-level entries
    5. scores = indexer_score(query, pooled_keys) # [n / B]
    6. selected = topk(scores, top_k_blocks)
    7. # 3. Compute attention only over the real keys and values in the selected blocks
    8. sel_keys, sel_values = gather_blocks(keys, values, selected, block_size)
    9. return softmax_attention(query, sel_keys, sel_values)

    3.3 Design Trade-offs

    • Block size B: A larger block makes indexing faster, but the information inside each block gets averaged, which weakens fine-grained matching.
    • Top-k count: A larger k improves recall but increases computation.
    • Pooling method: Mean pooling is simple to implement. A learnable compression function is also an option, but it makes training more complex.

    4. Multi-Head Latent Attention Without Positional Encoding (NoPE MLA)

    4.1 Review of Multi-Head Latent Attention

    The core of Multi-Head Latent Attention (MLA) is projecting each token’s keys and values into a low-dimensional latent vector. The cache stores only this latent vector, and the keys and values are up-projected back when needed for computation. The cache size per token is therefore much smaller than in standard multi-head attention.

    4.2 Why Remove Positional Encoding

    Rotary Position Embedding (RoPE) injects position information by rotating the query and key vectors. It conflicts with low-rank caching. Position information must be compressed together with the keys, so implementations usually have to separate the positional part from the rest.

    Removing RoPE from the language backbone (NoPE) has two practical motivations:

    1. It reduces the implementation complexity and cache overhead caused by decoupling.
    2. It lets the architecture supply position information itself, through mechanisms such as the causal mask, recurrent states, and the sequential accumulation in linear layers.

    4.3 Risks and Mitigations

    Without explicit positional encoding, the model’s ability to extrapolate beyond its training length must be verified separately. Common practices include:

    • Keeping global attention in several layers, combined with linear layers that provide implicit positional signals;
    • Gradually extending the context length in the later stages of training, and observing how perplexity changes with length;
    • Running dedicated regression tests on order-dependent tasks, such as long-document retrieval and code localization.

    The conclusions from this kind of design depend on the specific data and tasks. Decide based on your own evaluations, and do not apply other teams’ conclusions directly.

    5. Manifold-Constrained Hyper-Connections (mHC)

    5.1 Motivation for Hyper-Connections

    A traditional residual connection has a single identity path. Hyper-Connections widen the residual stream into several parallel copies and exchange information between layers through learnable mixing matrices. This structure improves expressiveness. However, if the mixing matrices are unconstrained, signals can be repeatedly amplified or attenuated in deep networks, which makes training unstable.

    5.2 Manifold Constraint

    The approach is to restrict the mixing matrices to a mathematical manifold. Take doubly stochastic matrices as an example. Their rows and columns each sum to 1, and their elements are non-negative. This keeps the mixing operation from changing the overall mean scale of the signal. In practice, Sinkhorn iterations are commonly used to project the matrix onto this set:

    1. def project_doubly_stochastic(M, iters=20):
    2. M = exp(M) # ensure non-negativity
    3. for _ in range(iters):
    4. M = M / M.sum(dim=1, keepdim=True) # row normalization
    5. M = M / M.sum(dim=0, keepdim=True) # column normalization
    6. return M

    With this constraint, the residual stream norm stays stable in deep layers, and training becomes less sensitive to the learning rate.

    6. Combining Modules and Engineering Trade-offs

    The division of labor among the modules is summarized below:

    Module Main problem it addresses Main cost
    Gated delta-rule linear attention Reduces computation and state memory on long sequences Weaker retrieval precision than full attention, and requires a chunk-wise parallel implementation
    Pooled indexing with sparse attention Recalls key positions precisely across the full context The compression ratio of the index must be balanced against recall
    Multi-head latent attention without positional encoding Compresses the KV cache and simplifies positional information handling Length extrapolation needs separate verification
    Manifold-constrained hyper-connections Improves deep-layer expressiveness while keeping training stable Each layer requires an additional projection computation

    6.1 KV Cache Estimation

    When you estimate deployment cost, you can roughly size the cache with the following function:

    1. def kv_cache_bytes(num_full_layers, seq_len, latent_dim, bytes_per_elem=2):
    2. # Count only the latent cache of full attention layers; linear layer states are independent of sequence length
    3. return num_full_layers * seq_len * latent_dim * bytes_per_elem

    Because only some layers need a cache that grows with the sequence, the overall memory curve is noticeably flatter than in a full-attention architecture.

    6.2 Engineering Checklist

    • Operator implementation: Chunk-wise parallel linear attention and top-k selection for sparse indexing both need carefully optimized kernels. Without them, the theoretical gains are hard to realize.
    • Hybrid layer ratio: The ratio of full attention layers to linear layers requires repeated tuning to balance accuracy and speed. No universal optimum exists.
    • Evaluation: Beyond standard perplexity, cover long-document retrieval, multi-hop reasoning, and code completion. Linear and sparse components fail in different ways.
    • Monitoring: During training, track the spectral norm of the hyper-connection mixing matrices and the distribution of residual stream norms. These can reveal early signs of instability.

    7. Summary

    The core idea of this architecture is a division of labor. Linear attention provides inexpensive global approximation. Sparse indexing handles precise recall. Latent attention compresses the cache. Manifold-constrained hyper-connections stabilize deep training. Each module has clear costs, and the value of the combination lies in offsetting those costs against each other, rather than maximizing any single metric. Teams evaluating long-context approaches can start with cache estimation and small-scale ablation experiments, then decide whether to adopt the full combination.