Train a small GPT — the kind of model behind ChatGPT, only ~0.8 million parameters instead of a trillion — from scratch, right here in this tab. No server, no install. Watch the loss curve fall, then ask it to write you a sentence. Source ↗
You can sample while training is still running — this is the trick. The model is a single instance in a Web Worker; Generate runs a forward pass against the same weights training is mutating, between steps. Sample twice during a run to watch what the model has picked up.
Click any byte below to see what the model considered at that
position — the top-10 next-byte probabilities the
last forward pass produced, and the per-head attention
weights from the final transformer block (which earlier
bytes each head was looking at).
This is honest: it's the actual distribution that token was sampled
from, and the actual softmax weights from the last attention layer.
Nothing prettified. · marks bytes that are whitespace
or control characters.
computing…
python_ref/train.py path uses PyTorch with CUDA / Apple MPS
and runs on every core. A 10M model trains in ~24 s / 1k steps on an
M5 Pro — comfortable iteration speed.swiftshader) — see docs/notes.md §10.
Try it on your machine and watch tokens/sec.SharedArrayBuffer and worker threads. Open box.Full speed write-up: docs/performance.md ↗ · The journey of every lever — shipped, blocked, open, and why: the performance journey ↗
Runs the same matmul on the WebGPU compute kernel and the WASM kernel, checks they agree, and reports the speedup. Needs Chrome / Edge 113+.
In-browser is single-threaded WASM — comfortable up to ~1M params. For 5–25M+ (a few minutes on a laptop), run the Python reference where it uses your GPU (Apple MPS / CUDA).
git clone https://github.com/sarthakagrawal927/tinygpt
cd tinygpt
python -m venv python_ref/.venv && source python_ref/.venv/bin/activate
pip install -r python_ref/requirements.txt
# measure how fast your machine trains:
python python_ref/bench.py
# train a ~10.8M model on your own text:
python python_ref/train.py --model-config configs/model.small.json \
--data your-text.txt --out checkpoints/run
# generate from it:
python python_ref/sample.py --checkpoint checkpoints/run --prompt "Once "