Certified overrelaxed Hopfield attention
Implementation & benchmark of arXiv:2608.21304 — Basin-Preserving Discretizations of Modern Hopfield Retrieval Dynamics: Energy Cells, Dissipation, and the Attention Limit
Source paper: Basin-Preserving Discretizations of Modern Hopfield Retrieval Dynamics: Energy Cells, Dissipation, and the Attention Limit arXiv:2608.21304 ⓘ · analyzed Sep 1, 2026
AI-generated research hypothesis, automatically tested. Not peer-reviewed.
Idea description
Replace the standard unit-step modern Hopfield retrieval update with a relaxed step using theta greater than 1, while restricting theta to the theoretically safe interval (0,2). The relaxed map has the same fixed points as ordinary attention and provably decreases the Hopfield energy, so it can move farther toward an attractor per iteration without changing the retrieval objective.
Formulas
Mathematical statement
The energy is E(x) = 1/2 ||x||_2^2 - lse_beta(X^T x), where x is the d-dimensional retrieval state, X = [xi_1,...,xi_N] is the d by N memory matrix, beta > 0 is inverse temperature, and lse_beta(z) = beta^{-1} log(sum_mu exp(beta z_mu)). Define p(x) = softmax(beta X^T x). Then grad E(x) = x - X p(x), so the attention map A(x) = X p(x) and the relaxed update Psi_theta(x) = (1-theta)x + theta A(x) = x - theta grad E(x). The paper's parameter-uniform unit-curvature majorant gives the descent inequality E(Psi_theta(x)) <= E(x) - theta(1-theta/2)||grad E(x)||_2^2 for 0 < theta < 2. Thus theta greater than 1 is an overrelaxed but dissipative step. Energy cells are connected components of sublevel sets containing one attractor and no other critical point; below the cell's escape energy, the paper proves containment in the basin of the continuous flow and every relaxed map in this interval.
Implementation notes
Integrate this at the iterative retrieval state update in a modern Hopfield layer or associative-memory attention block. For each state x, compute logits z = beta times X-transpose times x, p = softmax(z), attention output a = X times p, and candidate x_new = (1-theta)x + theta a. Start with fixed theta values 1.25, 1.5, and 1.75. Use a numerically stable energy evaluator based on logsumexp: E(x) = 0.5 times squared norm of x minus logsumexp(beta times X-transpose times x) divided by beta. A safeguarded version evaluates E(x_new); if it is larger than E(x), replace theta by 1 + (theta - 1)/2 and recompute until the energy decreases or theta reaches 1. Pseudocode is: z=beta*X.T@x; p=softmax(z); g=x-X@p; theta=theta_init; repeat candidate=x-theta*g; if E(candidate)<=E(x): x=candidate; break; theta=1+(theta-1)/2. Stop when the relative step norm is below tolerance. The paper supplies the dissipation inequality; the engineer estimates only the current energy and gradient norm. First test on a two-dimensional synthetic memory with separated and nearly colliding patterns, then on MNIST prototype retrieval or CIFAR feature retrieval. Compare theta=1, fixed overrelaxation, and safeguarded overrelaxation at equal attention-evaluation budgets. Measure iterations to tolerance, wall-clock latency, final retrieval accuracy, energy-increase frequency, and basin-switch frequency. A successful result is at least 20 percent fewer iterations at equal accuracy, with no energy increases for the safeguarded method.
Verification
Stage 1 · Toy mechanism gate: Passed ✓
Stage 2 · Mechanism transferred to benchmark: Confirmed ✓
Stage 2 · Practical benchmark result: Significant win ✓
Methodology: 8 paired seeds, permutation test (p<0.05) against a learning-rate-tuned baseline. How verification works
Stage 1 — Mechanism check agent confidence 9/10
Built stable Hopfield energy, attention, fixed relaxed updates, safeguarded updates, toy prediction sweeps, and a digits-prototype retrieval benchmark in experiment.py. The observed dissipation ratio matched theta(1-theta/2) across theta in (0,2) to near numerical precision; no energy increases occurred below 2, while increases appeared frequently above 2. The mechanism manifested, but the practical speedup claim did not: theta=1 was fastest and most accurate in the digits test, while overrelaxation required many more iterations.
- Agent confidence
- 9/10
- Baseline
- theta=1: digits accuracy 0.9233, mean 2.64 attention evaluations, 0 energy-increase steps; toy retrieval mean iterations 4.03 separated / 5.40 colliding
- Idea
- fixed theta=1.5: digits accuracy 0.9167, mean 24.19 evaluations, 0 energy-increase steps; safeguarded theta=1.5: accuracy 0.9167, mean 24.21 evaluations, 0 energy-increase steps. Toy dissipation ratio at theta=1.5 was 0.375016 separated vs predicted 0.375 and 0.375000 colliding vs predicted 0.375; theta=2.05 caused 118/400 and 166/400 increases in the two toy memories.
Limitations: Only small 2-D synthetic memories and sklearn digits mean prototypes were tested; no trained modern Hopfield layer, MNIST neural classifier, CIFAR features, GPU implementation, FLOP-normalized large-scale benchmark, basin-switch statistics, or formal proof was performed. The theorem boundary is sufficient rather than necessary for each individual state, so some states can still decrease energy above theta=2.
How to run: python3 experiment.py
Stage 2 — Benchmark vs. tuned baseline (arXiv:2608.21304)
Beats the tuned baseline by 23.7% (p=0.0156, wins 7 / 8 paired seeds; metric: lower is better).
- Benchmark
- Sequence modeling
- Model
- transformer_tiny
- Paired seeds
- 8
- Baseline mean
- 0.2601
- Idea mean
- 0.1983
- Effect (Δ)
- -0.0617 (−23.7%; negative = idea better)
- Wins
- 7 / 8 paired seeds
- p-value
- 0.0156 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- ±12.9%
- Mechanism
- Confirmed ✓
- Practical effect
- Helps
- Baseline tuning
- swept over 3 configs
Only the registered sequence track was tested. Vision, tabular, and dynamics transfer were not evaluated, and wall-clock retrieval latency was not measured.
How to run: python3 bench_experiment.py
Verdict computed by deterministic test code from paired-seed statistics — not by the language model.
Stage 2 — Benchmark latest Worked ✓
Agent confidence: 8/10
Certified overrelaxed Hopfield attention significantly improved sequence-forecast test MSE relative to the tuned theta=1 baseline. The trained-model dissipation signature quantitatively confirmed the predicted energy decrease and showed no energy increases.
- Baseline
- lr=0.01; mean test MSE 0.2600801; std 0.0312714
- Idea
- lr=0.003, theta=1.75; mean test MSE 0.1983311; std 0.0213586; delta -0.0617490; p=0.0156; 7/8 wins
Benchmark result
Beats the tuned baseline by 23.7% (p=0.0156, wins 7 / 8 paired seeds; metric: lower is better).
- Benchmark
- Sequence modeling
- Model
- transformer_tiny
- Paired seeds
- 8
- Baseline mean
- 0.2601
- Idea mean
- 0.1983
- Effect (Δ)
- -0.0617 (−23.7%; negative = idea better)
- Wins
- 7 / 8 paired seeds
- p-value
- 0.0156 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- ±12.9%
- Mechanism
- Confirmed ✓
- Practical effect
- Helps
- Baseline tuning
- swept over 3 configs
Only the registered sequence track was tested. Vision, tabular, and dynamics transfer were not evaluated, and wall-clock retrieval latency was not measured.
How to run: python3 bench_experiment.py
Artifacts
- bench_experiment.py 4.7 KB View Raw
- bench_report.json 3.6 KB View Raw
- experiment.py 4.6 KB View Raw
- report.md 1.8 KB View
- report_bench_2026-09-01T180549.md 3.2 KB View
- results.json 11.7 KB View Raw