Long-context sequence models face a fundamental tradeoff: softmax attention uses flexible token-level interactions at quadratic cost, whereas linear attention obtains linear-time training and constant-time decoding by compressing history into a fixed-size state. In this work, we ask whether we can connect these regimes through a tunable notion of structure. To this end, we introduce Structured Matrix Attention (SMat-Attention) via a family of causal masks with structured long-range routing whose row supports have VC-dimension d. In our construction, d=1 recovers the standard causal mask, and increasing d permits richer subset-routing patterns. We give chunkwise forward and backward algorithms to enable hardware-efficiency. For sequences of length T, the hard-routing construction takes O(T2−3/d+T) work, despite the mask being dense, for our prescribed family. In fixed-horizon streaming, decoding after the distant prefix takes constant time per token using O(T1−1/d) cached states. SMat-Attention therefore makes VC-dimension an explicit knob governing access-pattern complexity, prefill cost, and decoding memory. Empirically, subset-routing and rule-assisted multi-key retrieval experiments illustrate the masks' routing expressiveness. Extensions to Mamba-2 and Gated DeltaNet using learned routing with top-k query reads retain subquadratic prefill, improve recall accuracy over the backbones in several settings, and achieve comparable small-scale language-modeling performance.
Figures & tables
Figure 1: Block layout of M(d) ; shaded regions are nonzero. Both diagonal blocks are ordinary causal masks, and all long-range structure lives in G .
Figure 2: Hyperplane aggregation and shared-state reads in SMat-Attention. (a) A profile table is indexed by F33 . Three coordinate hyperplanes each aggregate their incident profile states into a type state (A-C). The central profile belongs to all hyperplanes, so its state contributes to all the sums. (b) Each type state supplies every query of that type. The horizontal lines carry fixed shared states throughout these reads. The output scatters its results back to this order. The figure shows augmented long-range contributions, before causal addition and final normalization.
Figure 3: Prefill cost against fused causal attention (bf16, 8 heads, r=64 , chunk 128 ; median of 15 timed runs).
Figure 4: Cached decoding for additive SMat-Attention with hard-routing. Left: distant key-value contributions pool into profile states, which are added via the incidence structure to form the type cache. Colors identify the contributing profiles within each cached summary. Right: successive decoding steps access the fixed cache while maintaining one running state for recent tokens. The input vectors at each step are the query, key, and value. The key and value update the running state before answering the query. Repeated cache banks depict successive views of the shared memory.
Figure 5: Routing-pattern match against the requested dimension k, after training with the mask fixed, T = 1024, mean of three seeds.
Model
k=1
k=2
k=3
Softmax
44.29 (49.00)
66.60 (57.68)
66.46 (57.55)
Linear Baselines
0.00 (0.00)
0.00 (0.00)
0.00 (0.00)
LSH bucketing (125 buckets)
100.00 (0.00)
1.71 (0.50)
0.03 (0.03)
SMat ( d=2 )
100.00 (0.00)
13.90 (2.13)
1.29 (0.33)
SMat ( d=3 )
100.00 (0.00)
99.82 (0.10)
34.20 (1.21)
SMat ( d=4 )
99.98 (0.03)
99.92 (0.03)
98.99 (0.03)
Table 1: Exact routing-pattern match (%) on multi-key retrieval, by the number k of marked positions. Payloads are resampled each batch and evaluation uses fresh ones. Mean (std) over 3 seeds. SMat performs better at higher k as d increases.
Backbone
Width
Base
Log-Linear
d=2
d=3
d=4
Gated DeltaNet
16
44.34 (7.58)
44.17 (10.90)
49.82 (5.21)
45.40 (3.70)
44.63 (1.39)
Gated DeltaNet
32
63.99 (4.14)
68.41 (8.13)
70.07 (0.48)
79.74 (2.65)
75.21 (6.78)
Gated DeltaNet
64
70.59 (7.96)
79.06 (2.11)
78.88 (8.01)
87.37 (4.12)
80.52 (6.07)
Mamba-2
16
41.36 (3.07)
46.47 (7.61)
47.61 (4.36)
61.57 (2.41)
49.19 (5.93)
Mamba-2
32
73.55 (5.02)
76.57 (4.90)
75.44 (0.19)
77.89 (4.45)
81.90 (2.49)
Mamba-2
64
87.87 (4.26)
85.85 (1.92)
91.76 (0.95)
92.89 (2.13)
93.14 (1.55)
Table 2: Final MQAR accuracy (%), 32 epochs. Mean (std) over 3 seeds.
Variant
Mamba-2
GDN
Native
51.14 (17.74)
53.78 (2.85)
+ Log-Linear
66.01 (19.88)
57.78 (5.36)
+ SMat ( d=2 )
54.10 (3.72)
51.25 (5.28)
+ SMat ( d=3 )
61.65 (3.15)
60.15 (3.27)
+ SMat ( d=4 )
59.12 (15.12)
59.89 (9.34)
Table 3: Average validation accuracy (%) on joint context–key recall, averaged over five memory loads. All models use width 64, 32 epochs, learning rate 0.003. Mean (std) over 3 seeds.
Appendix figures & tables15 assets
Supplementary material from the paper’s appendix.
Appendix
prefill
per decoded token
decode cache
Softmax attention
Θ(T2dv)
Θ(Tdv)
Θ(T) pairs
Linear attention
Θ(Trp)
Θ(rp)
1 state
Log-linear attention
Θ(TlogTrp)
Θ(rplogT)
Θ(logT) states
SMat, VC dim. d
O((T2−3/d+T)rp)
O(rp)
O(T1−1/d) states
Appendix
Table 4: SMat sits between linear and softmax attention. It keeps the O(rp) per-token decoding cost of linear attention and pays for VC dimension d in cache size rather than in decoding time.
Figure 6: Both masks drawn at the same length T=1.5Tmax , in blocks of cdc=Tmax/4 tokens. Left: the fixed- T mask once its boundary is kept at n=Tmax/2 . The incidence block G stops growing at two blocks and everything after the boundary falls to the recurrence. Right: the stepped window, whose recent region stays between cdc and 2cdc tokens at every length while G keeps absorbing the older blocks.
Schedule
1024
2048
4096
8192
No long-range branch
13.3 (10.0)
13.5 (10.6)
12.8 (9.6)
11.7 (9.4)
Boundary kept, current
91.5 (3.7)
78.4 (5.3)
63.6 (9.2)
51.9 (11.2)
Rebuilt, current
91.6 (4.0)
87.2 (4.7)
83.7 (6.1)
81.8 (6.8)
Doubling
78.8 (4.0)
68.7 (4.2)
62.6 (1.8)
53.9 (1.5)
Window, cdc=Tmax/8
93.8 (4.9)
98.3 (1.4)
95.6 (6.8)
90.1 (13.9)
Window, cdc=Tmax/4
82.2 (2.3)
92.9 (1.0)
95.9 (0.5)
97.6 (1.1)
Appendix
Table 5: MQAR accuracy (%) by evaluation length, uniform layout, models trained at length 1024. The quarter-length window is the only schedule whose accuracy rises with the evaluation length, and the only one whose spread does not. Knowing T in advance recovers part but not all of the fixed boundary’s loss: the rebuilt oracle ends at 81.8 against 51.9 for the kept boundary. Mean (std) over 3 seeds.
Schedule
D=0
D=256
D=1024
D=3072
D=7678
No long-range branch
8.7 (6.1)
7.9 (5.7)
8.3 (6.3)
8.0 (6.4)
7.0 (5.8)
Boundary kept, current
35.4 (14.9)
34.7 (15.7)
34.1 (15.1)
33.6 (14.7)
99.6 (0.3)
Rebuilt, current
36.1 (18.4)
34.9 (18.0)
35.9 (18.9)
34.6 (18.8)
99.7 (0.3)
Doubling
22.4 (3.8)
23.1 (2.4)
23.0 (3.2)
22.1 (3.1)
85.6 (7.5)
Window, cdc=Tmax/8
73.4 (20.2)
81.9 (23.0)
81.7 (22.5)
81.9 (22.9)
83.9 (20.1)
Window, cdc=Tmax/4
27.1 (3.0)
94.9 (3.2)
94.3 (3.3)
94.7 (3.0)
97.5 (2.6)
Appendix
Table 6: MQAR accuracy (%) by gap D between the pair region and the query region, placed layout at evaluation length 8192 . The lower block reports how often the pairs actually reach the long-range branch. At D=7678 the pairs precede every boundary and the fixed schedules are the strongest arms. For 256≤D≤3072 the pairs land inside the fixed boundary’s recent region, which it can serve only from the fixed-size recurrence, and its accuracy falls to about 34% while the quarter-length window holds about 95%. At D=0 , the quarter-length window obtains 27.1% , below the two fixed-boundary variants ( 35.4% and 36.1% ). The eighth-length window instead obtains 73.4% , with substantial seed variation. Performance near the boundary therefore depends on the particular window schedule. Mean (std) over 3 seeds.
Schedule
[0,1024)
[2048,4096)
[4096,8192)
[8192,16384)
No long-range branch
1.686 (0.006)
1.675 (0.007)
1.679 (0.008)
1.670 (0.007)
Boundary kept, current
1.634 (0.005)
1.588 (0.005)
1.598 (0.004)
1.595 (0.005)
Rebuilt, current
1.634 (0.005)
1.614 (0.008)
1.619 (0.006)
1.601 (0.004)
Doubling
1.646 (0.008)
1.605 (0.008)
1.610 (0.007)
1.610 (0.008)
Window, cdc=Tmax/8
1.608 (0.003)
1.546 (0.003)
1.561 (0.004)
1.559 (0.004)
Window, cdc=Tmax/4
1.639 (0.008)
1.584 (0.012)
1.596 (0.010)
1.595 (0.014)
Appendix
Table 7: PG-19 bits per byte by position within the evaluation window, trained at length 2048 and evaluated at 16384 ; lower is better. Every schedule improves past the training length rather than degrading, and the quarter-length window is similar to the fixed boundary. Mean (std) over 3 seeds.
Routing
MQAR
MKAR
JCKR
PG-19
Data
Sequence length
1024
64–256
1024
64–3076
16384 / 32768
Vocabulary
–
8192
–
563
50257 (GPT-2)
Task size
k≤6
4–64 pairs
8 pairs
4–512 records
–
Model
Layers
1
2
1
2
8
Appendix
Table 8: Training configuration for each experiment. Routing trains with the mask fixed and optimizes a mean-squared-error readout; MKAR uses binary cross-entropy on one sigmoid logit per pair (multi-label), and MQAR, JCKR and PG-19 use categorical (softmax) cross-entropy. PG-19 batch sizes are per context length, chosen so that every step sees 32,768 tokens, giving 300M training tokens per arm.
Model
k=1
k=2
k=3
k=4
k=5
k=6
Softmax
100.00 (0.00)
52.21 (2.09)
28.78 (0.98)
17.97 (3.47)
7.81 (1.28)
5.27 (0.90)
Mamba-2
100.00 (0.00)
63.09 (9.95)
32.23 (6.60)
19.21 (4.80)
9.90 (1.64)
5.60 (0.81)
DeltaNet
99.93 (0.11)
76.69 (1.85)
46.55 (2.35)
30.21 (4.35)
15.76 (0.45)
9.83 (1.18)
Gated DeltaNet
100.00 (0.00)
66.80 (13.44)
39.78 (5.18)
24.22 (6.80)
16.93 (0.30)
8.27 (2.14)
Log-Linear
99.93 (0.11)
76.69 (1.71)
46.55 (4.30)
28.71 (5.40)
16.41 (1.55)
9.77 (0.59)
SMat ( d=1 )
100.00 (0.00)
77.21 (1.75)
48.31 (4.56)
29.88 (3.65)
14.65 (1.35)
9.96 (1.03)
Appendix
Table 9: Exact routing-pattern match (%) on subset routing, by the number k of marked positions. T=1024 , one layer, 1500 steps, batch 64, learning rate 0.003; payloads are resampled each batch and evaluation uses fresh ones. Mean (std) over 3 seeds. SMat performs better at higher k as d increases.
Train (ms/step)
Prefill (ms)
Decode
Cache
Model
16K
64K
64K
256K
(ms/token)
(MB)
SMat ( d=1 )
12.9
48.1
11.5
45.6
0.25
0.5
SMat ( d=2 )
14.1
51.6
11.3
44.5
0.25
99
SMat ( d=3 )
25.1
107.0
18.3
63.8
0.25
774
SMat ( d=4 )
192.8
1717.9
168.6
725.4
0.26
3439
Gated SMat ( d=2 )
92.7
988.9
43.1
211.3
0.34
99
Appendix
Table 10: End-to-end cost of the subset-routing models: batch 64, fp32. SMat prefill uses the Triton kernels. Decode latency and cache size are at context length 256K. Optimized and reference recurrences share the same one-step decoder. a The SSD kernel exceeds a CUDA launch limit at batch 64 and length 256K. b The upstream port builds a dense T×T level table (512 GiB at 256K). c The reference Log-Linear builds the same dense table and runs out of memory in tr aining at 16K. d Value at 16K.
k=1
k=2
k=3
Model
s0
s1
s2
s0
s1
s2
s0
s1
s2
Softmax
100.0
7.9
25.0
99.9
0.0
100.0
99.9
0.0
99.5
Mamba-2
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
DeltaNet
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
Gated DeltaNet
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
Log-Linear
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
Appendix
Table 11: Per-seed exact-support accuracy (%) behind Table 1 , after 12K steps on 2,048 fresh queries per run. SMat rows use rule-chosen hyperplane directions (see text).
Softmax schedule, LR
k=1
k=2
k=3
no warmup, 3×10−4 (reported)
100.0 / 7.9 / 25.0
99.9 / 0.0 / 100.0
99.9 / 0.0 / 99.5
1K-step warmup, 10−4
100.0 / 0.0 / 13.4
0.0 / 0.0 / 0.0
0.0 / 0.0 / 0.0
1K-step warmup, 3×10−4
100.0 / 1.5 / 13.4
0.0 / 0.0 / 2.8
99.8 / 0.0 / 0.0
1K-step warmup, 10−3
0.0 / 0.0 / 100.0
0.0 / 0.0 / 0.0
0.0 / 0.0 / 0.0
Appendix
Table 12: Softmax on multi-key subset recall at T=1024 : exact-support accuracy (%) for seeds 0 / 1 / 2 under each schedule tried. A run that leaves the constant-prior plateau reaches ≥99% ; the runs between 1% and 25% had begun leaving it when training stopped. The reported row is the best schedule.
Model
T=128
T=256
T=1024
Softmax
97.5
99.5
100.0
Mamba-2
99.2
0.0
0.0
DeltaNet
100.0
100.0
0.0
Gated DeltaNet
100.0
100.0
0.0
Log-Linear
99.9
93.6
0.0
Linear attention
94.8
35.6
0.0
Appendix
Table 13: Positive control: exact-support accuracy (%) for k=1 , seed 0, with the harness, metric, model and 12K-step budget of Table 1 and only the context length changed (8 pairs throughout).
Figure 7: Multi-key subset recall at T=1024 , every seed. Top: training binary cross-entropy of the minibatch at each evaluation step (log scale); the dashed line is the constant-prior loss H(k/8) , and all 18 linear-baseline runs per panel lie on it. Bottom: exact-support accuracy on 2,048 fresh queries, evaluated every 2 K steps.
Model
k=1
k=2
k=3
Mamba-2
0.00 (0.00)
0.00 (0.00)
0.00 (0.00)
SMat ( d=2 )
99.48 (0.72)
2.51 (3.54)
0.00 (0.00)
SMat ( d=3 )
96.43 (4.65)
84.29 (19.86)
0.00 (0.00)
SMat ( d=4 )
100.00 (0.00)
99.98 (0.02)
99.90 (0.14)
Appendix
Table 14: Mamba-2 SMat results across three seeds. Mean (std).
Model
Accuracy (%)
Plain GDN
53.80(2.86)
GDN + SMat ( d=3 )
58.92(4.22)
MoM-derived, profile-count matched
43.73(1.48)
MoM-derived, matrix-storage matched
35.10(3.82)
Appendix
Table 15: Shared-key joint recall: final-test accuracy averaged equally over the five evaluated binding loads. Mean and std reported across three seeds.
Table 16: PG-19 language modeling results. Left: negative log-likelihood (NLL) per token after 300M training tokens with eight layers and width 384. Right: validation perplexity after 750M training tokens at 16K context (seed 123). Lower is better.
Long contexts have become standard in pretrained LLMs, yet they remain expensive to run: prefill compute grows quadratically with sequence length, and every decode step re-reads a key-value cache that grows linearly with it. Sparse attention cuts these costs by attending only to a relevant subset of past tokens, but selecting that subset is itself expensive. We present SpotAttention, a lightweight selector that attaches to a frozen pretrained transformer and learns by KL distillation to estimate its attention distribution. The selector picks the top-K keys each query attends to, and because its estimate is a calibrated distribution, a dual top-p rule reads the per-query, per-layer budget directly from it. Across Qwen3 (dense, 4B-32B) and Qwen3.5 (hybrid linear/full attention, 4B-9B), SpotAttention matches dense accuracy at contexts up to 128K tokens, eight times the training length. Decode at L=128K runs 3.9x faster than FlashAttention and 1.8x faster than Twilight, the strongest training-free baseline. Quantizing the selector's K-cache to INT4 or FP4 microscale shrinks it 3.5x at no accuracy cost.
Modern sequence modeling is dominated by two families: Transformers, whose self-attention can access arbitrary elements of the visible sequence, and structured state-space models, which propagate information through an explicit recurrent state. These mechanisms face different limitations on long contexts: when attention is diffuse, the influence of individual tokens is diluted across the effective support, while recurrent state propagation can lose long-range sensitivity unless information is actively preserved. As a result, both mechanisms face challenges in preserving and selectively retrieving information over long contexts. We propose Sessa, a decoder that places attention inside a recurrent feedback path. This creates many attention-based paths through which past tokens can influence future states, rather than relying on a single attention read or a single recurrent chain. We prove that, under explicit assumptions and matched regimes, Sessa admits power-law memory tails O(ℓ−β) for 0<β<1, with slower decay than in the corresponding Transformer and Mamba-style baselines. We further give an explicit construction that achieves this power-law rate. Under the same assumptions, Sessa is the only model class among those considered that realizes flexible selective retrieval, including profiles whose influence does not decay with distance. Consistent with this theoretical advantage, across matched experiments, Sessa achieves the strongest performance on long-context benchmarks while remaining competitive with Transformer and Mamba-style baselines on short-context language modeling.
Long-context recall in linear-time sequence models highlights a tradeoff in how they write to memory. State-based linear models, such as state-space models (SSMs) and linear Transformers, write densely, updating the entire state for each newly arrived token, which leads to interference and makes specific past tokens hard to recover. Sliding-window attention (SWA) exhibits the opposite behavior: it writes sparsely by storing explicit token representations, but only within a fixed window, so recall drops once the relevant token is evicted. Interpolating between these models, we introduce Raven, a linear-time sequence model that maintains a fixed set of memory slots and, at each step, decays and updates only a selected subset via learned, input-dependent routing. This lets Raven mitigate SWA's position-based overwriting and hard eviction while reducing interference from dense state updates in SSMs, thereby preserving long-range content much more effectively. Across recall-intensive benchmarks, Raven is competitive with or outperforms prior linear-time baselines, achieving strong long-context recall where both SWA and SSMs sharply degrade. It remains effective when extrapolating to context lengths as large as 16x its training length, with similar gains in hybrid architectures.