Full text not available for this paper

Summary (Overview)

  • MERLIN (Moment Routing for multi-state LINear attention) is proposed as a novel aggregation method for Multi-State Linear Attention (MSLA) mechanisms, leveraging both the first and second moments of segment keys to compute aggregation weights.
  • The method addresses a key limitation of existing MSLA aggregation approaches: they only use mean alignment (first-order) or position-based weights, ignoring the variance of the alignment distribution within segments.
  • MERLIN stores compact first moments (μi\mu_i) and second moments (Σi\Sigma_i) of each segment's keys, allowing a query to recover both the mean and variance of its alignment with each segment.
  • Experiments on multi-state variants of Gated DeltaNet-1.3B and Mamba-2-780M show consistent improvements: +8.3% (GDN) and +7.0% (Mamba-2) on RULER, and +13.5% and +12.0% on LongBench over the strongest baseline.
  • MERLIN outperforms baselines that consume 4× more memory, demonstrating both performance and memory efficiency gains.

Introduction and Theoretical Foundation

Background and Motivation

Standard self-attention (Vaswani et al., 2017) is the core operation in long-sequence modeling but suffers from quadratic computational complexity and a linearly growing KV cache. Linear attention mechanisms (Katharopoulos et al., 2020; Sun et al., 2023; Peng et al., 2023) address these limitations by reformulating attention to operate in sub-quadratic complexity, replacing the KV cache with a single fixed-size memory state.

However, single-state linear attention models (e.g., DeltaNet, Gated DeltaNet) are inherently limited in memory capacity, leading to information loss when compressing longer contexts. This motivates Multi-State Linear Attention (MSLA) mechanisms, which partition the context into segments and compress each segment into its own memory state.

Two Novel Challenges in MSLA

  1. Separation: How to divide the context into segments
  2. Aggregation: How to combine segment-level outputs

The paper focuses on aggregation, which is relatively underexplored. Existing methods aggregate segment-level outputs via weighted sums where weights represent segment relevance to the query, but they derive weights from either:

  • Position (Guo et al., 2026; Wang et al., 2026): assuming recency as the source of relevance
  • Mean alignment (Behrouz et al., 2026): first-order alignment between query and segment keys

Key Theoretical Insight

The paper demonstrates that variance matters for aggregation. Figure 1b shows that on retrieval-augmented generation tasks, the segment containing the ground truth receives the highest aggregation weight when weights are derived from both mean and variance of the alignment, compared to mean or position alone.

The theoretical foundation connects to softmax attention: when grouping token-level softmax attention mass by segment, the log-evidence expands in cumulants as:

log⁡Zt,i(δ)=δηt,i+δ22σt,i2+O(δ3)\log Z_{t,i}(\delta) = \delta \eta_{t,i} + \frac{\delta^2}{2}\sigma^2_{t,i} + O(\delta^3)

where ηt,i\eta_{t,i} is the mean alignment and σt,i2\sigma^2_{t,i} is the variance—precisely the scores MERLIN computes.


Methodology

3.1 First and Second Moments of Keys

For each token, MERLIN projects new keys and queries kt′,qt′∈Rdrk'_t, q'_t \in \mathbb{R}^{d_r} from hidden states (with dr<dd_r < d to keep moments compact). The moments for segment CiC_i are:

μi=1∣Ci∣∑j∈Cikj′,Σi=1∣Ci∣∑j∈Cikj′kj′⊤\mu_i = \frac{1}{|C_i|} \sum_{j \in C_i} k'_j, \quad \Sigma_i = \frac{1}{|C_i|} \sum_{j \in C_i} k'_j k'^{\top}_j
  • μi\mu_i captures the average direction of keys in segment ii
  • Σi\Sigma_i captures how keys are spread within the segment

3.2 Aggregation Weight Derivation

For a token at position tt and each visible segment CiC_i, MERLIN computes:

rt,iμ=μi⊤qt′,rt,iΣ=qt′⊤Σiqt′−(rt,iμ)2r^{\mu}_{t,i} = \mu^{\top}_i q'_t, \quad r^{\Sigma}_{t,i} = q'^{\top}_t \Sigma_i q'_t - (r^{\mu}_{t,i})^2

where:

  • rt,iμr^{\mu}_{t,i}: mean key-query alignment (first-order)
  • rt,iΣr^{\Sigma}_{t,i}: variance of the alignment (second-order)

The final aggregation weight is computed via a gated mixture of softmax-normalized scores:

λt,i=γtsoftmaxi(τμrt,iμ)+(1−γt)softmaxi(τΣrt,iΣ)\lambda_{t,i} = \gamma_t \text{softmax}_i(\tau_\mu r^{\mu}_{t,i}) + (1 - \gamma_t)\text{softmax}_i(\tau_\Sigma r^{\Sigma}_{t,i})

where:

  • γt\gamma_t: scalar gate computed from hidden state xtx_t via learned projection
  • τμ,τΣ\tau_\mu, \tau_\Sigma: learnable temperatures calibrating the sharpness of each term

3.3 Connection to Softmax Attention

The paper shows that MERLIN's scores correspond exactly to the first two cumulants of the segment-level attention mass in softmax attention:

ηt,i=μi⊤qt′=rt,iμ,σt,i2=qt′⊤Σiqt′−(μi⊤qt′)2=rt,iΣ\eta_{t,i} = \mu^{\top}_i q'_t = r^{\mu}_{t,i}, \quad \sigma^2_{t,i} = q'^{\top}_t \Sigma_i q'_t - \left(\mu^{\top}_i q'_t\right)^2 = r^{\Sigma}_{t,i}

Rather than using fixed additive coefficients from the cumulant expansion, MERLIN uses a learned gated mixture with independently normalized softmax terms, providing more flexibility.

Complexity Comparison

MechanismCompute (Prefill)Memory
Full AttentionO(T2d)O(T^2 d)O(Td)O(Td)
Linear AttentionO(Td2)O(Td^2)O(d2)O(d^2)
Log-Linear AttentionO(Td2log⁡T)O(Td^2 \log T)O(d2log⁡T)O(d^2 \log T)
Memory CachingO(TLd2)O(TLd^2)O(Ld2)O(Ld^2)
MERLIN (ours)O(TL(d2+dr2))O(TL(d^2 + d_r^2))O(L(d2+dr2))O(L(d^2 + d_r^2))

Empirical Validation / Results

Setup

  • Models: Gated DeltaNet-1.3B (pre-trained on 50B tokens from FineWeb-edu) and Mamba-2-780M (official checkpoint pre-trained on 300B tokens from Pile)
  • Mid-training: Two-stage process to convert single-state models to multi-state variants
    • Stage 1: 2B tokens from Long-Data-Collections (LDC), 10% augmented with RULER NIAH-like tasks
    • Stage 2: 60M tokens with 50% LDC and 50% synthetic RULER HotpotQA/SQuADQA samples
  • Segmentation: Uniform, 256 tokens per segment
  • Baselines: Vanilla (single-state), Position (Eq. 5), Meanpool (Eq. 6)

RULER Results (16K context)

ModelMethodS-NIAH-1S-NIAH-2S-NIAH-3MK-NIAH-1MQ-NIAHMV-NIAHHotpotQASQuADQAAvg
GDN-1.3BVanilla89.099.210.823.480.870.215.08.349.6
Position97.296.816.042.282.578.416.07.354.6
Meanpool99.699.421.248.486.685.012.010.757.9
MERLIN99.2100.047.045.091.088.817.013.762.7
Mamba-2-780MVanilla1001008.424.692.286.4164.754.0
Position100.0100.054.291.094.589.220.08.069.6
Meanpool100.0100.066.289.493.791.820.08.171.2
MERLIN99.899.896.094.895.992.222.09.476.2

LongBench Results (16K filtered)

ModelMethodNQQRMFHP2WGRQMMNSSTCTQAvg
GDN-1.3BVanilla6.06.112.26.88.59.916.59.440.542.521.416.3
Position11.59.614.914.311.16.114.012.339.048.523.118.6
Meanpool8.815.218.014.69.88.715.310.134.554.822.419.3
MERLIN13.919.420.316.314.47.815.912.840.060.420.121.9
Mamba-2-780MVanilla1.03.27.64.25.210.212.314.736.554.55.714.1
Position1.25.110.55.76.815.515.017.442.065.112.517.9
Meanpool1.74.211.56.05.616.017.718.544.561.115.118.4
MERLIN1.96.712.67.89.120.416.119.246.072.714.220.6

Positional Bias Analysis (HELMET TriviaQA)

  • Vanilla: Strong recency bias—struggles unless gold passage is near the end
  • Position: Weak recency bias with gradually increasing accuracy toward the end
  • Meanpool: Flatter but weaker overall
  • MERLIN: Stays high and roughly uniform across all gold passage positions

Segment Length Analysis

MERLIN outperforms baselines across segment lengths m∈{64,128,256,512}m \in \{64, 128, 256, 512\}. Notably, MERLIN at m=256m=256 outperforms Meanpool and Position at m=64m=64, which consume 4× more memory.

Ablations

Dimension of Moments (drd_r):

  • Performance increases with dr∈{16,32,64,128}d_r \in \{16, 32, 64, 128\}, saturating around dr=32d_r=32 (GDN) and dr=64d_r=64 (Mamba-2)
  • Trade-off: larger drd_r improves expressiveness but increases memory

Parameter Sharing Ablations:

VariantSingleMultiSummFew-shotOverall
GDN + MERLIN17.915.412.240.221.9
+ write-forget14.99.211.635.318.5
+ shared-KQ10.79.210.929.815.7
Mamba + MERLIN7.18.518.644.320.6
+ write-forget6.76.916.643.819.6
+ shared-KQ5.16.115.138.317.1

Both ablations (sharing keys/queries between memory state and moments, and using write-forget gates) substantially degrade performance, confirming that dedicated keys and queries for moments are crucial.


Theoretical and Practical Implications

Theoretical Contributions

  1. Identifies aggregation as a key bottleneck in multi-state linear attention, which was relatively underexplored compared to separation.
  2. Establishes a theoretical connection between MSLA aggregation and softmax attention via cumulant expansion, showing that mean and variance of key-query alignment are the first two cumulants of the segment-level attention mass.
  3. Demonstrates the necessity of second-order information for content-aware routing: variance captures sharply aligned keys that mean alone cannot distinguish from uniformly weak alignments.

Practical Implications

  1. Memory efficiency: MERLIN at m=256m=256 outperforms baselines at m=64m=64 (4× more memory), showing that better routing can substitute for more memory states.
  2. General architecture-agnostic: Works on both Gated DeltaNet (linear attention with delta rule) and Mamba-2 (state-space model), suggesting broad applicability across MSLA architectures.
  3. Modest overhead: Extra memory cost limited to at most 12.6% (GDN) and 4.2% (Mamba-2) at dr=128d_r=128, decreasing quadratically with drd_r. Parameter overhead is on par with Meanpool baseline (4.6% for GDN, 2.2% for Mamba-2).

Conclusion

Main Takeaways

  • MERLIN provides a simple and general routing mechanism for improving long-context capabilities of MSLA models by leveraging both first and second moments of segment keys.
  • The method consistently outperforms existing aggregation methods (position-based and mean-based) across multiple benchmarks, architectures, and segment lengths.
  • The variance of key-query alignment is critical for content-aware aggregation, enabling the model to identify sharply aligned keys within segments.

Future Directions

  • Exploring adaptive segmentation strategies (separation) in conjunction with MERLIN's aggregation, potentially optimizing both jointly.
  • Scaling to larger model sizes and longer contexts (beyond 16K tokens).
  • Investigating the application of moment-based routing to other sequence modeling paradigms beyond linear attention.
  • Further reducing the memory footprint of the second-moment features through compression or low-rank approximations.

Related papers