---
title: Spectral Koopman Attention (SKA)
url: https://www.emergentmind.com/topics/spectral-koopman-attention-ska
type: topic
---

# Spectral Koopman Attention (SKA)

Spectral Koopman Attention (SKA) is a drop-in replacement for causal self-attention designed for associative recall with constant inference memory. By leveraging a closed-form dynamical operator and power-iterated spectral filtering, SKA augments state-space model (SSM) blocks to enable key–value binding and retrieval without the need for a linearly-growing key–value (KV) cache. The method accumulates sufficient statistics in $O(r^2)$ streaming state, where $r$ is a small projection rank, and fits a compact linear (Koopman) operator to the key and value stream via kernel ridge regression. This approach is central to Echo, a KV-cache-free associative recall architecture, and allows for infinite-horizon content-based retrieval in long-context agentic inference [2605.06997].

## 1. Motivation and Architectural Distinctions

SKA addresses critical limitations in both Transformer-based attention and recurrent SSMs. In standard softmax attention, memory and compute scale as $O(N^2)$ and $O(Nd)$, respectively, where $N$ is sequence length and $d$ is model dimensionality; this creates a bottleneck for long-context reasoning due to the linear growth of the KV cache. By contrast, SSMs operate at constant memory per token but demonstrate a "memory cliff," with retrieval accuracy decaying exponentially as the gap between a stored fact and its recall increases.

SKA differs fundamentally from prior compression-based or linear attention variants and SSMs in the following respects:

- **Memory Usage:** Maintains only three fixed-size matrices per head—$r \times r$ or $P \times r$, where $P$ is head dimensionality—resulting in constant $O(r^2+Pr)$ memory per head.
- **Retrieval Dynamics:** Rather than compressing all history into a fixed recurrent state, SKA computes and stores sufficient statistics for a ridge-regressed Koopman operator, preserving exact content associations for arbitrarily long horizons.
- **Interleaving with SSMs:** In architectures like Echo, SKA layers are alternated with SSM (e.g., Mamba-2) layers, allowing local sequential modeling and global associative retrieval.

## 2. Mathematical Formulation

SKA operates on input representations $x_t \in \mathbb{R}^d$, projecting into key, query, and value spaces via matrices $W_k, W_q \in \mathbb{R}^{d \times r}$ and $W_v \in \mathbb{R}^{d \times P}$. Key and query vectors are normalized per block:

\[
z_t = W_k x_t, \quad z^\mathrm{q}_t = W_q x_t, \quad v_t = W_v x_t
\]
\[
\hat z_t = \frac{z_t}{m}, \quad \hat z^\mathrm{q}_t = \frac{z^\mathrm{q}_t}{m}, \quad m = \max_{s \leq T} \|z_s\|_2
\]

Three streaming statistics are accumulated for each head:

\[
G_t = G_{t-1} + \hat z_t \hat z_t^\top \in \mathbb{R}^{r \times r}
\]
\[
M_t = M_{t-1} + \hat z_t \hat z_{t-1}^\top \in \mathbb{R}^{r \times r}
\]
\[
C_{v,t} = C_{v,t-1} + v_t \hat z_t^\top \in \mathbb{R}^{P \times r}
\]

Closed-form kernel ridge regression computes the Koopman operator and regression weights:

\[
A_w = M G^{-1}, \quad B_v = C_v G^{-1}
\]
\[
G = G_T + \varepsilon I_r
\]

With Cholesky factorization $G = LL^\top$, the whitened Koopman operator is $A_w = L^{-1} M L^{-\top}$ and is spectrally normalized to ensure bounded norm:

\[
\hat{A}_w \leftarrow \frac{A_w}{\max(1, \sigma_\mathrm{max}(A_w))} \times \gamma, \quad \gamma \in [1.0, 1.5]
\]

Retrieval proceeds by mapping the query to whitened space, applying $K$ steps of $\hat{A}_w$, and then projecting back for value readout:

\[
w_q = L^{-1} \hat z^\mathrm{q}
\]
\[
w_f = \hat{A}_w^K w_q
\]
\[
z_f = L w_f
\]
\[
\hat y = \eta \cdot B_v z_f, \quad \eta \text{ learned}
\]

Alternatively, this process can be interpreted as spectral weighting of operator eigenmodes.

## 3. Integration with SSM Blocks

In the Echo architecture, SKA is interleaved with SSM layers, such as those based on Mamba-2. The typical update sequence per token is:

1. Apply SSM update to obtain $h_t$ from $x_t$ and $h_{t-1}$.
2. Compute SKA projections and update streaming statistics ($G, M, C_v$).
3. Perform Cholesky factorization, update operator fits ($A_w, B_v$), apply spectral normalization, and execute power-iterated retrieval.
4. Add the SKA output to the residual, apply LayerNorm, and feed into an MLP.

This workflow enables the model to maintain constant-size state for associative recall, while allowing high-capacity local sequential modeling through SSM recurrence. Chunk-causal computation supports efficient LM training and ensures equivalence to full-prefix statistics when partitioned into reasonable chunk sizes (e.g., $S=64$).

## 4. Computational Complexity

The computational and memory complexity of SKA, standard attention, and SSM blocks are as follows:

| Model Type      | Training Complexity   | Inference Complexity    | State Memory         |
|-----------------|----------------------|------------------------|----------------------|
| Standard Attention | $O(N^2d)$             | $O(Nd)$                 | $O(Nd)$ (KV-cache)   |
| SSM (Mamba-2)      | $O(Nd)$                | $O(d)$                  | $O(d)$               |
| SKA                | $O\left(\frac{N}{S} r^3 + N r^2\right)$* | $O(r^3)$            | $O(r^2+Pr)$ (fixed)  |

*Per chunk of size $S$.

In SKA, memory and compute requirements remain constant in sequence length $N$, scaling instead with projection rank $r$ and head dimensionality $P$. The dominant cost arises from Cholesky decomposition and triangular solves in $O(r^3)$ per token.

## 5. Empirical Evaluations

Empirical results demonstrate that SKA-augmented SSMs eliminate the memory cliff observed in pure SSMs and outperform both standard attention and hybrid SSM+Attention approaches:

- **Sub-Million Scale Transfer:** On mixed synthetic benchmarks (tool-trace, recall, multi-hop) at ~1M parameter scale, SSM+SKA achieves ≈81% mean accuracy compared to SSM+Attn (76%) and pure SSM (54%). In length generalization, SSM+SKA retains 65% retrieval accuracy at gaps of $4096$ tokens, where others fall below 5%.
- **Multi-Query Associative Recall (MQAR, 50M):** Pure Mamba-2 is at chance (≈3%), Mamba-2+Attn nearly achieves 100%, and Mamba-2+SKA achieves 100% accuracy in all tested configurations, including settings with 32 KV pairs and gaps up to $4096$.
- **Language Modeling (180M):** Echo-180M achieves best-in-class performance on 5 out of 6 held-out transfer benchmarks and records a perplexity of 16.48 on WikiText-103, outperforming or matching baseline Transformer, Mamba-2/3, and GDN models at comparable scale and less data.

## 6. Ablation and Analysis

Ablation studies indicate that the retrieval accuracy gains of SKA are attributable primarily to the spectral operator and closed-form ridge regression, not to the prefix mask or masking strategies. Removing the action mask (i.e., accumulating statistics across all tokens) yields negligible differences in training. Both prefix and masked retrieval variants share equivalent operator fits. Chunk-causal training at reasonable chunk size (e.g., $S=64$) results in no loss in retrieval relative to full-prefix compute, confirming correct accumulation semantics.

## 7. Implementation Recommendations

Key implementation considerations for SKA are as follows:

- **Projection rank $r$:** Should be selected near the per-head dimension $P$ or in the range $[32, 64]$ for 50–200M models. Larger $r$ offers better conditioning (stability, retrieval bandwidth) but increases cubic cost.
- **Regularization $\lambda$ ($\varepsilon$):** Set near $10^{-3}$ to $10^{-2}$ for Gram invertibility while preserving operator expressiveness.
- **Power filter order $K$:** $K=2$ separates persistent from transient modes; higher values may oversuppress intermediate eigenmodes.
- **Spectral normalization $\gamma$:** Learnable in $[1.0, 1.5]$ to maintain output variance.
- **Numerical precision:** Key accumulations and factorizations should employ full FP32 precision; cast outputs to model type for speed.
- **Kernel fusion:** Fusing the batched Cholesky/inversion steps and power iterations in a single GPU kernel improves throughput.

In summary, Spectral Koopman Attention enables content-addressed retrieval via explicit kernel ridge regression and spectral filtering from constant streaming state, eliminating the SSM memory cliff and achieving attention-equivalent associative recall with constant inference memory. This provides a backbone for architectures such as Echo, which deliver KV-cache-free associative recall for long-context agentic reasoning and tool-calling scenarios [2605.06997].

Source: https://www.emergentmind.com/topics/spectral-koopman-attention-ska