A guide to building long-term compounding knowledge infrastructure. See details on GitHub .

LLMs from Scratch

Repository and accompanying book materials that guide readers to build a working LLM from first principles.

Overview

LLMs from Scratch is the official code repository accompanying the book “Build a Large Language Model (From Scratch)”. It walks readers through implementing, pretraining, and fine-tuning GPT-like models using clear, educational code and explanations.

Key features

  • Chapter-aligned code examples covering tokenization, attention mechanisms, model implementation, and training loops.
  • Exercises, notebooks, and optional setup guides for running experiments on local machines and GPUs.
  • Focus on clarity and reproducibility for learning and research prototyping.

Use cases

  • Teaching and self-study to understand LLM internals.
  • Reference implementation for prototyping model components and training recipes.

Technical notes

  • Implemented primarily in PyTorch with attention to numerical stability and engineering practices.
  • Includes scripts for pretraining, fine-tuning, and evaluation, as well as optional performance improvements.

Comments

LLMs from Scratch
Resource Info
📖 Tutorial 🌱 Open Source