Sam Babichenko

Reading notes / Deep Learning Alchemy

Regularization and fine-tuning

From Lecture 10 of Stanford CS 312 Deep Learning Alchemy (Fall 2026), taught by Tatsunori Hashimoto and Suhas Kotha

slides assignment code

Least squares
nnnumber of training samples
ppnumber of features, which is also the number of parameters of the linear model
xxfeature vector of one sample, with pp isotropic Gaussian entries
yylabel of one sample, y=w⊤x+ϵy=w^\top x+\epsilon
wwtrue coefficient vector of the linear model, with Gaussian prior w∼N(0,τ2Ip)w\sim N(0,\tau^2I_p)
ϵ\epsilonlabel noise in y=w⊤x+ϵy=w^\top x+\epsilon, with variance σ2\sigma^2
XXn×pn\times p data matrix, one row per sample
w^\hat wridge estimate w^=(X⊤X+(σ2/τ2)Ip)−1X⊤y\hat w=(X^\top X+(\sigma^2/\tau^2)I_p)^{-1}X^\top y, the posterior mean of ww
τ2\tau^2prior variance of each coefficient; the ridge penalty is σ2/τ2\sigma^2/\tau^2
Recipes
DDnumber of seed tokens available for training (200M tokens of DCLM in the main experiments)
NNparameters per model (in billions in the fitted laws)
KKnumber of ensemble members, independently trained copies that differ only in random seed
HHevery training choice other than the data (parameter count, epochs, learning rate, weight decay)
A(D,H)\mathcal A(D,H)the model trained on DD tokens with choices HH (Kim et al. write AA)
LLvalidation loss, cross-entropy per token on the held-out set
LD∗L^*_Dbest loss reachable from DD tokens with unlimited compute, LD∗=min⁡HL(A(D,H))L^*_D=\min_HL(\mathcal A(D,H))
pip_iprobability that ensemble member ii gives a sequence xx
pensp_{\rm ens}the ensemble's probability of a sequence, pens(x)∝exp⁡(1K∑ilog⁡pi(x))p_{\rm ens}(x)\propto\exp\big(\tfrac1K\sum_i\log p_i(x)\big)
Scaling laws
L^(N)\hat L(N)fitted loss against parameter count, L^(N)=A/Nα+L∞\hat L(N)=A/N^{\alpha}+L_\infty
L(D)L(D)best loss against seed tokens, L(D)=A/Dα+L∞L(D)=A/D^{\alpha}+L_\infty
AAcoefficient of a fitted scaling law such as L^(N)=A/Nα+L∞\hat L(N)=A/N^{\alpha}+L_\infty (Kim et al. write ADA_D)
α\alphaexponent of a fitted scaling law such as L^(N)=A/Nα+L∞\hat L(N)=A/N^{\alpha}+L_\infty (Kim et al. write αD\alpha_D)
L∞L_\inftyasymptote of a fitted scaling law, the loss it approaches with unlimited parameters or data (Kim et al. write EDE_D)
D′D'number of tokens the standard recipe needs to match a better recipe's loss; D′/DD'/D is the data multiplier
A1A_1coefficient AA of the standard recipe's data scaling law L(D)=A/Dα+L∞L(D)=A/D^{\alpha}+L_\infty
A2A_2coefficient AA of the better recipe's data scaling law L(D)=A/Dα+L∞L(D)=A/D^{\alpha}+L_\infty
Transfer
DFD_Fnumber of Python characters used for fine-tuning
DTD_Teffective data transferred by pre-training, the extra Python a model of the same size trained from scratch would need to match the fine-tuned model, DT=kDF aN bD_T=kD_F^{\,a}N^{\,b}
kkcoefficient of the transfer law DT=kDF aN bD_T=kD_F^{\,a}N^{\,b} (1.9×1041.9\times10^4 from text to Python)
aaexponent of the fine-tuning data DFD_F in the transfer law DT=kDF aN bD_T=kD_F^{\,a}N^{\,b} (0.18 from text to Python; Hernandez et al. write α\alpha)
bbexponent of the parameter count NN in the transfer law DT=kDF aN bD_T=kD_F^{\,a}N^{\,b} (0.38 from text to Python; Hernandez et al. write β\beta)
fPTf_{\rm PT}pre-trained model read as a mixture of capabilities, fPT(y∣x)=∑iπi(x)fi(y∣x)f_{\rm PT}(y|x)=\sum_i\pi_i(x)f_i(y|x)
fif_icapability ii of the pre-trained model (coding, writing and so on), a conditional distribution fi(y∣x)f_i(y|x)
πi(x)\pi_i(x)weight of capability ii for input xx, the probability that xx calls for capability ii (the lecture writes αi(x)\alpha_i(x))
Constants
0.050.05coefficient AA of the regularized law L^200M(N)\hat L_{200\mathrm M}(N) at 200M tokens
1.021.02exponent α\alpha of the regularized law L^200M(N)\hat L_{200\mathrm M}(N) at 200M tokens
3.433.43asymptote L∞L_\infty of the regularized law at 200M tokens, the recipe's estimated best loss with unlimited compute
1.9×1041.9\times10^4coefficient kk of the transfer law from text to Python
0.180.18exponent aa of the fine-tuning data in the transfer law from text to Python
0.380.38exponent bb of the parameter count in the transfer law from text to Python

Context. Compute-optimal pre-training assumes an unlimited stream of fresh tokens. A the compute-optimal recipe of Hoffmann et al. (2022): for a fixed training budget, train on about 20 tokens per parameter. Reading note: Chinchilla scaling-style recipe uses about 20 tokens per parameter, inference-focused models stretch to roughly 2,000, and the course's d8 trains about 30M parameters on 600M tokens. Each token appears once, so training loss on a fresh batch is an unbiased estimate of test loss and overfitting cannot occur. That infinite-data regime is ending. Web text grows about 3% a year while pre-training compute grows four- to five-fold a year (Villalobos et al., 2024; Sevilla and Roldán, 2024). Specialized domains such as agent trajectories, DNA, robotics, prices, and personal data are small from the start. Lecture 10 of Stanford CS 312 (Hashimoto and Kotha, Fall 2026) asks how to train when data is fixed and compute is abundant. It covers regularized pre-training first, then pre-training on related data followed by fine-tuning.

With fixed data and ample compute, repeating epochs and scaling up the model both overfit under standard defaults. Tuning weight decay far above the usual 0.1, up to 32 times higher, restores clean power-law scaling in model size. Recipes can then be compared by their scaling-law asymptote, the loss approached at unlimited compute. By that metric, an ensemble of independently trained models beats a single larger model. Ensembles of larger models match the standard recipe's best loss with roughly a fifth of the data, and sequence-level distillation packs most of that gain back into one model. When related data is available, pre-training multiplies a small fine-tuning set by orders of magnitude. Schedule handoff, data replay, and pre-training breadth then govern how well transfer holds up.

Lessons from least squares. Linear regression y=w⊤x+ϵy=w^\top x+\epsilon with nn samples, pp with covariance equal to the identity, so every feature direction has the same variance Gaussian features, and noise variance σ2\sigma^2 gives two guiding principles, worked out further in the benign-overfitting notes. Past p=np=n, gradient descent from zero converges to the X⊤(XX⊤)−1yX^\top(XX^\top)^{-1}y, the coefficient vector of smallest Euclidean norm among those that fit every training label exactly. Reading notes: Double descent, Surprises in High-Dimensional Ridgeless Least Squares Interpolation. Its implicit bias pulls test error down again as pp grows, producing the second descent of test error that rises as the parameter count approaches the number of samples, where the fit just interpolates and its variance is largest, and falls again beyond it (Hastie et al., 2022). Reading note: Double descent. In a latent-variable model where pp features are noisy views of a low-dimensional signal, too few features underfit and too many fit the noise. Under a Gaussian prior w∼N(0,τ2Ip)w\sim N(0,\tau^2I_p), the posterior mean is ridge regression, w^=(X⊤X+(σ2/τ2)Ip)−1X⊤y\hat w=(X^\top X+(\sigma^2/\tau^2)I_p)^{-1}X^\top y for data matrix XX. Tuning the ridge penalty at each pp makes test error fall monotonically in pp (Nakkiran et al., 2021). The lecture carries both lessons to neural networks. Training may already bias models toward useful simplicity, and explicit regularization should be tuned until scaling turns monotone again.

Setting. The main pre-training experiments come from Kim et al. (2025), co-authored by the course instructors. They fix D=200D=200M tokens of DataComp for Language Models, a large filtered web-text corpus built for pre-training research web text with a 4M-token held-out validation set. On this pool they train Llama-style models of NN equal to 150M, 300M, 600M, and 1.4B parameters using AdamW, a cosine schedule decaying to zero, context length 4,096, and batches of 64 sequences. At 300M parameters, the model has 1.5 parameters per token, 30 times Chinchilla's ratio. Loss denotes validation cross-entropy per token. Collect every training choice besides the data (model size, epochs, learning rate, weight decay) into HH, and write A(D,H)\mathcal A(D,H) for the trained model. The goal is the best loss reachable from DD tokens with unlimited compute: LD∗=min⁡HL(A(D,H)).L^*_D=\min_H L(\mathcal A(D,H)). Assignment 6 runs the same program on d8 using a 30M-token pool of DNA from OpenGenome2, with a 19-token vocabulary, default 32 epochs, learning rate 0.003, and weight decay 3.2.

Repeating data and adding parameters both overfit. Under standard defaults, throwing compute at fixed data backfires. In Kim et al.'s figure for a 300M model at weight decay 0.1 and a tuned learning rate, validation loss drops from about 4.98 at 1 epoch to about 3.78 at 8 epochs. By 128 epochs it climbs back to about 4.96, even while training loss keeps falling. Scaling up the model with epochs and learning rate tuned at each size helps little. From 150M to 1.4B parameters, validation loss improves by less than 0.1, hitting its low of 3.75 at 600M while 1.4B does slightly worse. Overfitting with repeated epochs contradicts the data-constrained scaling law of Muennighoff et al. (2023), which predicts monotonically falling loss with epochs. Their study filtered out most overfitting runs before fitting its curve.

Heavy weight decay restores power-law scaling in model size. Jointly tuning learning rate, epochs, and weight decay by coordinate descent at each size changes scaling completely. Optimal weight decay climbs from 0.8 at 150M to 3.2 at 600M and 1.4B, up to 32 times the usual 0.1, while optimal epochs drop from 16 to 8. Validation loss then falls monotonically in NN (in billions) along a power law with an asymptote: L^(N)=ANα+L∞,L^200M(N)=0.05N1.02+3.43.\begin{aligned}\hat L(N)&=\frac{A}{N^{\alpha}}+L_\infty,\\\hat L_{200\mathrm M}(N)&=\frac{0.05}{N^{1.02}}+3.43.\end{aligned} The exponent near 1 far exceeds Chinchilla's 0.34 and matches the variance-limited regime of Bahri et al. (2021), where fixing one resource makes excess loss shrink inversely with the other. Because the curve is monotone, its asymptote L∞=3.43L_\infty=3.43 estimates the recipe's infinite-compute limit, varying by at most 0.02 across three seeds. Heavy decay also reshapes the loss curve: loss falls slowly at first and drops steeply near the end, so runs can be judged only at schedule completion. Smaller batches improve per-token loss down to 64 sequences, the hardware minimum. It remains open whether heavy weight decay acts mainly as a regularizer or sets optimization speed through the weight norm. On d8, experiments test this by plotting loss against the product of learning rate and weight decay and comparing against an optimizer wrapper that holds the norm of each weight matrix, and of its update, at a fixed value in place of weight decay (Wen et al., 2026). Reading note: Noisy quadratics and weight norms, which fixes weight norms without weight decay.

Independent ensembles reach a lower asymptote than larger models. Spending compute on multiple independent runs pushes the infinite-compute floor lower than regularizing one model. Train KK copies differing only in random seed (initialization and data order), and combine their sequence probabilities pi(x)p_i(x) by averaging log-probabilities and renormalizing: pens(x)∝exp⁡(1K∑i=1Klog⁡pi(x)).p_{\rm ens}(x)\propto\exp\Big(\frac1K\sum_{i=1}^K\log p_i(x)\Big). Count the ensemble as NKNK parameters to reflect its KK-fold inference cost. Excess loss again falls roughly as 1/K1/K, but toward a lower asymptote of 3.34 for 300M members as K→∞K\to\infty, below the single-model limit of 3.43. Three 300M models already beat 3.43, and two 300M models beat one 600M model. Either source of randomness alone, initialization or data order, captures most of the gain, with data order contributing slightly more.

Ensemble members should overfit more than the best single model. The best ensemble members are not the best standalone models. Halving each member's weight decay and doubling its epochs lets individual models overfit more, yet lowers the 300M ensemble's asymptote from 3.34 to 3.27. That rule held in every tested setting except one. Lecture 10 connects this to the multi-view picture of Allen-Zhu and Li (2023). When examples carry several predictive features and optimal prediction combines them all, a single model latches onto one view. Independent seeds capture different views, and averaging cancels their individual overfitting. Dropout cheaply imitates ensembling. Experiments on d8 test how much of the ensemble gain dropout recovers and whether the two compose.

Joint scaling and constant data-efficiency gains. Taking K→∞K\to\infty at each member size, fitting those limits as a power law in NN, and letting N→∞N\to\infty yields an estimated asymptote of 3.17.
Estimated best validation loss from 200M tokens of DCLM, by recipe (Kim et al., 2025)
RecipeLoss
Standard, best run3.75
Regularized, N→∞N\to\infty3.43
300M ensemble, K→∞K\to\infty3.27
Joint, K,N→∞K,N\to\infty3.17
To turn a loss drop into an equivalent data gain, find the token count D′D' where the standard recipe's data scaling law matches that loss and report the multiplier D′/DD'/D. At 200M tokens, the regularized recipe is worth 2.29 times as much data and the joint recipe 5.17 times. Without extrapolation, the best single 1.4B model is worth 2.09 times, and an ensemble of five 1.4B models 3.75 times. Across 200M, 400M, 800M, and 1.6B tokens, all three recipes fit L(D)=A/Dα+L∞L(D)=A/D^{\alpha}+L_\infty with α∈[0.23,0.24]\alpha\in[0.23,0.24] and L∞∈[1.89,1.96]L_\infty\in[1.89,1.96]. When two recipes share α\alpha and L∞L_\infty and differ only in coefficients A1A_1 (standard) and A2A_2 (improved), equating their losses gives a constant multiplier independent of DD: A1D′ α=A2Dα⟹ D′D=(A1A2)1/α.\begin{aligned}\frac{A_1}{D'^{\,\alpha}}&=\frac{A_2}{D^{\alpha}}\\\Longrightarrow\ \frac{D'}{D}&=\Big(\frac{A_1}{A_2}\Big)^{1/\alpha}.\end{aligned} Because α≈0.23\alpha\approx0.23 is small, a modest drop in AA amplifies sharply. Using A1/A2=1.30/0.88A_1/A_2=1.30/0.88 from Kim et al.'s Figure 8 legend gives a multiplier between 5 and 5.5 for α\alpha between 0.24 and 0.23 (computed here). Each fit rests on only four points, however, and the authors note that the fits are noisy.

Distillation compresses the ensemble, and self-distillation mimics it. Ensembles multiply inference cost by KK, so training a student on text sampled from a teacher model, in place of matching the teacher's per-token probabilities (Kim and Rush, 2016) packs their gain back into one model. Sample a large unprompted synthetic corpus from the teacher, then train a fresh student on a mix of real and synthetic tokens. Distilling an eight-member 300M ensemble (loss 3.32) into one 300M student reaches 3.36 at one-eighth the inference cost. That keeps 83% of the ensemble's gain over the best regularized 300M model (3.57), beats the regularized asymptote (3.43), and matches a four-member ensemble. Self-distillation, with the same architecture for teacher and student, also beats the teacher. A single 300M teacher at 3.71 produces a student at 3.43, ahead of both its teacher and the best regularized 300M model. Mixing in real data is essential: training on teacher samples alone degrades the student to 4.07, consistent with the loss of diversity and quality when models are trained repeatedly on text that models generated. Allen-Zhu and Li read self-distillation as an implicit ensemble of teacher and student. Kim et al. (2026) support that view, finding that ensembles of self-distilled students approach nearly the same limit as ensembles trained on real data alone (3.32 against 3.31). Self-distillation therefore does not compose with ensembling, which suggests the two deliver the same benefit.

Validation gains carry over to benchmarks and continued pre-training. Kim et al. evaluated PIQA, SciQ, and ARC Easy only after locking in every recipe on validation loss. Lower validation loss carried straight to accuracy. The best ensemble beat the best unregularized model by over 9 percentage points on average, and distilled 300M students outperformed every other 300M model. The same toolkit helps further next-token training of an already pre-trained model on a narrower corpus, here math web text of Llama 3.2 3B on MegaMath-Web-Pro restricted to 4B of its 73B tokens. Smaller batches and repeated epochs raised the GSM8K, MATH, and MathQA average from 30.59 under reference hyperparameters to 35.82, though weight decay did not help here. An ensemble of eight such models reached 40.58, surpassing the 39.23 of the reference recipe trained on all 73B tokens for a 17.5-fold data-efficiency gain.

Pre-training multiplies small fine-tuning sets. When related pre-training data exists, transfer amplifies a small target corpus sharply. Hernandez et al. (2021) pre-train transformers on English text, fine-tune on DFD_F characters of Python, and measure DTD_T: the extra Python that a model of the same size trained from scratch would need to match the fine-tuned model's loss DTD_T. In the small-DFD_F regime, DTD_T and the resulting data multiplier follow DT=k DF a N b,DF+DTDF≈k NbDF 1−a,\begin{aligned}D_T&=k\,D_F^{\,a}\,N^{\,b},\\\frac{D_F+D_T}{D_F}&\approx\frac{k\,N^{b}}{D_F^{\,1-a}},\end{aligned} with non-embedding parameters NN. From text to Python, k=1.9×104k=1.9\times10^4, a=0.18a=0.18, and b=0.38b=0.38. The multiplier peaks when fine-tuning data is scarce. In their Figure 1 example, a 40M model fine-tuned on 3×1053\times10^5 characters matches training from scratch on roughly 1,000 times as much Python. Because b≈2ab\approx2a, a 10-fold larger model is worth roughly 100 times more fine-tuning data. On a fixed small target set, from-scratch models plateau as NN grows, whereas pre-trained models keep improving at a gentler slope. Small models given abundant target data are the exception: pre-training leaves them worse than training from scratch, a failure the authors call ossification.

Why transfer works and how stronger base models learn faster. One conceptual picture writes a pre-trained model as a mixture fPT(y∣x)=∑iπi(x)fi(y∣x)f_{\rm PT}(y|x)=\sum_i\pi_i(x)f_i(y|x) of capabilities fif_i such as coding and writing, weighted by the probability πi(x)\pi_i(x) that input xx invokes capability ii. Identifying the weights πi\pi_i takes far fewer samples than learning a capability from scratch. In-context learning can be read as estimating those weights by Bayesian inference over tasks (Xie et al., 2021), and fine-tuning as adjusting them by gradient descent while keeping the other capabilities intact. Recent 2026 studies show that stronger base models also extract more from target data. To match retrieval-augmented generation on a reading-comprehension benchmark using synthetic document rewrites, a 14B Qwen3 model needs 102 times the original text against 813 times for a 1.7B model (Han et al., 2026). In chess, the reward gain per tenfold increase in RL compute grows with the number of pre-training tokens (Shen et al., 2026).

Schedule handoff, optimizer choice, and replay during fine-tuning. How pre-training ends governs how smoothly a model adapts. Under a decaying learning rate, most loss reduction happens during the decay phase. Sharing one decaying schedule across pre-training and fine-tuning would starve fine-tuning of step size, so the cleaner handoff uses a a schedule with a short warmup, a long constant phase and a final decay to zero. Reading note: Learning-rate schedules and batch size schedule and runs its final decay on the target data. Because released checkpoints are already decayed and lack optimizer state, practitioners warm the learning rate back up. Pre-training loss alone also fails to predict transfer cleanly. Watts et al. (2026) find that flatter solutions from higher peak pre-training learning rates fine-tune with less forgetting even when pre-training loss is worse. Li et al. (2026) find that past a large enough pre-training data budget, an optimizer that replaces each weight matrix's momentum by the nearest matrix with all singular values equal to 1, UV⊤UV^\top for momentum UΣV⊤U\Sigma V^\top. Reading note: Muon beats AdamW in pre-training loss yet finishes worse after fine-tuning. Replay largely prevents catastrophic forgetting. In Marek et al. (2026), a 2M-parameter transformer trained sequentially on addition, reversal, sorting, and modular addition forgets prior tasks without replay. Mixing in samples generated by the current model keeps all four intact. Once replay is used, residual forgetting tracks capacity. Small models saturated by many tokens per parameter overwrite old knowledge when absorbing new data, whereas larger models trained at lower token-to-parameter ratios adapt more easily.

Out-of-distribution robustness comes from diverse pre-training. Across many models and interventions, shifted test accuracy is closely linear in in-distribution accuracy on a Φ−1(accuracy)\Phi^{-1}(\text{accuracy}), the inverse of the standard normal distribution function Φ\Phi applied to an accuracy, which stretches accuracies near 0 and 1 apart scale (Recht et al., 2019; Miller et al., 2021). Most techniques therefore lift both accuracies along one fixed line. Pre-training breaks that line. On iWildCam, a benchmark of camera-trap photos from unseen locations scored by macro F1, ImageNet-pretrained models sit on a separate, steeper line. At the scores they reach, they beat what the from-scratch line predicts out of distribution. Across broad comparisons of robustness methods, pre-training on more diverse data remains the most reliable lever (Fang et al., 2022).

Limits. The data-constrained pre-training results come from one corpus, one recipe, and one group's runs, mostly at 200M tokens. Each asymptote extrapolates from four or five points, and the data scaling laws from four asymptotes. The 1.4B model also used fewer layers than the 600M model (16 versus 24), a framework preset that the authors suggest may have aggravated its overfitting. Ensembles multiply inference compute by KK unless distilled.

Terms

LD∗L^*_D
min⁡HL(A(D,H))\min_HL(\mathcal A(D,H)): the best loss reachable from DD tokens with unlimited compute
standard recipe
more epochs and more parameters at weight decay 0.1; both eventually overfit
regularized recipe
learning rate, epochs and weight decay tuned jointly per size; best weight decay 0.8 to 3.2; loss 0.05/N1.02+3.430.05/N^{1.02}+3.43
asymptote as a metric
compare monotone recipes by L∞L_\infty of their scaling law, not at one compute budget
ensemble
average log-probabilities of KK seeds; excess loss about 1/K1/K; lower asymptote than N→∞N\to\infty
member settings
half the weight decay and twice the epochs of the best single model
data efficiency
D′/DD'/D, the extra data the standard recipe needs; (A1/A2)1/α(A_1/A_2)^{1/\alpha} when α,L∞\alpha,L_\infty agree
sequence-level distillation
train a student on teacher samples mixed with the real data; 8-ensemble into one 300M model keeps 83% of the gain
self-distillation
student of the teacher's size beats it, if real data is mixed in; same benefit as ensembling
effective data transferred
DT=k DF aN bD_T=k\,D_F^{\,a}N^{\,b}; multiplier kNb/DF1−akN^b/D_F^{1-a} shrinks as DFD_F grows
ossification
pre-training that hurts a small model when target data is plentiful
replay
mixing old (or self-generated) data into fine-tuning; largely prevents forgetting
accuracy on the line
shifted-set accuracy is about linear in original accuracy (probit scale); pre-training changes the line

Sources

Lecture 10, “Generalization 1: Regularization and fine-tuning” (Nov 12, 2026), of Stanford CS 312 Deep Learning Alchemy, Fall 2026. Taught by Tatsunori Hashimoto and Suhas Kotha; course staff Kaiyue Wen and Tristan Thrush (CAs).

Course site Lecture slides Assignment Assignment code

The lessons, experiments, figures and quiz problems in this note are the course's, shown here with the instructors' permission.

Connected notes

Threads