You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5f92e69
Browse filesBrowse the repository at this point in the historyBrowse files
Train the GPT with nanoGPT's AdamW behind --optimizer adamw
SGD at a fixed learning rate stays the default. With --optimizer adamw, a
step stores each parameter table's gradient as a table (one backward pass
for all of them), then updates each table with one SQL statement:
gradients clipped to a global norm of 1, Adam's moments as columns beside
the weights, weight decay on all but the layer norms, and the learning rate
read from a schedule(step, lr) table with nanoGPT's warmup and cosine
decay, stretched to --steps. The JAX reference step matches
torch.optim.AdamW after clip_grad_norm_ exactly, and the SQL matches it to
6e-15 after each of five steps.
Also say in the attention demo that its three grad() calls share one
backward pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h
Copy file name to clipboardExpand all lines: benchmarks/ml/README.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ array programs.
18
18
| # | Script | Model | What it measures |
19
19
|---|---|---|---|
20
20
| 01 |[`01_attention.py`](01_attention.py)| causal softmax attention, the core of a transformer, in einfold's window and `GROUP BY` spellings | the naive plan, which stores every score, for [FlashAttention](https://arxiv.org/abs/2205.14135)'s tiled plan to beat; gradients with respect to Q, K and V; masked pairs as absent rows; a control that isn't attention, the Nadaraya–Watson kernel average |
21
-
| 02 |[`02_nanogpt.py`](02_nanogpt.py)|[nanoGPT](https://github.com/karpathy/nanoGPT)'s GPT-2 model, at 1 layer and 4,416 parameters, on Tiny Shakespeare | the loss on each host; SGD training steps, every parameter table checked after every step |
21
+
| 02 |[`02_nanogpt.py`](02_nanogpt.py)|[nanoGPT](https://github.com/karpathy/nanoGPT)'s GPT-2 model, at 1 layer and 4,416 parameters, on Tiny Shakespeare | the loss on each host; training steps with SGD or, as nanoGPT trains, AdamW, every parameter table checked after every step |
22
22
| 03 |[`03_graphcast.py`](03_graphcast.py)| a miniature [GraphCast](https://arxiv.org/abs/2212.12794), DeepMind's graph neural network for weather forecasting, over [ERA5](https://www.ecmwf.int/en/forecasts/dataset/ecmwf-reanalysis-v5) reanalysis in Zarr | a global against a regional forecast; the gradient of the forecast error; the receptive field of a region |
23
23
24
24
The SQL favors legibility over speed. Each model reads like its definition,
@@ -48,7 +48,8 @@ options are the same in all three:
48
48
--csv results.csv # also write the results table
49
49
```
50
50
51
-
Demo 2 adds `--steps`, the number of training steps. Demo 3 adds
51
+
Demo 2 adds `--steps`, the number of training steps, and `--optimizer`:
52
+
`sgd` (the default), or `adamw` to train as nanoGPT does. Demo 3 adds
52
53
`--rounds`, the number of processor rounds.
53
54
54
55
The output ends with one table: a row per step, host and size, with its
@@ -105,7 +106,10 @@ with DataFusion 54.0.0, DuckDB 1.5.5 and ddxdb 0.3.0, one repetition each.
105
106
respect to Q, K and V, in both spellings, match `jax.grad` to 3e-15 of the
106
107
largest value at every size. After each of five SGD steps, all eleven of
107
108
the GPT's parameter tables match JAX's to 1e-15, and the loss falls from
108
-
4.18 to 3.84 (each step on a different batch).
109
+
4.18 to 3.84 (each step on a different batch). With AdamW, the weights
110
+
and both of Adam's moments match a JAX transcription of
111
+
`torch.optim.AdamW` to 6e-15 after each of five steps, and that
112
+
transcription matches PyTorch exactly.
109
113
110
114
**DataFusion computes a CTE once for every place that reads it.** A
111
115
model reads its activations more than once: a layer norm reads its input
@@ -165,7 +169,7 @@ SQL gives a number.
165
169
- Part B of the NanoGPT demo: the four tricks behind a record of the
166
170
[NanoGPT speedrun](https://github.com/KellerJordan/modded-nanogpt), a
167
171
public race to train GPT-2 fastest, as a small diff to `02_nanogpt.py`.
168
-
It needs nanoGPT's optimizer, AdamW, with its state as versioned tables.
172
+
Its sparse optimizer updates build on `--optimizer adamw`.
169
173
- Peak memory per host, from a fresh process per measurement.
0 commit comments