Sam Babichenko

Reading notes / Deep Learning Alchemy

Prediction as understanding: the d8 model organism

From Lecture 1 and LLMs 101 (supplementary session) of Stanford CS 312 Deep Learning Alchemy (Fall 2026), taught by Tatsunori Hashimoto and Suhas Kotha

slides assignment code LLMs 101 slides LLMs 101 handout

Objective and data
x=(x1,…,xT)x=(x_1,\dots,x_T)a training row, a sequence of T=1024T=1024 tokens cut from the concatenated web text
VVvocabulary size, the number of distinct tokens (4096)
pθp_\thetathe model's next-token distribution, pθ(xt+1∣x≤t)p_\theta(x_{t+1}\mid x_{\le t}), the probability it gives each possible next token after the prefix x≤tx_{\le t}
θ\thetathe model's parameters, all of its weights (about 35M for d8)
L(θ)L(\theta)cross-entropy per prediction target in nats, the mean of −ln⁡pθ(xt+1∣x≤t)-\ln p_\theta(x_{t+1}\mid x_{\le t}) over a row's 1023 targets (about 2.93 at the end of a d8 run)
Model
kknumber of blocks of the ladder model dkk (8 for d8)
ddwidth, the length of each token's vector in the residual stream, d=64kd=64k on the ladder (512 for d8)
HHnumber of attention heads per block, kk on the ladder (8 for d8)
dhd_hhead width, the length of each head's query, key and value vectors (64)
dffd_{ff}MLP inner width, the length of the SwiGLU MLP's inner vector, 3.5d3.5d (1792 for d8)
NNnon-embedding parameters, the attention and MLP weights of all blocks, 14.5 k d214.5\,k\,d^2 (30.4M for d8)
dind_{in}input width of a weight matrix, the length of the vectors it multiplies (dd for most matrices, dffd_{ff} for W2W_2)
AAthe standard normal V×dV\times d table both embeddings start from, A/dA/d for the input embedding and A⊤/dA^\top/\sqrt d for the output matrix
hℓh_\ellinput of block ℓ\ell, the residual stream as block ℓ\ell reads it
uℓu_\ellsum of the attention and MLP outputs of block ℓ\ell, so the default block computes hℓ+1=hℓ+uℓh_{\ell+1}=h_\ell+u_\ell
Optimizer
η\etapeak learning rate (0.003), reached at the end of warmup
ηs\eta_slearning rate at step ss, rising linearly from 0 to η\eta over the first 1% of steps, then falling linearly to 0
λ\lambdaweight-decay coefficient (0.1), so each step multiplies a decayed matrix by 1−ηsλ1-\eta_s\lambda
β1,β2\beta_1,\beta_2Adam's averaging coefficients (0.9, 0.95), the weight each running average keeps on its old value at every step, β1\beta_1 for the gradient and β2\beta_2 for its square
ϵ\epsilonsmall constant added to Adam's denominator, 10−810^{-8}, which keeps the division safe when v^s\sqrt{\hat v_s} is near zero
m^s\hat m_sbias-corrected running average of the gradient at step ss, ms/(1−β1s)m_s/(1-\beta_1^s) with ms=β1ms−1+(1−β1)gsm_s=\beta_1m_{s-1}+(1-\beta_1)g_s and m0=0m_0=0. Adam moves each weight along it
v^s\hat v_sbias-corrected running average of the squared gradient at step ss, coordinate by coordinate, vs/(1−β2s)v_s/(1-\beta_2^s) with vs=β2vs−1+(1−β2)gs2v_s=\beta_2v_{s-1}+(1-\beta_2)g_s^2 and v0=0v_0=0. Adam divides by v^s\sqrt{\hat v_s}, so a weight whose gradient keeps a steady size and sign moves by about ηs\eta_s whatever its gradient's scale
BBbatch size, 64 rows (65,536 tokens) per step
SSnumber of optimizer steps, 600,000 rows divided by BB (9,375)

Context. Deep learning runs modern language models, self-driving stacks, protein-structure predictors, and Go engines. Yet no general theory predicts what a change to a training run will do. Classical intuition often misleads. The U-shaped expected squared test error split into bias squared, variance, and irreducible noise; classically U-shaped in model capacity as bias falls and variance rises gave way to test error peaking near the interpolation threshold (where the model just fits the training data exactly) and falling again at larger capacity (Belkin et al., 2019). Reading note: Double descent. Lecture 1 of Hashimoto and Kotha's Stanford course CS 312 (Deep Learning Alchemy) opens with data-limited pre-training runs from Kim et al. (2025). In those runs, loss stops improving with model size until weight decay is tuned, and then follows a clean power law. This note covers Lecture 1 and the supplementary LLMs 101 session and handout, which set out the course's training setup.

In the course's view, understanding a training phenomenon means predicting an experiment's outcome before running it. Students build that skill by running many experiments on one small, fully specified model organism called an 8-block, width-512 transformer with about 35M parameters, pre-trained on 614.4M tokens of web text. The opening d8 experiments already yield two lessons that carry beyond this setup. First, an architecture ablation means little at one shared learning rate. Removing pre-norm diverges at the default rate. At a lower rate, it trains nearly as well as removing RoPE and changes the ranking of five ablations. Second, d8's final loss varies by about 0.003 across random seeds. Smaller gaps, such as the one from averaging two earlier block inputs in the skip path, cannot be read off a single run of each variant.

Lecture 1 grounds this predictive stance in science, where theories earn credit through predictions, and in next-token prediction itself. The targets are validation loss and internal statistics such as activation, gradient, and parameter norms. Most of the course studies training a model from scratch to predict the next token of a large text corpus for three reasons. Validation loss predicts downstream usefulness with little noise, L≈aN−b+cL\approx aN^{-b}+c: empirical fits of final loss against model size NN, data, or compute used to extrapolate from small runs to large ones. Reading notes: Chinchilla scaling, Hyperparameters, scaling, noise and debugging let small runs stand in for large ones, and every run starts from scratch with no inherited state.

The default recipe: objective and data. Write a training row as tokens x=(x1,…,xT)x=(x_1,\dots,x_T) of length T=1024T=1024, drawn from a vocabulary of V=4096V=4096 subwords. The autoregressive model pθp_\theta predicts each token from the prefix before it, giving T−1=1023T-1=1023 targets per row. The objective is cross-entropy per target in −ln⁡p-\ln p: natural-log loss units, where one nat equals 1/ln⁡2≈1.441/\ln 2\approx1.44 bits, the mean negative log-probability of each true next token:L(θ)=−1T−1 Ex[∑t=1T−1ln⁡pθ(xt+1∣x≤t)].\begin{aligned}L(\theta)&=-\frac{1}{T-1}\,\mathbb E_x\\&\quad\Big[\sum_{t=1}^{T-1}\ln p_\theta(x_{t+1}\mid x_{\le t})\Big].\end{aligned}Training uses each position tt conditions on the true prefix x≤tx_{\le t} rather than the model's own predictions, so all 1,023 targets in a row compute in parallel. The corpus is DataComp for Language Models, a filtered corpus of web text web text, tokenized with a subword tokenizer trained on raw text to a fixed vocabulary (here V=4096V=4096) (Kudo and Richardson, 2018), concatenated, and sliced into 1,024-token rows that can cross document boundaries. A default run makes one pass over 600,000 rows (614.4M tokens) and evaluates on 1,000 fixed held-out rows. It finishes near 2.93 nats, a eLe^{L}: the number of equally likely tokens that would give the same loss of about 19.

Architecture. d8 is a Llama-style a single stack of transformer blocks with no encoder or cross-attention; here attention is causal (position tt attends only to positions ≤t\le t), whereas a prefix LM lets the prompt attend bidirectionally (Raffel et al., 2020) transformer. An a learned V×dV\times d matrix (4096×5124096\times512) that maps each vocabulary token to its row vector maps each token to a vector of the length dd of each token's vector in the residual stream (512 for d8); attention matrices are d×dd\times d, MLP matrices are d×dffd\times d_{ff} or dff×dd_{ff}\times d, and embedding tables are V×dV\times d d=512d=512. Eight h←h+F(norm(h))h\leftarrow h+F(\mathrm{norm}(h)): each branch reads a normalized copy of the residual stream and adds its output back, leaving the skip path unnormalized. Reading note: Signal propagation in depth blocks with γ⊙y/d−1∑iyi2+10−5\gamma\odot y/\sqrt{d^{-1}\sum_iy_i^2+10^{-5}} with learned per-coordinate scale γ\gamma; unlike LayerNorm it drops mean subtraction and bias on the hypothesis that rescaling alone steadies training, matching LayerNorm at lower cost (Zhang and Sennrich, 2019) each add an attention branch and an MLP branch to the h←h+Attn(norm(h))h\leftarrow h+\mathrm{Attn}(\mathrm{norm}(h)), then h←h+MLP(norm(h))h\leftarrow h+\mathrm{MLP}(\mathrm{norm}(h)): the dd-dimensional vector carried from block to block by skip connections (named after ResNets, He et al., 2016); each branch adds to it rather than overwriting it, and it is the thick line in the figure below. Reading note: A Mathematical Framework for Transformer Circuits. A final norm and an output matrix then produce the next-token logits. Attention uses H=8H=8 heads of width dh=64d_h=64 with rotary position embeddings: pairs of query and key coordinates rotated by angles proportional to token position so dot products depend on relative offset and RMSNorm applied to each head's query and key vectors after RoPE and before their dot product, preventing score growth with incoming vector size while learned scales preserve adaptability. Reading note: Small-scale proxies for large-scale Transformer training instabilities. The MLP is MLP(y)=W2(SiLU(W1y)⊙W3y)\mathrm{MLP}(y)=W_2\big(\mathrm{SiLU}(W_1y)\odot W_3y\big) with SiLU(z)=z/(1+e−z)\mathrm{SiLU}(z)=z/(1+e^{-z}), W1,W3∈Rdff×dW_1,W_3\in\mathbb R^{d_{ff}\times d}, and W2∈Rd×dffW_2\in\mathbb R^{d\times d_{ff}} (Shazeer, 2020) with inner width dff=1792d_{ff}=1792 (3.5d3.5d). The architecture omits biases and dropout, and keeps the input and output embeddings separate. Each block holds four d×dd\times d matrices (query, key, value, output), about 1.05M parameters; each head uses a dhd_h-wide slice with Hdh=dHd_h=d attention weights and three matrices W1,W3,W2W_1,W_3,W_2 of size d×dffd\times d_{ff} or dff×dd_{ff}\times d, about 2.75M parameters MLP weights. Across all eight blocks, non-embedding parameters total 8(4d2+10.5d2)=30,408,7048(4d^2+10.5d^2)=30{,}408{,}704 attention and MLP weights across all eight blocks, excluding norm scales, alongside 2⋅V⋅d=2⋅4096⋅512≈4.192\cdot V\cdot d=2\cdot4096\cdot512\approx4.19M across the separate input embedding and output matrices in the two embedding tables.

Initialization. Every weight matrix starts from a normal distribution with standard deviation 1/din1/\sqrt{d_{in}}, normal draws conditioned to lie in ±3/din\pm3/\sqrt{d_{in}}, cutting off about 0.3% of draws and shrinking the standard deviation slightly (by about 1.3%, computed here); the handout notes the shrinkage without giving a reason, though truncation is usually used to rule out outsized starting weights, where dind_{in} is its input width. Scaling by 1/din1/\sqrt{d_{in}} keeps for independent weights of variance 1/din1/d_{in}, each output ∑j=1dinwjyj\sum_{j=1}^{d_{in}}w_jy_j has variance din−1∑jyj2d_{in}^{-1}\sum_jy_j^2, matching the input's mean square at any width; the handout presents this as a scale argument only, with no guarantee about training dynamics at any width. Both embedding tables come from one standard normal table A∈RV×dA\in\mathbb R^{V\times d}. The input embedding is entries of size 1/d≈0.0021/d\approx0.002; the course gives no reason for this scale, but it starts token vectors far smaller than block outputs so Adam's steps (up to η=0.003\eta=0.003) quickly learn the embedding almost from scratch, and the output matrix is entries of size 1/d1/\sqrt d, so initial logits have size about 1 and starting loss sits about half a nat above ln⁡4096≈8.3\ln 4096\approx8.3 nats (computed here). The two tables therefore start aligned in direction, though the course does not explain why.

The scaling ladder. Larger and smaller models come from one preset family. Model preset with kk blocks, width d=64kd=64k, kk heads of width 64, and MLP inner width 3.5d3.5d. Reading note: Hyperparameters, scaling, noise and debugging has kk blocks, kk attention heads, and width d=64kd=64k, so depth and width grow together at a d/k=64d/k=64 for every preset (called a convention in the handout); Lecture 9 reports Kaplan et al.'s (2020) finding that at fixed parameter count, varying this ratio by a factor of 40 changes the loss only slightly. Reading note: Depth, width and expressivity. Each block holds 14.5 d214.5\,d^2 weights with d∝kd\propto k, so non-embedding parameters N=14.5 k d2N=14.5\,k\,d^2 scale as k3k^3. That gives about 3.8M for d4, 30.4M for d8, and 243M for d16. Switching presets changes nothing else. Learning rate, batch size, token count, and step count all the course gives no reason for holding them fixed; Lecture 2 shows the optimal learning rate shifts with model size and Lecture 4 derives width-scaling rules, and with fixed tokens a larger preset sees fewer tokens per parameter (about 20 for d8 vs. 2.5 for d16). Reading notes: Hyperparameters, scaling, noise and debugging, Parametrization across width and depth.

Optimization. Training uses θs+1=(1−ηsλ)θs−ηsm^s/(v^s+ϵ)\theta_{s+1}=(1-\eta_s\lambda)\theta_s-\eta_s\hat m_s/(\sqrt{\hat v_s}+\epsilon): Adam with decoupled weight decay, where decay shrinks weights directly instead of passing through the gradient averages (Loshchilov and Hutter, 2019). Reading note: Noisy quadratics and weight norms with β1=0.9\beta_1=0.9, β2=0.95\beta_2=0.95, and ϵ=10−8\epsilon=10^{-8}. Each batch holds B=64B=64 rows (65,536 tokens), so one pass over 600,000 rows takes S=9,375S=9{,}375 steps. The learning rate ηs\eta_s rises linearly from zero over the first 1% of steps (93 steps of an opening phase where the learning rate ramps linearly from zero to its peak. Reading note: Hyperparameters, scaling, noise and debugging) to a peak η=0.003\eta=0.003, then decays linearly back to zero. Decoupled weight decay λ=0.1\lambda=0.1 applies to attention, MLP, and output matrices, excluding embeddings and norm scales. Write m^s\hat m_s and v^s\hat v_s for Adam's m^s=ms/(1−β1s)\hat m_s=m_s/(1-\beta_1^s) and v^s=vs/(1−β2s)\hat v_s=v_s/(1-\beta_2^s), where ms=β1ms−1+(1−β1)gsm_s=\beta_1m_{s-1}+(1-\beta_1)g_s and vs=β2vs−1+(1−β2)gs2v_s=\beta_2v_{s-1}+(1-\beta_2)g_s^2 start from 0 (coordinatewise squares); dividing by 1−βs1-\beta^s corrects the zero-start pull over the first ~50-100 steps. A weight whose gradient keeps a steady size and sign has m^s/v^s≈±1\hat m_s/\sqrt{\hat v_s}\approx\pm1 and moves by about ηs\eta_s, while sign-flipping gradients average down of the gradient and its coordinatewise square. Each decayed matrix updates asθs+1=(1−ηsλ) θs−ηsm^sv^s+ϵ.\begin{aligned}\theta_{s+1}&=(1-\eta_s\lambda)\,\theta_s\\&\quad-\eta_s\frac{\hat m_s}{\sqrt{\hat v_s}+\epsilon}.\end{aligned}Because each step shrinks decayed weights by a fraction ηsλ\eta_s\lambda, weight decay fades to zero alongside the learning rate. Before each update, gradient clipping caps the global gradient norm across all parameters at 1. Weights and optimizer state stay in fp32 while matrix products run in bf16. One d8 run takes 10 to 15 minutes on a single H100 GPU, costing about fifty cents of rented compute.

How the course tests prediction. Each quiz problem supplies a a patch to the course codebase that completely specifies the modified runs and asks for a measured outcome, such as a loss gap, a ratio bin, or a ranking. Staff settle the answer by running the experiment. Assignment 1 lays out five rules for clean experiments. Change one thing at a time, use the smallest scale that shows the effect, and measure run-to-run variation. Sweep across a range of settings instead of comparing two points, and match parallel runs to available compute.

Learning-rate sensitivity. A peak learning rate within a factor of 3 of the optimum costs little on d8. The default 0.003 wins across six peak rates from 10−410^{-4} to 3⋅10−23\cdot10^{-2}, spaced roughly by factors of 3. Moving a factor of 3 either way adds only 0.03 to 0.05 in final loss. The basin is lopsided. A rate ten times too small costs 0.22, while a rate ten times too large costs 0.09. Low-rate loss curves are still falling steeply when the fixed 9,375 steps expire; high-rate runs train stably and finish only moderately worse. A rate tuned for one model is therefore a reasonable starting guess for a nearby variant.

Ablations must be compared at each variant's own learning rate. Six variants of d8 are trained across peak rates {3⋅10−4,10−3,3⋅10−3,10−2,3⋅10−2}\{3\cdot10^{-4},10^{-3},3\cdot10^{-3},10^{-2},3\cdot10^{-2}\} and ranked by their best final loss. Removing pre-norm replaces the block-input norms with identities, while dropping the skip additions so each block computes h←MLP(norm(Attn(norm(h))))h\leftarrow\mathrm{MLP}(\mathrm{norm}(\mathrm{Attn}(\mathrm{norm}(h)))), turning d8 into a plain 16-layer chain. Reading note: Signal propagation in depth turns each block into a plain chain of normalized attention and normalized MLP:
Final loss of the six d8 variants, in order of their best loss (Lecture 1)
VariantAt the default rateAt its best rate
A, the baseline2.92672.9267
F, without RoPE3.06713.0671
B, without pre-normnot finite3.0766 at 10−310^{-3}
D, without the MLP branches3.21993.2199
E, without the attention branches4.86414.8641
C, without residuals (skip connections)6.87476.8745 at 0.03
At the shared default rate, B ranks last. Tuned to its own rate (10−310^{-3}), it lands within 0.01 of F and rises to third. The instructors' own single-rate check missed that removing pre-norm fails only at the default rate and above. Each remaining gap reflects a direct structural cause. Without attention, positions never mix and the model collapses to a bigram predictor. Without residuals, the eight-block stack never trains and stalls near 6.9 after the first hundred steps. Without RoPE, the causal mask still supplies enough position information to lose only 0.14.

The residual path tolerates large changes. Write hℓh_\ell for the input to block ℓ\ell and uℓu_\ell for the sum of its attention and MLP outputs, so the default block computes hℓ+1=hℓ+uℓh_{\ell+1}=h_\ell+u_\ell. At the default rate, halving the skip term hℓh_\ell hurts substantially, raising loss from 2.9267 to 3.2269. Doubling hℓh_\ell, or adding Gaussian noise of standard deviation 0.1 or 1 to the skip path, costs at most 0.04 at the default rate. At rate 0.03, all three match or beat the baseline. A mixed skip averages the two previous block inputs:hℓ+1=12hℓ+12hℓ−1+uℓ(ℓ≥2).h_{\ell+1}=\tfrac12h_\ell+\tfrac12h_{\ell-1}+u_\ell\quad(\ell\ge2).Block 1 stays unchanged, and gradients flow through both skip inputs. Across all six rates, this variant lands within 0.01 of the default. Its best loss differs by 2.9257−2.9267=−0.00102.9257-2.9267=-0.0010. That gap is about a third of d8's seed-to-seed standard deviation (0.0029 over ten seeds), so a single pair of runs cannot separate the two architectures.

Limits. The d8 setup is narrow, using about 35M parameters, one corpus, 9,375 steps, and language alone. The course plans a later switch to another modality, such as DNA. Assignment 1 warns that lessons from d8 are far from universal and will often disagree with published results, yet asks students to master d8 anyway. The experimental habit transfers to any domain, and d8 intuitions give a rough first guess when no better evidence exists. Because the comparisons above come from single runs, gaps under about 0.003 fall inside seed noise.

Terms

prediction as understanding
the course's stance: understanding a phenomenon means predicting an experiment's outcome before running it
d8
8 pre-norm blocks, width 512, 8 heads of 64, RoPE, QK-norm, SwiGLU (1792), untied embeddings; about 35M parameters
default data
DCLM web text, 4,096-token vocabulary, rows of 1,024 tokens, 600,000 rows (614.4M tokens), one pass
default optimizer
AdamW (0.9, 0.95), peak 0.003, 1% warmup, linear decay to 0, weight decay 0.1 on matrices, clip at 1, 64 rows per step, 9,375 steps
L(θ)L(\theta)
mean next-token negative log-probability per target, in nats; about 2.93 for default d8
ladder dkk
width 64k64k, kk heads, N=14.5 k d2∝k3N=14.5\,k\,d^2\propto k^3; hyperparameters unchanged
decoupled decay
θ←(1−ηsλ)θ−ηsm^s/(v^s+ϵ)\theta\leftarrow(1-\eta_s\lambda)\theta-\eta_s\hat m_s/(\sqrt{\hat v_s}+\epsilon): the decay fades with the schedule
learning-rate basin
best 0.003; a factor 3 off costs 0.03 to 0.05; 10 times too small 0.22, 10 times too large 0.09
ablation ranking
A < F < B < D < E < C with each variant at its own rate; without pre-norm the run diverges at 0.003
mixed skip
hℓ+1=12hℓ+12hℓ−1+uℓh_{\ell+1}=\tfrac12h_\ell+\tfrac12h_{\ell-1}+u_\ell: −0.0010-0.0010, a third of the seed-to-seed standard deviation

Sources

Lecture 1, “Introduction: prediction as understanding, the pre-training setting, the d8 model organism” (Sep 22, 2026), and LLMs 101 (supplementary session), Sep 23, 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 LLMs 101 slides LLMs 101 handout

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

Connected notes

  • Linear attention's state is a running sum of key-value products that never forgets. Of Mamba-2's components added one at a time to a 300M model, a data-dependent decay of that sum and a short convolution carry nearly all the gain. Test loss goes from 3.13 to 2.88 with the decay alone, 2.93 with the convolution alone and 2.77 with both, while the other components move it by 0.07 or less.

  • With effects θi\theta_i spread around a common mean, the posterior mean pulls each raw estimate toward that mean, and Lindley's version of James-Stein estimates both the mean and the amount of pulling from the spread of the estimates themselves. It beats the raw estimates in total squared error for every configuration of the θi\theta_i once there are four or more, and in Efron's batting example it cuts the total prediction error to 0.28 of that of the raw batting averages.

  • PreNorm's unweighted running sum grows with depth and dilutes every earlier output, so Attention Residuals replace it with softmax-weighted averages over earlier block sums, bounding the mixed input by max⁡jRMS(vj)\max_j\mathrm{RMS}(v_j) while keeping direct shortcuts across depth without the matrix-product instability of multi-stream mixing.

  • To name the better of two Gaussian arms with error at most δ\delta, sample arm 1 on the fraction σ1/(σ1+σ2)\sigma_1/(\sigma_1+\sigma_2) of rounds, which minimizes the variance of the difference of means, and stop once that difference exceeds 2β(t,δ)\sqrt{2\beta(t,\delta)} standard deviations; equal sampling costs up to twice as many samples, and with equal variances the rule is Robbins' sequential test.

Threads