← TinyGPT · docs · devlog · roadmap · speedup
source: docs/training_guide.md · view on GitHub ↗

Training guide

The --depth single knob (B18)

tinygpt train --depth N derives every pretrain hyperparameter from one number — architecture and the learning-rate / batch / step schedule — following the nanochat surface (karpathy/nanochat) and the Chinchilla compute-optimal corner (Hoffmann et al. 2022).

Any explicit flag (--max-lr, --steps, --batch, …) overrides the derived value, with a warning. The derivation lives in native-mac/Sources/TinyGPTModel/DepthDerivation.swift (deriveHP).

Derivation

quantityrule
nLayersN
dModel64 · N (head_dim 64, GPT-2/Llama shape)
nHeadsN
dMlp4 · dModel
params (non-embed)12 · L · d²
tokensregime · params — chinchilla = 20×, overtrained = 40×
peak_lr3e-3 · √(512/dModel), clamped to [1e-4, 6e-3]
batch (seqs)⌈32 · dModel / seqLen⌉
total_steps⌈tokens / (batch · seqLen)⌉

Derived table (chinchilla regime, seqLen 1024)

depthdModeldMlpparamspeak_lrbatchstepstokens
425610243.1M4.24e-387,68062.9M
12768307284.9M2.45e-32469,1201.70B
2415366144679M1.73e-348276,48013.6B
36230492162.29B1.41e-372622,08045.9B

--regime overtrained doubles tokens (and steps); architecture and peak_lr are unchanged. These are a documented approximation of nanochat’s curve, not a port of its exact constants — DepthDerivationTests pins the numbers.

Learning-rate schedules

--lr-schedule {cosine,wsd,constant} (default cosine; wsd is warmup-stable-decay). For WSD, --decay-shape {1-sqrt,cosine,linear} (B11) selects the decay-phase curve (default 1-sqrt, MiniCPM). --llrd γ (B15) adds layer-wise LR decay on the sft/dpo/finetune paths.