Pretrain a small LLM on one 8 GB GPU: the Lyra recipe
10 steps · about 10 h 45 min · Intermediate
- Let's build GPT: from scratch, in code, spelled out. (video, Andrej Karpathy (YouTube), 2 h)
Start by learning what a decoder-only Transformer is and how it is trained, since Lyra is one.
- karpathy/nanoGPT: The simplest, fastest repository for training/finetuning medium-sized GPTs (repo, Andrej Karpathy (GitHub), 40 min)
Read a compact, real training script (it is now deprecated but still a good reference) so Lyra's train.py will look familiar.
- Training Compute-Optimal Large Language Models (article, arXiv (Hoffmann et al., DeepMind), 45 min)
Learn the model-size versus tokens trade-off, which explains why 6.4B tokens is a sensible budget for 326M parameters.
- Automatic Mixed Precision (tutorial, PyTorch Tutorials, 25 min)
Learn autocast and GradScaler, the first trick that makes training fit and run fast on an 8 GB card.
- Methods and tools for efficient training on a single GPU (doc, Hugging Face Docs, 40 min)
See the other memory levers in one place: gradient accumulation, checkpointing, optimizer choice and Flash Attention.
- Let's reproduce GPT-2 (124M) (video, Andrej Karpathy (YouTube), 4 h)
Watch a full pretraining run: data loading, speed optimizations, learning-rate schedules, validation loss and evaluation.
- karpathy/build-nanogpt: Video+code lecture on building nanoGPT from scratch (repo, Andrej Karpathy (GitHub), 45 min)
Step through the clean commit history from the video to see how each training feature gets added.
- luka0x12/Lyra: A 326M-parameter decoder-only Transformer trained from scratch on one RTX 3060 Ti (repo, luka0x12 (GitHub), 45 min)
Now read the trending project itself: model.py, train.py, data.py and the SFT pipeline, using what you learned.
- Lyra architecture and training notes (article, luka0x12 (GitHub Pages), 25 min)
Compare the author's own design choices and training notes against the theory and recipes from earlier steps.
- luka0x12/Lyra-326M-Instruct (doc, Hugging Face, 20 min)
Finish with the fine-tuned model card, then run chat.py to see how supervised fine-tuning turns a text completer into a chat model, flaws included.