Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

AI from scratch

Working through how neural networks actually function — from a single multiply-and-add on paper to training and post-training a language model.

I already build with AI on the surface layer — Agentic Engineering. This repo is about the layer underneath that: not how to use the tools, but how they work and why. Everything here is built rather than read about, and every derivation gets checked numerically against code rather than taken on trust.

No deadline. Roughly 12–15 hours a week. Phases advance on a pass/fail exit criterion, never on elapsed time.

Method

  • Build first, pull the maths in when the implementation stalls. Never a maths block before the code.
  • Pen and paper before an editor. Every operation gets hand-computed before it gets typed.
  • Implement from scratch, then diff against a reference implementation.
  • Roughly 80% hands-on, 20% reading.
  • Where a derivation matters, hand-derive it and verify numerically — gradient checking, finite differences. The numerical check is the pass condition.

Handwritten notes are scanned in alongside the code, because the paper working is where the understanding actually happened.

Phases

Each advances only when its exit criterion is met.

#PhaseExit criterion
1Backpropmicrograd written blind, gradient checks matching finite differences to ~1e-6
2Training dynamicsdiagnose a broken training run from the loss curve and gradient norms alone
3Transformerwithin 5% of nanoGPT val loss, written from a blank file
4RL from scratchPPO from scratch matching CleanRL on LunarLander-v2
5Scaling laws and datajustify parameter count, token count and data mixture from an own sweep
6Distributed trainingaccount for the gap between theoretical and achieved FLOPs
7Post-trainingbase model to instruction-following, changes shown with evals
8Inferencecached generation matching uncached output token-for-token at greedy decoding

Phase 1 runs pen-and-paper for its first five lessons — the weighted sum, squashing, loss, sensitivity, and the chain rule — before any code gets written.

Each phase gets its own README recording what actually happened — including the things that didn't work, since those are usually where the learning was. Commit history is the progress log; there are no status tables to keep in sync.

References

  • Karpathy, Neural Networks: Zero to Hero — phases 1–3
  • Sutton & Barto, Reinforcement Learning: An Introduction — phase 4
  • Spinning Up in Deep RL, CleanRL — phase 4 reference implementations
  • Kaplan et al. 2020; Hoffmann et al. 2022 (Chinchilla) — phase 5
  • ZeRO (Rajbhandari et al. 2019); Megatron-LM (Shoeybi et al. 2019) — phase 6
  • InstructGPT (Ouyang et al. 2022); DPO (Rafailov et al. 2023) — phase 7

Note on this repo

This is a learning log, not a library. The implementations here are deliberately naive — written to be understood rather than used. Anything useful for real work already exists elsewhere and is better.

About

From a single multiply-and-add on paper to training and post-training a language model. Built rather than read about; every derivation verified numerically. Handwritten working included.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors