UncleanCode's picture
DenseAM HP transfer reproduction: verdict, figure, code, logs
c846d02 verified
|
Raw History Blame Contribute Delete
7.26 kB
# Reproduction: Hyperparameter Transfer for Dense Associative Memories
**Paper** arXiv:2605.10164 — Roi Holtzman (Oxford), Dmitry Krotov (IBM Research), Boris Hanin (Princeton ORFE), May 2026.
**Target** Table 1 and Figure 4.
**Verdict** `verified`, with a documented caveat on the SGD arm (see *Where it diverges from the paper*).
No author code was released for this paper, so this is an independent reimplementation
from the equations in the text, not a run of the authors' code.
---
## The claim under test
Figure 4 shows HP transfer for DenseAMs trained on MNIST denoising in the proportional
regime (eq. 1.3, κ = K/N = 2, ρ = P/N = 5, β = B/P = 0.1) for 256 epochs. Input
dimension is varied by plaquette coarse graining (block size j = 1…6), which changes
N, K, P and B together by a factor of 31 between the largest and smallest scale.
The claim: with the centered parameterisation of Table 1, the *optimal effective
learning rate η₀ is the same* at every scale, i.e. a hyperparameter tuned on the small
model transfers to the large one.
## Model, exactly as specified
Forward pass (eq. 2.1, the centered model):
f(x) = s2 · Wᵀ σ_C( s1 · W g(x) + b ) + c
σ_C = C ∘ σ ∘ C, C = I_K − (1/K)·11ᵀ, g = tanh, σ = ReLU (p=1) or softmax
Centering is implemented literally: the pre-activation has its mean over the K hidden
units removed, and so does the post-activation. Gradients flow through C, which is the
constrained-gradient convention of Appendix A (W̃ = CW, b̃ = Cb).
Table 1, proportional scaling:
| activation | optimiser | s1 | s2 | η_W | η_b,0 | η_c,0 |
|---|---|---|---|---|---|---|
| ReLU p=1 | SGD | 1/√N | 1/√K | η₀√K | η₀ | η₀ |
| ReLU p=1 | Adam | 1/√N | 1/√K | η₀ | η₀ | η₀ |
| Softmax | SGD | 1/√N | 1/√K | η₀√K | η₀ | η₀ |
| Softmax | Adam | 1/√N | 1/√K | η₀ | η₀ | η₀ |
Objective (eq. 1.2), plain minibatch SGD / Adam with β₁=0.9, β₂=0.999, ε=1e-8,
W, b, c ~ N(0,1) at initialisation, one random seed per run.
## Data
MNIST, plaquette reduction j × j with grid ⌈28/j⌉, pixels centred across the dataset
(Appendix J). Scales, all in the proportional regime:
| j | N | K | P | B |
|---|---|---|---|---|
| 1 | 784 | 1568 | 3920 | 392 |
| 2 | 196 | 392 | 980 | 98 |
| 3 | 100 | 200 | 500 | 50 |
| 4 | 49 | 98 | 240 | 24 |
| 5 | 36 | 72 | 180 | 18 |
| 6 | 25 | 50 | 120 | 12 |
P training points are drawn from images 0–39999; a 2000 image held-out slice (58000–59999)
is never used for fitting. 256 epochs = 2560 gradient steps at every scale.
## Assumptions (the caption does not pin these down)
1. **Noise scale σ_ε = 0.1.** Equation (1.2) leaves σ_ε free and the figure captions do
not state it. We used 0.1 on inputs mapped to [-1, 1].
2. **Pixel range [-1, 1]** (2x−1 from the [0,1] MNIST bytes) so that MSE is on the same
order as the 1e-2 … 4e-1 range the paper plots.
3. **Plaquette border.** ⌈28/j⌉·j exceeds 28 for j ≥ 5, so the border block is
edge-replicated before averaging.
4. **Biases trainable** (Table 1 sets η_b,0 = η_c,0 = η₀, which only makes sense if they are).
5. **Metric** = per-element mean squared error on the P training points, averaged over
seeds; the held-out MSE is reported alongside it in the JSON.
## Results
528 runs on Modal (CPU containers), 396 for the ReLU panels and 132 for the softmax
panels. The full ReLU grid takes 164 s wall clock with one container per run.
Per-scale optimal η₀ (median over seeds, argmin of final train MSE):
| scale | ReLU SGD | ReLU Adam | Softmax SGD | Softmax Adam |
|---|---|---|---|---|
| j=1 N=784 | 30 | 0.1 | 30 | 1.0 |
| j=2 N=196 | 30 | 0.1 | 30 | 0.3 |
| j=3 N=100 | 10 | 0.03 | 30 | 0.3 |
| j=4 N=49 | 10 | 0.01 | 30 | 0.3 |
| j=5 N=36 | 3 | 0.01 | 10 | 0.3 |
| j=6 N=25 | 3 | 0.01 | 10 | 0.1 |
| **spread** | 10× | 10× | 3× | 10× |
| **one η₀ for all six** | 3 (worst 3.67×) | **0.03 (worst 1.42×)** | 10 (worst 1.17×) | 0.1 (worst 1.13×) |
"One η₀ for all six" is the operational test of transfer: take the single learning rate
that minimises the *worst* per-scale ratio to that scale's own optimum. The grid spans
5.5 decades, so a worst-case penalty of 1.1–1.4× means one number essentially serves all
six scales.
What reproduces:
- **Transfer yes.** Across a 31× range of N (and of K, P, B) a single η₀ is within 1.4×
of optimal at every scale in the ReLU+Adam arm, and the argmin moves by at most one
decade in every arm. This is the paper's claim.
- **Curve shapes and ordering.** Final train MSE falls monotonically with N at fixed η₀
in all four panels, exactly as in Figure 4, and the four (activation, optimiser)
combinations order the same way: Adam below SGD, ReLU below softmax.
- **Adam is the stable one.** The stability edge (largest η₀ with finite loss) is η₀ = 10
at all six scales under Adam, i.e. the divergence threshold is scale invariant to the
resolution of our grid. This is the sharper version of the transfer claim.
Where it diverges from the paper:
- **The SGD upturn is two decades late.** In the paper the ReLU+SGD curves turn up
around η₀ ≈ 0.3–1. In our reimplementation they keep falling to η₀ ≈ 30 and only
diverge above that, so the SGD arm has no interior minimum and its "optimal" η₀ is
really the grid edge. We could not find a reading of Table 1 that moves it: Adam
matches the paper's shape at the printed η₀ values, so this is specific to the
η_W = η₀√K branch and to the bias learning rate, not a global scale error.
- **Our ReLU fits better.** Best train MSE 1.5e-3 … 2.7e-3 versus the 1e-2 … 4e-1 in
Figure 4. The softmax levels (0.004 … 0.25) do match the paper's range.
Memorisation is cheap here: 120 points at j=6 against 1325 parameters, so a
well-tuned run of 2560 steps can go below the Bayes denoising floor.
Taken together: the parameterisation and the transfer phenomenon are real and
reproduce at the level of one learning rate serving a 31× range of model size. The
absolute location of the SGD instability does not reproduce, which is what would be
needed to match Figure 4 panel (a) point for point.
## Files
- `denseam_repro.py` — model, data pipeline, training loop, Modal app
- `run_grid.py` — the 528-run grid on Modal (one container per run)
- `analyze.py` — aggregation, transfer metrics, Figure 4 style plot
- `results/grid_relu.jsonl`, `results/grid_softmax_a.jsonl`, `results/grid_softmax_b.jsonl`
— every run, including the diverged ones, with loss curves
- `results/analysis.json` — per-scale optima, spreads, single-η₀ regret
- `results/figure4_repro.png` — the four panels
- `logs/` — raw Modal client logs, including the failed first attempts
## Reproducing
```bash
# data: two MNIST idx files, placed in data/
python -m modal run run_grid.py # needs MODAL_TOKEN; ~3 min for 396 runs
python analyze.py results/grid_relu.jsonl results/grid_softmax_a.jsonl results/grid_softmax_b.jsonl
```
Environment: Python 3.11, torch 2.15.0+cpu, numpy; Modal app `denseam-repro`, 2 CPU per
container, no GPU. Seeds are fixed per run (1000 + seed for the data draw), so a rerun
is bit-identical.