R205 · AI education › Learning paths for AI engineers

Train LLM From Scratch: every post-training objective on one hand-written Transformer

Read the original

Authors Mayank A. (shared)

trainingpost-trainingteachingopen-source

Source: Mayank A.'s LinkedIn post (2026-10-27) on FareedKhan-dev/train-llm-from-scratch by Fareed Khan. MIT license, 13.3K stars and 1.8K forks on 2026-11-21 (the post said 12.5K), created January 2025, last push 2026-11-16.

The claim

The post calls the repo an entire LLM engineering course in one codebase: a Transformer written in plain PyTorch, then pretraining, SFT, a reward model, DPO/ORPO/KTO, PPO and GRPO on the same backbone, plus a modern variant (RoPE, RMSNorm, SwiGLU, GQA, MLA, MoE, KV cache) and a 369K-parameter model that trains on a laptop CPU in about five minutes. The README supports all of that. It also covers more than the post lists: Muon, LoRA, IPO, SimPO, Dr. GRPO, DAPO, GSPO, speculative decoding and int8 inference, all hand-written with no trl, peft or transformers.

How it is built

What the evidence shows, and what it doesn't

How it compares

Train LLM From Scratch (R205)MiniMind (R097)nanochat (R120)
Main aimteach every objective on one backbonea usable 64M model end to endthe fastest honest single-node pipeline
Post-training breadthwidest: SFT, RM, DPO family, PPO, GRPO familywide: DPO, PPO, GRPO, CISPO, agent RLnarrow: SFT, a simple RL stage
Library usenone for training (no trl/peft/transformers)someminimal
Smallest run369K params, laptop CPU, about 5 min64M, one GPUCPU script, then GPU speedrun
Evidenceexact lm-eval match; weak post-training numbersREADME as lab notebook, stderr reportedpublic speedrun leaderboard

Pick this one to read the objectives side by side; pick nanochat to learn what makes pretraining fast, and MiniMind for a model that actually does something after post-training.

Failure modes for a reader

Review checklist if you adopt it for teaching

  1. Run the laptop track first (three commands) and confirm the tiny model writes coherent stories.

  2. Run pytest -m "not slow" and one smoke config per stage before any real run.

  3. For an objectives lesson, hold the SFT checkpoint, preference data and seed fixed, then run --loss_type dpo, orpo, kto, simpo and compare implicit-reward accuracy and sample outputs, not only loss curves.

  4. Use the verifier reward for PPO/GRPO demos; show the arithmetic curriculum's role by removing it once.

  5. Pair eval_base.py with lm-evaluation-harness on GPT-2 as a lesson in validating your own eval code.

R097 MiniMind and R120 nanochat (the other two from-scratch training repos), R098 Stanford CS329A (theory behind GRPO and verification), R126 (async GRPO used for real on a 27B model), R053 (small from-scratch models as a bench for poisoning studies).

Cited in field guides

Connections

See R205 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.