Karpathy: Deep Dive into LLMs like ChatGPT
TL;DR. A general-audience lecture from February 2025 that walks through how a ChatGPT-like model is made, end to end. It covers pre-training on filtered web text, tokenisation, the network as a next-token predictor, a base model in action, supervised fine-tuning on conversations, the “psychology” that follows from this pipeline, and reinforcement learning, from DeepSeek-R1 and AlphaGo to RLHF. It complements Let’s build GPT, which is about code; this one is about the whole system and is mostly conceptual. Watch the video.
Why it matters now. It gives a shared map of the stack that most current work plugs into. It also explains many everyday failures, such as hallucination, spelling errors and uneven skills, in terms of how models are trained.
Key idea
Section titled “Key idea”Three stages build on each other:
- Pre-training: predict the next token on internet text, producing a base model that completes documents.
- Supervised fine-tuning: continue training on conversations written to show an ideal assistant, so the model imitates that persona.
- Reinforcement learning: let the model try many solutions and reinforce those that score well, either against a verifiable answer or against a reward model of human preferences.
The worked number in the diagram uses for pre-training. At inference each token costs about FLOPs, which is why “models need tokens to think”.
Lecture map (chapter times from the video description; study pages on this site):
| time | chapter | study page |
|---|---|---|
| 1:00 | pre-training data (internet) | FineWeb, DCLM |
| 7:47 | tokenisation | BPE |
| 14:27–26:01 | network I/O, internals, inference | Attention Is All You Need, 3Blue1Brown |
| 31:09 | GPT-2: training and inference | Let’s build GPT, GPT-3 |
| 42:52 | Llama 3.1 base model inference | Llama 3 |
| 1:01:06 | post-training data (conversations) | InstructGPT |
| 1:20:32 | hallucinations, tool use, working memory | SimpleQA, Lost in the Middle |
| 1:46:56 | models need tokens to think | Chain-of-Thought, Why we think |
| 2:01:11 | tokenisation revisited: spelling | BPE |
| 2:14:42 | reinforcement learning | PPO, GRPO |
| 2:27:47 | DeepSeek-R1 | s1, test-time compute |
| 2:48:26 | RLHF | Reward modelling, RM over-optimisation |
| 3:09:39 | preview of things to come | Agents |
Key results
Section titled “Key results”This is a lecture, so its results come from the papers it shows (linked in its description):
- Data and tokens: FineWeb as an example pre-training set and the Tiktokenizer web app to inspect tokens.
- Base model: Llama 3.1 405B; the Llama 3 paper reports 15.6T pre-training tokens and FLOPs.
- Post-training: InstructGPT for SFT; DeepSeek-R1 for reasoning learned through RL; AlphaGo for RL that surpasses imitation.
- Factuality: The Llama 3 paper’s §4.3.6 describes probing what the model knows, then training it to refuse questions it consistently gets wrong. Its stated principle is that post-training should make the model “know what it knows” rather than add knowledge.
Limitations & open questions
Section titled “Limitations & open questions”- General audience. No equations or code. Pair it with the GPT-3, InstructGPT and GRPO pages for detail.
- A snapshot of early 2025. Products, rankings and “where to find LLMs” age quickly.
- Mental models, not measurements. Ideas like “models need tokens to think” or “jagged intelligence” are useful heuristics; check them against studies such as CoT faithfulness.
- Open: how much of RL-trained reasoning is new skill versus better use of what pre-training already learned, which the s1 and spurious-rewards results probe.
Connections
Section titled “Connections”- Code companion: Let’s build GPT.
- Full course on each stage: CS336.
- Reasoning stage: s1, test-time compute, spurious rewards.
- RLHF failure modes: reward hacking (Weng).
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
The lecture inspects Llama 3.1 as a base model. The Llama 3 paper says the 405B model was pre-trained on 15.6T tokens. Estimate its pre-training compute with 6ND, then use about 2N FLOPs per generated token to compare one answer token with a 500-token worked solution.
What a strong answer covers
- 6 × 405 × 10^9 × 15.6 × 10^12 ≈ 3.8 × 10^25 FLOPs, matching the paper.
- A forward pass costs about 2N ≈ 8.1 × 10^11 FLOPs per token, regardless of how hard that token is.
- A 500-token solution gets about 500 times more computation, about 4 × 10^14 FLOPs, spread over intermediate steps it can read back.
- This is the "models need tokens to think" point: put reasoning before the answer, not after, and do not expect hard steps in a single token.
- Mechanism
Explain why a strong LLM can fail to count the letters in a word or spell it backwards, using what the lecture covers on tokenisation, and what a model or user can do about it.
What a strong answer covers
- The model sees token IDs for multi-character chunks, not letters; Llama 3, for example, uses a 128K-token vocabulary.
- The spelling of a token is not directly visible in its ID and must be learned indirectly from data.
- Counting also needs several steps in one forward pass, which runs into the fixed compute per token.
- Workarounds: ask the model to write the letters out one by one first, or to use a code tool.
- Critique
The lecture separates reinforcement learning on verifiable tasks (with DeepSeek-R1 and AlphaGo as examples) from RLHF. Critique the claim that RLHF is reinforcement learning in the same sense, and explain what limits how long it can be run.
What a strong answer covers
- Verifiable RL scores answers against a ground truth or rule, so the reward cannot easily be gamed and training can run for a long time.
- RLHF optimises a learned reward model that imitates human preference rankings. It is a lossy proxy.
- Optimising a proxy too hard finds adversarial outputs the reward model overrates, so the true quality falls (reward over-optimisation).
- In practice RLHF is run for a limited number of steps or with a KL penalty to the starting policy; it is more like fine-tuning toward preferences than open-ended RL.
- Design
Design a post-training data pipeline that reduces hallucination on factual questions, following the knowledge-probing method in the Llama 3 paper (linked in the video description). Specify each step and how you would evaluate it.
What a strong answer covers
- Extract snippets from pre-training data and have the model write factual questions about them.
- Sample several answers, score correctness against the snippet with an LLM judge, and score informativeness.
- Where answers are consistently informative but wrong, train the model to refuse; where right, keep the answer. The aim is that it knows what it knows.
- Evaluate on a held-out short-form factual set such as SimpleQA, tracking accuracy, refusal rate and accuracy when answering, so refusals are not counted as wins.
- Add tool use (search) for questions outside the model's knowledge, so refusing is not the only option.
- Connect
Place DeepSeek-R1, s1 and compute-optimal test-time scaling on the lecture's pipeline. Which stage does each change, and what does each say about where reasoning ability comes from?
What a strong answer covers
- DeepSeek-R1 adds large-scale RL with verifiable rewards after pre-training; long chains of thought with self-reflection emerge from the reward.
- s1 shows that supervised fine-tuning on only 1,000 curated traces plus budget forcing can reach similar behaviour on some benchmarks, so much of the ability is already latent in the base model.
- Test-time compute work changes nothing in training; it spends more inference on search, revisions or best-of-N.
- All three rely on the base model from pre-training; RL and SFT mainly teach it to use more tokens productively.