Pretrain a small LLM on one 8 GB GPU: the Lyra recipe

10 steps · about 10 h 45 min · Intermediate

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.