Grokking, Visualized

Reproduce

Everything on this site is computed by an open pipeline: github.com/BurnyCoder/visualizing-grokking-modular-addition.

git clone --recurse-submodules https://github.com/BurnyCoder/visualizing-grokking-modular-addition
cd visualizing-grokking-modular-addition
uv sync --extra cu130        # or --extra cpu
uv run grokviz --phases all --skip publish_runs_to_hub,publish_site_data  # download, validate, train, analyse, export, build (no uploads)

Does our code reproduce the paper?

Before trusting any figure we checked that our re-implementation of the paper's analysis gives the paper's own numbers on the paper's own network (its published checkpoint at epoch 40,000). Rows marked no are listed honestly, with our best explanation; see also the errata.

IDQuantityPaper / ARENAOursMatchWhereNote
R1loss at epoch 40k (all 12,769 pairs, 113-way)2.41e-072.412e-07yesp.6–7The paper calls it test loss; it matches the all-pairs loss (test-only is 3.02e-7).
R2key frequencies[14, 35, 41, 42, 52][14, 35, 41, 42, 52]yesp.4
R3non-negligible W_E frequencies66yesp.4threshold 10 % of max; the 6th is k=31
R4W_L residual after 10-direction approximation<0.55 %0.005517yesp.6squared-norm ratio 0.552 % at step 40,001 (match: < 0.6 %) and 0.520 % at the last checkpoint (step 49,901); the norm ratio, 7.4 %, does not match the paper's wording (Frobenius norm under 0.55 % of ‖W_L‖)
R5neurons with >85 % FVE at one frequency433433yesp.6
R6neurons in the k=14 cluster4444yesp.7
R7Table 1 FVE of u_k/v_k read-offs (mean of 10)0.96240.9635yesp.6 Table 1paper's ten values average 96.24 %; per-row values in details.table1
R8alogit fit Σα_k cos(w_k(a+b−c)) FVE0.950.9614yesp.6
R8bloss of the fitted logits4.7e-084.395e-08yesp.6
R9aloss keeping only the 40 key 2D components7.24e-087.236e-08yesp.7
R9bMLP projected onto 10 W_L directions1.19e-072.377e-07nop.8closest variant shown; all variants in details.wl_projection
R9cMLP projected onto the nullspace5.274.804nop.8closest variant (MLP-only, bias-corrected) shown
R10aclustered neurons replaced by degree-2 polynomial2.48e-072.482e-07yesp.7
R10bneurons restricted to cos/sin(w_k(a+b)) terms5.54e-081.121e-07nop.7per-neuron restriction gives this value; the paper's 5.54e-8 matches the restricted-LOGITS loss (R19a, 5.547e-08) within 0.2 %, so the paper likely restricted logits
R11aMLP skip connection zero-ablated9.12e-078.877e-07yesp.13
R11bMLP skip connection mean-ablated7.25e-077.248e-07yesp.13
R11cattention heads zero-ablated24.324.27yesp.13
R11dskip around attention zero-ablated19.11.086nop.13not reproduced: our ablation sets resid_mid = attention output (the paper does not specify its hook)
R12mean attention from '=' to '=' (per head)0.1–0.4 %[0.004418, 0.001111, 0.004427, 0.001177]yesp.13match range 0.05–0.45 % (the paper's 0.1–0.4 % at its printed precision); our largest values, 0.44 %, round to the paper's 0.4 %
R13alinear fit of the attention softmax (variance explained)0.9750.9756yesp.16
R13bloss with softmax replaced by its linear fit2.12e-072.124e-07yesp.16
R14head frequencies (Table 2)[35, 42, 52, 42][35, 42, 52, 42]yesp.15 Table 2
R16ARENA excluded loss per key freq[0.000282, 0.000633, 0.00161, 0.07195, 0.03288][0.000282, 0.0006332, 0.00161, 0.07195, 0.03288]yesARENA tests.test_excl_loss
R17ARENA cluster sizes 14/35/41/42/52/always[44, 93, 145, 87, 64, 79][44, 93, 145, 87, 64, 79]yesARENA 2-circuit-and-feature-analysis
R18ARENA ReLU regression r² (with / without quadratic)[0.966, 0.849][0.9659, 0.8494]yesARENA
R19aARENA trig-only (restricted) logits loss5.547e-085.547e-08yesARENA
R19bARENA key-frequency neuron projection loss (with / without always-firing)[2.482e-07, 1.179e-06][2.482e-07, 1.179e-06]yesARENA
R15SSW at the paper's phase boundaries 1.4k / 9.4k / 14k (Fig. 7)falls; steepest in cleanup[3373, 2001, 995.5]yesp.8 Fig. 7; boundaries p.9qualitative; fall per step 0.171 (circuit formation) vs 0.219 (cleanup)
R20atotal SSW at epoch 40k and at the end of training[955, 942][955.4, 941.8]yesARENA §3 Analysis During Traininglast checkpoint: step 49901
R20battention to '=' returns after ~43k (attention at 40k → 45k)attends to '=' again[[0.004418, 0.001111, 0.004427, 0.001177], [0.1133, 0.0008202, 0.09146, 0.0008718]]yesARENA §3 Analysis During Training2 heads rise ≥ 5× to > 5 %; 2 such heads is our match criterion (ARENA gives no head count)

Validating the checkpoints

Recomputing the training loss of the paper's checkpoints on our reconstruction of its train/test split reproduces the paper's logged losses at every checked step (e.g. step 101: 2.211129 recomputed vs 2.211129 logged). This confirms both the data split and the step labelling (checkpoint “epoch e” = weights after e + 1 updates).

Our own runs

22 networks were trained with the paper's settings (chapter 20); their checkpoints, curves and analysis results are published on Hugging Face (Adam's saved states are not), and the hypotheses were frozen before training (git tag prereg-v1).