NeurIPS 2026Coming to NeurIPS in Sydney?Explore papers, orals & directions

Where to Look First in Grokking: Attention and MLP Coherence in Modular Arithmetic

Ruian Lei, Ruoxi Jiang, Marley M B R Vellasco, M. Tanveer, Zenglin XuNeurIPS 2026

TL;DR

When neural networks "grok," they spend thousands of epochs blindly memorizing training data before abruptly snapping into a state of near-perfect generalization. Historically, watching this generalizing rule form under the hood required reverse-engineering the exact mathematical circuit in advance. This paper introduces a clever retrospective compass—the Geometric Coherence Score—that reveals where in the Transformer and when in training this transition happens, showing that the MLP quietly organizes itself first while the attention heads lock in the final pieces right around the breakthrough.

What Problem Does This Paper Address?

Picture a small Transformer learning modular addition—essentially clock arithmetic. Early in training, it hits 100% accuracy on the training set while completely failing on unseen test pairs. It has built a giant, brittle lookup table. Yet if you leave the GPU running long after training loss bottoms out, test accuracy suddenly shoots up to 99%. That delayed, phase-transition-like epiphany is called grokking.

Mechanistic interpretability researchers love grokking because they can crack open the finished network and find elegant trigonometric algorithms (often called "Clock" or "Pizza" circuits). Once you know the exact algorithm, you can build custom progress measures to watch it assemble during the flat test-accuracy plateau.

Here is the catch: to build those progress measures, you have to reverse-engineer the final algorithm first—and two networks trained on the exact same task might invent completely different ones. If we face a network whose internal algorithm we haven't decoded yet, how do we know where inside the architecture, and when during training, to look first?

Methods

The authors introduce a novel, algorithm-free diagnostic called the Geometric Coherence Score (GCS). The intuition is wonderfully geometric: if a network is relying on a memorized lookup table, nudging two related inputs slightly will cause their internal representations to veer off in unrelated directions. If the network has learned a shared underlying rule, related inputs should respond similarly to local nudges.

Figure 1: The score and its trajectories. (a) Dots are inputs, shaded groups are neighbors in the final model, and arrows are local output responses. (b) Median and interquartile range (IQR) over 35 one-layer runs, with one run (GELU addition, seed 777, selected post hoc) in thin lines. MLP coherence initially falls while test accuracy remains nearly flat. Each coherence curve is smoothed over three checkpoints and scaled to its own range up to 5,000 epochs after grokking. Test accuracy is not rescaled.

What is new here is how GCS defines "related inputs" retrospectively without knowing the task's math:

  1. Final-Model Neighborhoods: Take the fully trained model at the end of a run and see which inputs cluster together as $k$-nearest neighbors in its final hidden space. That fixed graph becomes your reference map for the entire training history.
  2. Directional Probes: At every saved checkpoint, use Jacobian-vector products (JVPs)—automatic differentiation that measures instantaneous directional derivatives without finite noise—to nudge the prediction-position (=) embedding along principal neighbor directions.
  3. Spectral Summary: Measure the cosine similarity of these local output changes separately for the Attention and MLP sublayers, build a weighted similarity graph, and compute its spectral entropy to get a single coherence score per checkpoint.

To verify that these geometric shifts actually matter for prediction, the authors pair GCS with causal weight resets, activation patching, and frozen-component continuation experiments, rolling individual components back to a pre-grokking checkpoint ($t^-$) chosen just before attention outputs become symmetric to swapping operands (e.g., $a + b$ vs. $b + a$).

Datasets

No new benchmarks are introduced; the authors use standard synthetic modular arithmetic datasets modulo a prime $p = 113$ (with a cross-prime check at $p = 97$). Models read token sequences formatted as [a, b, =] and predict the result at = across four operations—addition, subtraction, multiplication, and division—using a harsh 30% train / 70% test split designed to induce grokking.

Key Insights and Ideas

  • Memorization looks like geometric shattering: Untrained networks actually start with high GCS because smooth random weights nudge everything the same way. As the network memorizes the training set, MLP coherence plunges into a deep trough—inputs that will eventually share a rule are being forced into fragmented, independent lookup entries.
  • MLPs lay the groundwork; Attention finishes the job: In one-layer Transformers, MLP coherence bottoms out early and recovers substantially before test accuracy buds, whereas attention coherence peaks right around grokking and dips afterward.
  • Pre-grokking MLPs are already "grok-ready": If you take a fully generalized network and swap its MLP weights back to a checkpoint shortly before grokking ($t^-$), the model barely blinks. Do the exact same rollback to the Attention layer, and test accuracy collapses. Even more strikingly, taking those $t^-$ MLP weights, freezing them, and transplanting them back into an early memorizing network allows the rest of the model to successfully grok, whereas freezing early memorizing MLP weights traps it.
Figure 2: Attention and MLP trajectories across depths. Attention (solid) and MLP (dashed) coherence, median and IQR over 35 one-layer, 34 two-layer and 35 three-layer runs, measuring the last block. Epochs are divided by each run’s tgrok and each score is scaled to its own range. The dotted line marks tgrok.

Key Results

  • Consistent trajectory signatures: Across 104 grokking runs (spanning 1–3 layers, ReLU/GELU/SiLU activations, and 4 arithmetic tasks), MLP coherence drops to a trough and partly recovers by grokking in 103/104 runs, while attention coherence peaks near grokking and dips in 94/104 runs. The separation between components is sharpest in 1-layer models (30/35 vs. a random-anchor null mean of 10.3).
  • Asymmetric reset costs: In 17 one-layer addition and multiplication runs, resetting final attention weights to $t^-$ causes a mean test accuracy drop of 0.40, whereas resetting the MLP drops accuracy by only 0.03—outweighing even parameter-matched random MLP unit resets (max mean drop 0.025). Within attention, resetting $K$ or $O$ matrices hurts far more than $Q$ (near zero) or $V$.
  • Frozen-MLP training: Continuing training from the MLP-coherence trough with frozen $t^-$ MLP weights reaches 99% test accuracy within budget in 15/17 runs, compared to 3/17 with trough MLP weights and 4/17 with untrained initialization weights.
  • Pinpointing critical windows: Using attention GCS alone to pick 11-checkpoint windows on 71 held-out runs captures accuracy jumps at the 0.887 median percentile and symmetry shifts at the 0.963 percentile, beating random windows (0.779 and 0.508) and frequently highlighting earlier, non-overlapping training stages compared to simple $L_2$/CKA distance-to-final metrics.

Limitations and Future Work

The authors are admirably candid about the boundaries of their setup:

  • Toy scale and architecture: Experiments focus on small, decoder-only Transformers without LayerNorm on synthetic arithmetic. Pilot runs with LayerNorm grokked too quickly for the checkpoint sampling rate to resolve the joint signature (appearing in only 2/11 one-layer and 0/10 two-layer runs), and deeper networks were only probed at their final block.
  • Retrospective and probe-sensitive: Because GCS relies on the final model's hidden states, it cannot be used as a live early-warning monitor during training, and it may miss transient precursor circuits that get wiped out during cleanup. Furthermore, changing how directional probes are aligned (e.g., using Procrustes rotations instead of singular-value rank, or probing operand tokens instead of =) alters or delays the observed MLP recovery.
  • Open mechanistic questions: It remains an open question for future work whether zooming into GCS-selected checkpoint windows actually makes it easier for researchers to reconstruct unknown circuits from scratch.

Summary updated

Abstract

Networks trained on modular arithmetic memorize their training set long before learning a rule that generalizes to unseen inputs. Progress measures built from a known algorithm track its formation, but they need the algorithm in advance. We ask where in the network, and when in training, this formation can be seen without the algorithm. We introduce the Geometric Coherence Score (GCS), which retrospectively compares the local responses of attention and MLP outputs at inputs that the final model treats as neighbors. A shared rule can give similar responses there, whereas separate lookup entries need not. We find that across 104 grokking runs of one- to three-layer Transformers, MLP coherence falls to a trough and partly recovers by grokking in 103. Attention coherence rises near grokking and dips afterwards in 94. The trajectories differ most clearly in one-layer networks. To relate these trajectories to prediction, we reset the final model's attention or MLP to a pre-grokking checkpoint selected by attention's operand-swap symmetry. In one-layer addition and multiplication models, the attention reset costs more test accuracy than the MLP reset (mean drops 0.40 and 0.03), and more than any size-matched reset of random MLP units. The same MLP weights, held fixed during further training from the preceding coherence trough, let 15 of 17 runs reach 99% test accuracy within budget, against 4 with the untrained MLP. To focus further analysis on specific training stages, we also select short windows of consecutive checkpoints using attention coherence alone. These windows capture larger accuracy gains and attention-symmetry changes than random windows do and often differ from those selected by distance to the final model. These results point to MLP response changes before grokking and later changes in attention as starting points for investigating how a generalizing rule forms.
BibTeX
@inproceedings{lei2026where,
  author = {Ruian Lei and Ruoxi Jiang and Marley M B R Vellasco and M. Tanveer and Zenglin Xu},
  title = {{Where to Look First in Grokking: Attention and MLP Coherence in Modular Arithmetic}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=rtabRRmgxe},
}
Figure