MIIII

Copenhagen, Denmark

Talk on Mechanistic Interpretability of Deep Learning Models presented at the University of Copenhagen
MIIIINoah SyrkisJanuary 8, 20251 | All 29 tasks grok when stable2 | Embeddings carry order and tasks3 | Each task keeps few frequencies4 | Some frequencies are transient5 | Transients slow grokkingA disgusting pile of matrices is often a poorly written elegant algorithm.After Neel NandaIntroduction▶Deep learning is sub-symbolic▶Interpretability turns weights into maths▶We train a model, then reverse engineer itFigure 1: One neuron of a model trained on (𝑥0+𝑥1)mod𝑝3 of 22Introduction▶We ask when each task is learned▶We ask whether the mechanisms stay fixed▶We ask how they are learned▶We ask how to write them as maths↓𝑓(𝑥)=sin𝑤𝑒𝑥+cos𝑤𝑒𝑥Figure 2: From parameters to a formula4 of 22Introduction▶Grokking is late generalization [1]▶A mechanism needs a general model▶Weights turn from table to algorithmFigure 3: Training loss above and validation loss below, from a grokking run5 of 22Introduction▶Prior work studies modular addition [2]▶We read the pair as a base 𝑝 number▶We predict it modulo each smaller prime▶So there are many tasks and order matters𝑦=(𝑥0+𝑥1)mod𝑝(1.1)𝑦⃗=(𝑥0+𝑥1𝑝)mod𝑞∀𝑞<𝑝(1.2)Figure 4: Modular addition above and our task below. Both 𝑝 and 𝑞 are prime6 of 22Introduction▶Inputs are all pairs of digits below 𝑝▶Targets are their remainders for each 𝑞↓Figure 5: Inputs for 𝑝=7 above. Targets for 𝑞=11 with 𝑝=13 below7 of 221 |All 29 tasks grok when stable▶All 29 tasks generalize at 𝑝=113▶GrokFast amplifies slow gradients [3]▶Without it the model did not convergeFigure 6: Training accuracy above and validation accuracy below, per task, at 𝑝=1138 of 221 |All 29 tasks grok when stable▶A learning rate of 0.003 collapses▶Each collapse follows a loss spike▶Lower rates never collapse▶Clipping at norm 1 changes nothingRate 0.003, 12 collapsesRate 0.001, 0 collapsesRate 0.0003, 0 collapses103104epoch0.00.20.40.60.81.0mean validation accuracyFigure 7: Mean validation accuracy at 𝑝=113. One seed per setting, so preliminary9 of 222 |Embeddings carry order and tasks▶In addition the positions look alike▶They correlate at 0.95, ours at −0.64▶So our input tells 𝑥0 from 𝑥1Figure 8: Positional embeddings for modular ad­dition above and our task below10 of 222 |Embeddings carry order and tasks▶Modular addition uses five frequencies▶Our task uses many more▶Its embedding table is nearly saturatedFigure 9: Token embeddings in a Fourier basis, for modular addition above and our task below11 of 223 |Each task keeps few frequencies▶We remove one frequency from task 𝑞▶It matters if the task’s loss rises 0.05 nats▶At the end only a few still matter▶Larger tasks keep a few more2511172331task 𝑞024answer frequenciesFigure 10: Frequencies that matter at the end, at 𝑝=37. Standard errors over 9 seeds12 of 224 |Some frequencies are transient▶Others matter only early in training▶Removing them later costs under 0.01 nats▶Every seed has them in every task from 11 up▶Larger tasks have more of them102103104epoch0123loss rise when removedFigure 11: Task 19 in one seed. Solid frequencies last and dashed ones fade13 of 225 |Transients slow grokking▶A is plain and B suppresses transients▶C and D suppress unused or lasting ones▶B takes 0.38 of C’s time, give or take 0.04▶Transients slow learning rather than help itABCD0246810thousand epochsFigure 12: Epochs for tasks 11 to 19 to reach 0.95 accuracy. Standard errors over five seeds14 of 22Transient frequencies are detours, not scaffolding. Suppressing them speeds grokking.References[1]A. Power, Y. Burda, H. Edwards, I. Babuschkin, and V. Misra, “Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets.” Accessed: Feb. 13, 2024. [Online]. Available: http://arxiv.org/abs/2201.02177[2]N. Nanda, L. Chan, T. Lieberum, J. Smith, and J. Steinhardt, “Progress Measures for Grokking via Mechanistic Interpretability.” Accessed: Dec. 16, 2023. [Online]. Available: http://arxiv.org/abs/2301.05217[3]J. Lee, B. G. Kang, K. Kim, and K. M. Lee, “Grokfast: Accelerated Grokking by Amplifying Slow Gradients.” Accessed: Jun. 09, 2024. [Online]. Available: http://arxiv.org/abs/2405.20233References17 of 22Hyperparametersrate𝜆wd𝑑lrheads110121325631044Table 1: Hyperparameters for our task18 of 22An earlier frequency count▶An earlier analysis counted strong frequencies▶The count rose from 0 to 18, then fell to 10▶That rule also flags noise and single digits▶Causal ablation replaces itFigure 13: Active neuron frequencies through training, one per row, from an earlier analysis19 of 22Gradients as a signalWrite the weights of a model as 𝜃 and the gradient of the loss at step 𝑡 as 𝑔(𝑡). Over training, 𝑔(𝑡) moves up and down like a stochastic signal, so it can be written in a Fourier basis. GrokFast [3] holds that the slowly varying frequencies drive grokking. Amplifying them relative to faster ones does accelerate it.20 of 22Discrete Fourier transformA function can be written as a sum of sines and cosines. The discrete Fourier transform does the same for a vector.21 of 22Singular value decompositionAn 𝑚×𝑛 matrix 𝑀 factors as 𝑈Σ𝑉∗. Here 𝑈 is an 𝑚×𝑚 unitary matrix, Σ is an 𝑚×𝑛 diagonal matrix, and 𝑉 is an 𝑛×𝑛 unitary matrix. Multiplying a vector by 𝑀 thus first rotates it by 𝑉∗, then scales it by Σ, then rotates it by 𝑈.22 of 22