AI Playground

An interactive, project-based book on how LLMs work — internals, training optimization, inference serving, and GPU performance — built around a clean, from-scratch LLaMA-style transformer. Its motto is Feynman’s: what I cannot create, I do not understand. You don’t just read this book; you build its capstone, one hour at a time, and every claim to understanding is checked by a test.

Source code lives at github.com/ggreg/ai_playground.

Note🏗️ The capstone project: serve your own LLM

Every chapter ends with a milestone toward one goal: design and train your own small LLM, then serve it through the mini-vLLM inference engine you build — paged KV cache, continuous batching, your model’s text through your own engine. The milestone map is on The Project page; the finale is your trained weights generating text through your paged engine, verified by the same parity assert real serving systems use.

What’s here, and how to use it

The book is three layers. Use any one alone, or all three together:

Layer What it is How you use it
This website Every chapter rendered with outputs and plots, plus the guides Read anywhere, zero setup. The 📍 map at the top of each page tracks your progress (stored in your browser).
The notebooks The same chapters as runnable Jupyter notebooks Clone the repo and run them locally (CPU/Apple Silicon is enough), or open any GPU chapter on a free T4 via its Open in Colab badge. Change things; predict before you check.
The project sessions One-hour study sessions pairing each chapter with a capstone step, tutored by a coding agent /onboard once, then /session — the agent paces you, hints without ever writing your code, and verifies each milestone with uv run pytest tests/milestones/.

Just browsing? Start with the Transformer Overview and follow the Learning Path.

Doing the book? Read How to Read This Book (5 minutes), then:

git clone https://github.com/ggreg/ai_playground.git
cd ai_playground
uv sync --extra dev
uv run pytest        # all green; the 26 milestone tests skip until you earn them

claude               # Claude Code, from the repo root
> /onboard           # 5-minute interview: background, goal, hardware, pace
> /session           # your first one-hour session starts here

No agent? The Session Guide works as a plain syllabus and the milestone tests verify your work either way. No GPU? Every GPU-flagged milestone has a stated CPU fallback, and the GPU chapters run on Colab’s free T4.

The one-hour session

Each session has the same shape — ~20 minutes reading and experimenting, ~30 minutes building the chapter’s project step (you write the code; the agent reviews, hints by an escalating ladder, and keeps time), ~10 minutes verifying and logging. Every card marks a midpoint, so a session also splits cleanly into two 30-minute sittings. Long training runs are launched at the end of one session and harvested at the next.

  • How to Read This Book — setup and the rules of the game
  • Session Guide — all 30 session cards: reading, project step, prerequisites, done-when test
  • Inside a Session — the full protocol: what the agent will and won’t do, the hint ladder, the log

Chapters

Read them here with all outputs rendered, run them locally, or open a chapter on a free GPU via its Open in Colab badge. The ⏱️ column is where each chapter sits in the session sequence — note the GPU module comes before the finale.

Module Chapters ⏱️ Sessions
DNN Refresher (optional) Neurons & MLPs · Backprop & Micrograd · The Training Loop · Softmax & Cross-Entropy (🏗️ M0) S0.1–S0.5
Transformer Internals Transformer Overview (🏗️ M1) · Attention Mechanisms (🏗️ M2) · Mixture of Experts (🏗️ M3) S1.1–S1.4
Training Optimization Training From Scratch (🏗️ M4) · Learning Rate Schedules (🏗️ M5) · Mixed Precision (🏗️ M6) · Gradient Accumulation (🏗️ M7) · AdamW From Scratch (🏗️ M8) S2.1–S2.8
GPU & NVIDIA Tools CUDA Basics (🏗️ M9) · SIMT Simulator (🏗️ M10) · Virtual GPU (🏗️ M11) · SGEMM Optimization (🏗️ M12) S5.1–S5.8
Inference Optimization Build a Mini vLLM (🏗️ M13, the finale) — paged KV cache, PagedAttention, continuous batching S4.1–S4.6
Building AI Agents (epilogue) What is an Agent? · Tool Use · Memory S6.1–S6.3

Guides

  • Learning Path — the phase-by-phase curriculum and what each milestone certifies
  • Concepts FAQ — deep dives on embeddings, cross-entropy, bias, and other conceptual questions
  • Papers — key papers organized by topic with summaries
  • Videos — curated videos matched to each module (3Blue1Brown, Karpathy, GPU MODE, and more)
  • Performance Exercises — between-session GPU practice for readers with cloud time
  • Cloud Setup — renting a GPU when Colab isn’t enough
  • Progress Template — the session-log format the agent maintains for you

Running the notebooks locally

uv sync --extra dev
uv run --with jupyterlab jupyter lab   # then open notebooks/ and pick a chapter

# Quick training sanity check (CPU/MPS, ~30 seconds)
uv run python scripts/train.py --config configs/tiny.yaml --max-steps 20

Everything imports from the ai_playground package — the same clean implementations the chapters explain (src/ai_playground/models, training, inference, profiling, fundamentals, agents). Your capstone artifacts live in the gitignored checkpoints/myllm/ workspace; your model never leaves your machine.