Subspace Crystallization in Grokking: Rank Compression Tracks the Phase Transition
Organizations: Lossfunk
Abstract
Grokking describes understanding something deeply and intuitively. In neural networks, it is the phenomenon where a network generalizes long after memorizing its training data. This delay has been linked to a fall in the effective rank of the network's weight matrices, but whether this rank compression drives grokking or follows it is still unresolved. We study a mean-field MLP and a one-layer transformer trained on modular arithmetic and observe that: (i) Compression follows the onset, not memorization. Every transformer memorizes its training data within 250 steps, while the grokking onset (the first step at which test accuracy reaches 95%) varies from 6,500 to 21,000 steps. The steepest fall in effective rank comes about 900 steps after the onset, however late the onset occurs, and networks that memorize without grokking compress far less. (ii) Subspace crystallization. We call the span of the fewest top singular directions of a weight matrix that preserve 99% of test accuracy its sufficient subspace. Its size can shrink as the margin between the correct and the best wrong output grows, so we also count the directions needed to keep the outputs within 10%. In the transformer, this count falls during the transition from a quarter or more of the available directions to about a tenth, which we call subspace crystallization. (iii) Imposing low rank does not speed up grokking. Against a factorized full-rank control, capping the rank of the transformer's MLP input weights delays the onset, and capping the rank of its embedding stops 15 of 20 runs from grokking. Compression is therefore a signature of grokking rather than its cause.
Figures & tables
| MLP | Transformer | |
| 1. Compression follows grokking, not memorization | ||
| Compression starts after test accuracy rises | 45 of 45 runs | 28 of 29 seeds |
| Fall in effective rank | 10% if grokked | if grokked, 15–23% if not |
| 2. Subspace crystallization: the transformer’s solution contracts into a low-dimensional subspace as it groks | ||
| Directions needed per matrix | Accuracy: from 110 to 65 of 128 Outputs: 122–127 of 128 (MSE) | Outputs: from 27–53 to 8–13, during the transition |
| 3. Imposing low rank does not speed up grokking | ||
| Optimizer | Effective lr | ER | |||
|---|---|---|---|---|---|
| Start (step 20,000) | – | 726 | 111 | 115.1 | 65 |
| AdamW, | 658 | 85 | 117.8 | 65 | |
| Gradient descent | 662 | 85 | 117.8 | 65 | |
| AdamW, | 775 | 120 | 114.8 | 70 | |
| Gradient descent | 783 | 126 | 114.6 | 72 | |
| AdamW, (main) | 1,040 | 203 | 104.8 | 89 |
| Model | Checkpoint | Outputs within 10% | 99% of accuracy | Median margin |
|---|---|---|---|---|
| MSE (15 seeds) | step 0 (untrained) | – | ||
| step 11,000 (before onset) | ||||
| step 20,000 | ||||
| end ( ) | ||||
| MSE, random labels (5) | end, training inputs | – | ||
| CE, lr (5) | last before onset |
| Matrix | Grokked | Final test accuracy (%) | ||
| None (unfactorized) | – | 5/5 | ||
| 128 | 5/5 | |||
| 32 | 5/5 | |||
| 24 | 4/5 | |||
| 16 | 3/5 | |||
| 8 | 1/5 |
| Step | Test acc. (%) | Restricted | Excluded | ||||
|---|---|---|---|---|---|---|---|
Appendix figures & tables44 assets
Supplementary material from the paper’s appendix.
Appendix
| Variant | Grokked | Final ER | Stage-4 drop (%) | Fourier IPR | |
|---|---|---|---|---|---|
| Main | 5/5 | ||||
| wd 0 | 5/5 | ||||
| wd | 5/5 | ||||
| wd | 5/5 | ||||
| wd | 5/5 | ||||
| CE, lr | 1/5 | ( ) | – |
| lr | Grokked | after | , end | , end | ER , end | ||
|---|---|---|---|---|---|---|---|
| 0.01 | 5/5 | ||||||
| 0.03 | 5/5 | ||||||
| 0.1 | 5/5 | ||||||
| 0.3 | 0/5 | – | – | – | – | ||
| 1.0 | 0/5 | – | – | – | – |
| Step | 20,000 | 30,000 | 50,000 | 100,000 |
|---|---|---|---|---|
| ER | ||||
| Size of top 65 |
| Weight decay | ER | Size of remaining 63 | |||
|---|---|---|---|---|---|
| 0 | |||||
| (main) | |||||
| Step 20,000 | Step 50,000 | Step | |
|---|---|---|---|
| (= Euler expression) | |||
| Share of coordinates with | |||
| Median | |||
| Mean (1 = sign descent) |
| Optimizer | Effective lr | ER | ||||
| At step 20,000 | – | 726 | 529 | 111 | 115.1 | 65 |
| AdamW, | 1,793 | 718 | 346 | 95.7 | 99 | |
| AdamW, | 1,582 | 874 | 318 | 94.7 | 98 | |
| AdamW, (main) | 1,040 | 748 | 203 | 104.8 | 89 | |
| AdamW, | 775 | 551 | 120 | 114.8 | 70 | |
| AdamW, | 658 | 469 | 85 | 117.8 | 65 |
| Threshold (fraction of clean accuracy) | (mean s.d.) |
|---|---|
| 90% | |
| 95% | |
| 99% | |
| 99.9% |
| Step | Test acc. (%) | ER | Freq. for 90% power | ||
|---|---|---|---|---|---|
| 10,000 | |||||
| 11,000 | |||||
| 12,500 | |||||
| 15,000 | |||||
| 20,000 | |||||
| 30,000 |
| Step | Hidden space ( ) | Input space |
|---|---|---|
| 0 | ||
| 5,000 | ||
| 10,000 | ||
| 12,500 | ||
| 15,000 | ||
| 20,000 |
| Matrix | Top- | Bottom- | Random subset | Random subspace | |
|---|---|---|---|---|---|
| MLP | / 128 | ||||
| Transformer | / 128 | ||||
| Transformer | / 128 | ||||
| Transformer | / 97 | ||||
| Transformer | / 98 |
| Model | Checkpoint | Out05 | Cen10 | Marg10 | Median margin | ||
|---|---|---|---|---|---|---|---|
| MSE, main | step 0 | – | 116.4 | 123.8 | 116.3 | 102.2 | |
| step 11,000 | 119.3 | 122.4 | 126.6 | 122.7 | 123.8 | 0.025 | |
| step 20,000 | 64.9 | 122.3 | 125.7 | 122.4 | 113.1 | 0.470 | |
| end | 89.1 | 127.3 | 127.9 | 127.3 | 121.4 | 0.611 | |
| end, training inputs | 88.0 | 127.3 | 127.9 | 127.5 | 121.1 | 0.649 | |
| MSE, random labels | end, training inputs | – | 123.0 | 127.0 | 123.2 | 116.6 | 0.110 |
| Model grokked model | Map | Test accuracy (%) |
|---|---|---|
| Grokked, other seed | fitted orthogonal | |
| Grokked, other seed | none | |
| Grokked, other seed | random orthogonal | |
| Random initialization | fitted orthogonal | |
| Random-label network | fitted orthogonal | |
| Grokked on (other task) | fitted orthogonal |
| MLP (15 seeds) | Transformer (29 grokked) | |
|---|---|---|
| Memorization step | 250 in all seeds | |
| Grokking onset | ||
| Start of compression | : (15/15 ) | : (28/29 after ) |
| Steepest ER decrease | (15/15 ) | (27/29 ) |
| Share of ER decrease after |
| Series | Null hypothesis | Med. | Rejected ( ) | ||
|---|---|---|---|---|---|
| First differences | Compression Grokking | 6/15 | |||
| Grokking Compression | 15/15 | ||||
| Stationary (ADF) | Compression Grokking | 4/15 | |||
| Grokking Compression | 15/15 |
| Run | Final test acc. (%) | Peak rate (per 1,000 steps) | Relative change, step 4,000 end |
|---|---|---|---|
| Grokked (29 seeds) | |||
| wd 1.0, seed 12 | 8.2 | ||
| wd 0.1, seeds 0–2 | 1.8–4.3 | to | to |
| wd 0.3, seeds 0–2 | 9.1–13.2 | to | to |
| Step | Group | ||||
|---|---|---|---|---|---|
| 10,000 | before own onset (17) | ||||
| after own onset (12) | |||||
| never groks (1) | 52 | 84 | 71 | 67 | |
| 12,500 | before own onset (9) | ||||
| after own onset (20) | |||||
| never groks (1) | 50 | 86 | 70 | 66 |
| Quantity | Transformer, held-out | MLP, | MLP, | |
|---|---|---|---|---|
| H1 | ( ) | (14/15) ∗ | – | – |
| H2 | – | (15/15) ∗ | (15/15) ∗ | |
| H3 | ( ) | – | (15/15) ∗ | (15/15) ∗ |
| H4 | – | (15/15) ∗ | (12/15) ∗ | |
| H5 | – | (15/15) ∗ | (15/15) ∗ | |
| H6 | for at , and unfactorized | – | and | and |
| Grokked | 15/15 | 15/15 |
|---|---|---|
| H2: | ||
| 15/15, , | 15/15, , | |
| H3: |
| Seed | Seed | Seed | ||||||
|---|---|---|---|---|---|---|---|---|
| 15 | 7,000 | 20 | 17,500 | 25 | 17,750 | |||
| 16 | 12,500 | 21 | 8,000 | 26 | 8,750 | |||
| 17 | 7,500 | 22 | 13,000 | 27 | 15,750 | |||
| 18 | 17,000 | 23 | 16,500 | 28 | 8,500 | |||
| 19 | 7,500 | 24 | 10,250 | 29 | 8,250 |
| Model | Grokked | Final test acc. (%) | Final ER | |
|---|---|---|---|---|
| Unfactorized (main) | 3/3 | |||
| , (control) | 3/3 | |||
| , | 3/3 | |||
| , | 3/3 | |||
| , | 3/3 | |||
| , | 3/3 |
| Step | , | Unfactorized |
|---|---|---|
| 0 | ||
| 500 | ||
| 1,000 | ||
| 1,500 | ||
| 2,000 | ||
| 3,000 |
| Task | Model | Grokked | Final test acc. (%) | Final ER | |
|---|---|---|---|---|---|
| Unfactorized | 3/3 | ||||
| , | 3/3 | ||||
| , | 3/3 | ||||
| , | 3/3 | ||||
| Unfactorized | 3/3 | ||||
| , | 3/3 |
| Task | Model | ER minimum before (step) | ER at | ER at step 8,000 | |
|---|---|---|---|---|---|
| unfactorized | – | – | |||
| ( ) | |||||
| ( ) | |||||
| ( ) | |||||
| unfactorized | – | – | |||
| ( ) |
| Model | Metric | Early | At window end | False alarms | Lead | |
|---|---|---|---|---|---|---|
| MLP | Fourier IPR ( ) | 2,500 | 15/15 | 14/15 | 5/5 | 10,000 |
| 5,000 | 15/15 | 15/15 | 5/5 | 7,500 | ||
| 10,000 | 15/15 | 14/15 | 5/5 | 2,500 | ||
| MLP | Gradient norm | 2,500 | 15/15 | 0/15 | 5/5 | 9,000 |
| 5,000 | 15/15 | 0/15 | 0/5 | 2,500 | ||
| 10,000 | 3/15 | 0/15 | 3/5 | 0 |
| Matrix | Max rank | |||
|---|---|---|---|---|
| (embedding) | 97 | |||
| / | 32 | / | ||
| 32 | ||||
| 128 | ||||
| 128 | ||||
| 128 |
| Property | MLP (MSE) | MLP (CE) | Transformer |
|---|---|---|---|
| Loss, weight decay, training steps | MSE, , | CE, , | CE, , |
| of first-layer weights (of 128) | – | ||
| of first-layer weights (of 128) | – | ||
| When falls | never | late, after | during the transition |
| Frequencies holding 90% of first-layer power | ( ) | – | ( ) |
| Run | Step | Test acc. (%) | ||||
| wd 1.0, seed 12 | 5,000 | 31 | 33 | 64 | 70 | 2.8 |
| end | 23 | 26 | 49 | 55 | 8.2 | |
| wd 0.1, seeds 0–2 | 5,000 | 45–47 | 42–43 | 74–77 | 81–84 | 1.0–2.8 |
| end | 35–38 | 35–37 | 67–69 | 78–83 | 1.8–4.3 | |
| wd 0.3, seeds 0–2 | 5,000 | 40–42 | 38–40 | 71–73 | 79–82 | 1.2–2.9 |
| end | 29–30 | 30–31 | 48–52 | 53–59 | 9.1–13.2 |
| Run | Train | Test | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| wd 1.0, seed 12 | 100.0 | 8.2 | 42 | 4 | 4 | 30 | 42 | 68 | 62 | 62 |
| wd 0.1, seed 0 | 100.0 | 4.3 | 43 | 4 | 19 | 31 | 50 | 82 | 78 | 72 |
| wd 0.1, seed 1 | 100.0 | 1.8 | 43 | 4 | 18 | 31 | 51 | 81 | 78 | 73 |
| wd 0.1, seed 2 | 100.0 | 3.0 | 44 | 4 | 18 | 31 | 52 | 84 | 79 | 73 |
| wd 0.3, seed 0 | 100.0 | 13.2 | 34 | 4 | 4 | 31 | 43 | 74 | 61 | 62 |
| wd 0.3, seed 1 | 100.0 | 10.7 | 36 | 4 | 4 | 31 | 43 | 73 | 61 | 62 |
| Grokked | Not grokked | |||
| Subspace pair | wd 1.0 | wd 0.1 | wd 0.3 | wd 1.0 |
| ( ) | ( ) | ( ) | ( ) | |
| Attention write ( ) vs. MLP read ( ) | ||||
| MLP read ( ) vs. MLP write ( ) | ||||
| MLP write ( ) vs. unembedding read ( ) | – | – | – | |
| MLP read vs. key frequencies of | – | – | – | |
Grokking
Grokking is delayed generalization in which neural networks memorize training data before abruptly learning a rule that works on unseen examples.
See all 81 papers