Where to Look First in Grokking: Attention and MLP Coherence in Modular Arithmetic
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.