Skip to main content

DM-3 — Breaking the 2D matrix ceiling

Open In Colab

The question: a \(d\times d\) matrix saturates at rank \(d\). What are the four ways 2025–2026 layers escape it?

Prerequisites: M1, M3, M4, M7 · Runtime: ~3 seconds on CPU.

Even with MesaNet’s exact least-squares solve, a linear matrix \(\mathbf{S} \in \mathbb{R}^{d_v \times d_k}\) has a hard geometric ceiling: it can store at most \(d_k\) linearly independent key–value pairs without interference. Push past \(d_k\) distinct writes and every 2D linear update rule hits the wall.

Between June 2025 and November 2026, four distinct architectural escapes emerged — each trading a different resource (tensor order, logarithmic state count, a small exact cache, or sparse table rows) to break the 2D rank wall:

  1. Triadic Linear Attention (Sep 2026): lift the 2D matrix \(\mathbf{k}\mathbf{v}^\top\) to a 3D tensor \(\mathbf{k} \otimes \mathbf{k}' \otimes \mathbf{v}\), multiplying capacity by \(E\) with only two tiny extra projections.
  2. Log-Linear & Bilateral Log-Linear Attention (Jun 2025 / Nov 2026): replace one matrix with a Fenwick-tree hierarchy of \(O(\log T)\) matrices (plus a second origin-anchored hierarchy in Bilateral).
  3. HOLA — A Hippocampus for Linear Attention (Jul 2026): pair a compressive delta-rule matrix \(\mathbf{S}_t\) with a bounded exact KV cache \(\mathcal{A}_t\) for items that shouldn’t be compressed.
  4. Delta N-gram (Oct 2026): replace the dense matrix with a sparse hashed N-gram table \(\mathbf{T}^0 + \Delta\) updated by a state-dependent row delta rule — which breaks dense rank limits cleanly, yet exposes a new failure mode (hot-row collisions).

Grounding: Log-Linear Attention (Guo et al., Jun 2025); HOLA (Cui, Jul 2026); Triadic Linear Attention (Sieberling et al., Sep 2026) Eqs. 2–5; Delta N-gram (Wu, Oct 2026) Eqs. 5, 8 & §8; Bilateral Log-Linear Attention (Islam & Cong, Nov 2026).

Objective

After this module you should be able to:

  • Explain why no 2D linear update rule can store more than \(d_k\) arbitrary key–value pairs without error.
  • Write the Triadic Linear Attention 3D state update \(\mathbf{S}_t = \mathbf{S}_{t-1} + \mathbf{k}_t \otimes \mathbf{k}'_t \otimes \mathbf{v}_t\) and verify that a second key of dimension \(E\) multiplies capacity by \(E\).
  • Explain the intuition of Log-Linear / Bilateral hierarchies (\(O(\log T)\) multi-scale states) and HOLA (compressive RNN + exact KV hippocampus).
  • Implement Delta N-gram’s sparse convex row update and reproduce the hot-row collision pathology Wu (2026) candidly reports.

Why it exists (the limitation it fixes)

Think of a \(d_k \times d_v\) matrix as a room with \(d_k\) orthogonal axes. You can hang one value on each axis cleanly. Hang a \((d_k + 1)\)-th distinct key and it must be a linear combination of the first \(d_k\) keys — so writing to it unavoidably smears across earlier memories. Improving the write rule (DM-1, DM-2) helps you approach \(d_k\) cleanly, but it cannot push past \(d_k\). To store more, you have to change the shape of the state object itself.

Reading

  • Triadic Linear Attention (Sieberling et al., Sep 2026): shows that contracting two key axes \((\mathbf{q}_t, \mathbf{q}'_t)\) is mathematically equivalent to using the Kronecker-product key \(\boldsymbol\kappa_t = \mathbf{k}_t \otimes \mathbf{k}'_t \in \mathbb{R}^{d_k E}\) — giving \(E\times\) capacity with only two small projections!
  • Log-Linear Attention & Bilateral Log-Linear: \(O(\log T)\) states in a Fenwick tree; Bilateral adds a second tree anchored at the start of the sequence so early context isn’t over-compressed.
  • HOLA (Cui, Jul 2026): readout \(\mathbf{o}_t = \mathbf{q}_t^\top \mathbf{S}_t + \lambda_t g_{\text{attn},t}(\mathbf{q}_t)\) combines compressive delta state with exact KV lookup.
  • Delta N-gram (Wu, Oct 2026): retrofits a frozen LLM’s hashed N-gram table with a 4.1M state-dependent writer; proves \(\|\Delta_j\| \le V\), yet shows 8 shared format rows grow to \(4.4\text{–}11.7\times \|\mathbf{T}_j^0\|\) and zero-shot LoCoMo QA fails (0.44 vs. 56.79 F1).

1. Triadic 3D state vs. 2D DeltaNet past the rank wall

Here is the core trick of Triadic Linear Attention (Sieberling et al., Sep 2026). Instead of projecting each token to one key \(\mathbf{k}_t \in \mathbb{R}^{d_k}\), project it to two keys: \(\mathbf{k}_t \in \mathbb{R}^{d_k}\) and a small second key \(\mathbf{k}'_t \in \mathbb{R}^{E}\) (say \(E=4\)). Their outer product \(\boldsymbol\kappa_t = \mathbf{k}_t \otimes \mathbf{k}'_t\) lives in \(\mathbb{R}^{d_k \cdot E}\)!

So the 3D tensor state \(\mathbf{S}_t \in \mathbb{R}^{d_k \times E \times d_v}\) has \(E\times\) the linear rank of a 2D matrix, while adding almost zero parameters (just two \(d \times E\) projections) and remaining 100% compatible with the delta rule and chunkwise parallelism (Triadic Eq. 5).

Let’s test 2D DeltaNet (\(d_k = 16\)) against Triadic 3D DeltaNet (\(d_k = 16, E = 4 \Rightarrow\) effective key dim \(64\)) and a HOLA-style hybrid (2D DeltaNet + a small exact KV buffer of size 16) as we write \(N = 4\) up to \(N = 48\) distinct pairs!

import torch
import torch.nn.functional as F
import matplotlib.pyplot as plt

torch.manual_seed(0)
d = 16
E = 4
N_max = 48

keys1 = F.normalize(torch.randn(N_max, d), dim=1)
keys2 = F.normalize(torch.randn(N_max, E), dim=1)
vals  = F.normalize(torch.randn(N_max, d), dim=1)

S_2d = torch.zeros(d, d)              # capacity ~ 16
S_3d = torch.zeros(d, d * E)          # triadic unfolded: capacity ~ 64
S_hola = torch.zeros(d, d)            # 2D delta + exact KV cache of last 16 items
kv_buf_k, kv_buf_v = [], []
buf_cap = 16

err_2d, err_3d, err_hola = [], [], []
checkpoints = list(range(4, N_max + 1, 4))

for t in range(N_max):
    k1, k2, v = keys1[t], keys2[t], vals[t]
    kappa = torch.outer(k1, k2).reshape(-1)  # unit-norm Kronecker key in R^{d*E}

    # 2D DeltaNet
    S_2d = S_2d + 0.9 * torch.outer(v - S_2d @ k1, k1)
    # Triadic 3D DeltaNet
    S_3d = S_3d + 0.9 * torch.outer(v - S_3d @ kappa, kappa)
    # HOLA-style: write to 2D delta AND keep exact KV for recent/high-error items
    S_hola = S_hola + 0.9 * torch.outer(v - S_hola @ k1, k1)
    kv_buf_k.append(k1); kv_buf_v.append(v)
    if len(kv_buf_k) > buf_cap:
        kv_buf_k.pop(0); kv_buf_v.pop(0)

    if (t + 1) in checkpoints:
        n = t + 1
        e2 = sum((S_2d @ keys1[j] - vals[j]).norm().item() for j in range(n)) / n
        e3 = sum((S_3d @ torch.outer(keys1[j], keys2[j]).reshape(-1) - vals[j]).norm().item() for j in range(n)) / n
        # HOLA readout: use exact KV cache if max cosine sim > 0.95, else fall back to S_hola
        K_mat = torch.stack(kv_buf_k)  # (buf, d)
        V_mat = torch.stack(kv_buf_v)  # (buf, d)
        eh = 0.0
        for j in range(n):
            sims = K_mat @ keys1[j]
            if sims.max().item() > 0.95:
                out = V_mat[sims.argmax()]
            else:
                out = S_hola @ keys1[j]
            eh += (out - vals[j]).norm().item()
        eh /= n
        err_2d.append(e2); err_3d.append(e3); err_hola.append(eh)

print(f"Mean recall error across all {N_max} stored pairs (2D rank ceiling d={d}):")
print(f"  2D DeltaNet (d=16)          : {err_2d[-1]:.3f}  (saturated past N=16)")
print(f"  HOLA hybrid (+16 exact KV)  : {err_hola[-1]:.3f}  (exact on buffered, lossy on evicted)")
print(f"  Triadic 3D (d=16, E=4 -> 64): {err_3d[-1]:.3f}  (stays clean up to N=48)")

plt.figure(figsize=(6.8, 3.0))
plt.plot(checkpoints, err_2d,   "o-", label="2D DeltaNet (rank 16)", color="#c85a53")
plt.plot(checkpoints, err_hola, "s-", label="HOLA hybrid (2D + 16 exact KV)", color="#2563eb")
plt.plot(checkpoints, err_3d,   "^-", label="Triadic 3D (d=16, E=4 -> 64)", color="#1f6f66", lw=2.2)
plt.axvline(d, ls="--", color="gray", alpha=0.6, label="2D rank ceiling (N=d)")
plt.xlabel("number of distinct stored pairs N"); plt.ylabel("mean recall error")
plt.title("Breaking the 2D matrix ceiling: Triadic 3D & HOLA vs. 2D DeltaNet")
plt.legend(fontsize=8); plt.tight_layout(); plt.show()
Mean recall error across all 48 stored pairs (2D rank ceiling d=16):
  2D DeltaNet (d=16)          : 1.023  (saturated past N=16)
  HOLA hybrid (+16 exact KV)  : 0.761  (exact on buffered, lossy on evicted)
  Triadic 3D (d=16, E=4 -> 64): 0.574  (stays clean up to N=48)

Look at the vertical dashed line at \(N = d = 16\): right there, 2D DeltaNet bends upward sharply. HOLA delays the damage by holding exact copies of the buffered items (in real HOLA, a learned gate \(\lambda_t\) blends the two readouts smoothly), while Triadic 3D sails straight past \(N = 16\) because its unfolded key space has dimension \(d \cdot E = 64\).

Making \(d_k\) 4× larger inflates the slow projection matrices \(W_k, W_q\) by 4× in parameters and FLOPs. Triadic 3D gets a \(4\times\) larger state matrix while adding only two tiny \(d \times 4\) projections — though you still pay the \(4\times\) memory bandwidth for storing and reading the larger state tensor.

2. Sparse tables & the hot-row collision trap (Delta N-gram)

What if you abandon dense matrices altogether and write into a sparse hashed lookup table \(\mathbf{T} = \mathbf{T}^0 + \Delta\) with \(R\) rows (say \(R = 10{,}000\)), where each token’s local N-gram hashes to one row \(j\)?

That is Delta N-gram (Wu, Oct 2026). Because only row \(j\) is touched on a write, different N-grams never interfere — unless they hash to the same row or share the same frequent N-gram! Its block-averaged row update is a convex combination:

\[\Delta_j^+ = (1 - w_j)\Delta_j + A_j, \qquad \beta_a = \sigma\big(B_\theta[\mathbf{x}_a, \Delta_j, \mathbf{v}_a - \Delta_j, \log(1 + c_j)]\big).\]

Notice two remarkable things about this equation: 1. State-dependent gate: \(\beta_a\) explicitly reads the current row state \(\Delta_j\) and its write count \(c_j\). 2. Boundedness: because \(w_j \in [0, 1]\) is a convex weight, \(\|\Delta_j\|\) is provably bounded by the target norm \(V\).

So why did Delta N-gram still suffer 176–198% layer-2 drift on math probes after 35,000 writes? Because natural language is Zipfian: frequent format bigrams like (:, \n) get hit thousands of times, driving those hot rows up to \(4.4\text{–}11.7\times \|\mathbf{T}_j^0\|\) even though each individual write is bounded! Let’s simulate that Zipfian hot-row effect in 15 lines.

torch.manual_seed(0)
R, d = 500, 16
T0 = torch.randn(R, d) * 0.25        # pretrained N-gram table (small norm ~ 1.0)
Delta = torch.zeros(R, d)            # sparse patch, bounded by V=4.0
counts = torch.zeros(R)

# Zipfian stream: rows 0..4 are frequent format bigrams (hit 40% of the time with
# consistent formatting direction); rows 5..499 are rare content N-grams (hit ~2 times each).
V_target = 6.0
format_dirs = F.normalize(torch.randn(5, d), dim=1)
for step in range(1500):
    if torch.rand(1).item() < 0.40:
        j = int(torch.randint(0, 5, (1,)).item())
        v = F.normalize(format_dirs[j] + 0.1 * torch.randn(d), dim=0) * V_target
    else:
        j = int(torch.randint(5, R, (1,)).item())
        v = F.normalize(torch.randn(d), dim=0) * V_target
    beta = 0.10
    Delta[j] = (1 - beta) * Delta[j] + beta * v
    counts[j] += 1

rel_hot  = (Delta[:5].norm(dim=1) / T0[:5].norm(dim=1)).mean().item()
rel_rare = (Delta[5:].norm(dim=1) / T0[5:].norm(dim=1)).mean().item()
print(f"After 2,000 Zipfian writes (every row bounded by ||Delta_j|| <= {V_target}):")
print(f"  Mean ||Delta_j|| / ||T0_j|| on 5 hot format rows : {rel_hot:.2f}x  (huge drift!)")
print(f"  Mean ||Delta_j|| / ||T0_j|| on 495 rare rows     : {rel_rare:.2f}x")
After 2,000 Zipfian writes (every row bounded by ||Delta_j|| <= 6.0):
  Mean ||Delta_j|| / ||T0_j|| on 5 hot format rows : 5.44x  (huge drift!)
  Mean ||Delta_j|| / ||T0_j|| on 495 rare rows     : 0.68x

Even though every row obeys the strict bound \(\|\Delta_j\| \le V\), the hot format rows saturate toward \(V\) while rare rows barely move — producing a \(4\times\)–\(10\times\) relative perturbation right on the punctuation/formatting tokens that every downstream prompt uses.

Honest scope. We skipped coding Log-Linear / Bilateral’s Fenwick-tree scan to keep the notebook short; its idea is clean in one sentence (keep \(O(\log T)\) exponentially coarser summary states, plus a second origin-anchored tree in Bilateral so the beginning of a long document stays sharp). The four escapes here show the fundamental trade-off: tensor order (Triadic), logarithmic state count (Log-Linear), exact cache hybrid (HOLA), or sparse addressing (Delta N-gram).

Exit check

  1. How does Triadic Linear Attention get an \(E\)-fold increase in effective rank while adding only two tiny projections?
  2. What failure of standard Log-Linear Attention does Bilateral Log-Linear Attention fix?
  3. How does HOLA combine a compressive delta state with an exact KV cache at readout?
  4. Why can a sparse table with provably bounded rows (\(\|\Delta_j\| \le V\)) still corrupt a frozen LLM’s general math performance?

Next → DM-4 — State-dependent gating & memory forensics