Skip to content

Karpathy: Deep Dive into LLMs like ChatGPT

optionalcorefrontiervideorubric 12/122025 · ~240 min

Andrej Karpathy

Status

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.

Three stages build on each other:

  1. Pre-training: predict the next token on internet text, producing a base model that completes documents.
  2. Supervised fine-tuning: continue training on conversations written to show an ideal assistant, so the model imitates that persona.
  3. 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 C≈6NDC\approx6ND for pre-training. At inference each token costs about 2N2N FLOPs, which is why “models need tokens to think”.

Lecture map (chapter times from the video description; study pages on this site):

timechapterstudy page
1:00pre-training data (internet)FineWeb, DCLM
7:47tokenisationBPE
14:27–26:01network I/O, internals, inferenceAttention Is All You Need, 3Blue1Brown
31:09GPT-2: training and inferenceLet’s build GPT, GPT-3
42:52Llama 3.1 base model inferenceLlama 3
1:01:06post-training data (conversations)InstructGPT
1:20:32hallucinations, tool use, working memorySimpleQA, Lost in the Middle
1:46:56models need tokens to thinkChain-of-Thought, Why we think
2:01:11tokenisation revisited: spellingBPE
2:14:42reinforcement learningPPO, GRPO
2:27:47DeepSeek-R1s1, test-time compute
2:48:26RLHFReward modelling, RM over-optimisation
3:09:39preview of things to comeAgents
Karpathy's deep dive into LLMs: a three-and-a-half-hour tour of pre-training, supervised fine-tuning and reinforcement learning A timeline of the video's chapters split into three stages. Pre-training, from about 1 to 59 minutes: internet data, tokenisation, network input and output, internals, inference, GPT-2 training and Llama 3.1 base-model inference. Post-training with supervised fine-tuning, from about 59 minutes to 2 hours 7 minutes: conversation data, hallucinations and tool use, knowledge of self, models need tokens to think, spelling problems and jagged intelligence. Reinforcement learning, from 2 hours 7 minutes to 3 hours 10 minutes: moving from SFT to RL, reinforcement learning on verifiable problems, DeepSeek-R1, AlphaGo and RLHF, then a look ahead. Each chapter is linked to a related study page. At the bottom, a worked number: Llama 3.1 405B was pre-trained on 15.6 trillion tokens, and 6 N D gives about 3.8 times 10 to the 25 FLOPs, as the Llama 3 paper reports. Three stages, one video (chapter times from the description) pre-training SFT + "psychology" reinforcement learning 0:00 1:00 2:00 3:00 Pre-training 1:00internet data → FineWeb 7:47tokenisation → BPE 14:27network I/O, internals 26:01inference, sampling 31:09GPT-2 training → GPT-3 42:52Llama 3.1 base model → Llama 3 Post-training: SFT 1:01:06conversation data → InstructGPT 1:20:32hallucination, tools → SimpleQA 1:41:46knowledge of self 1:46:56tokens to think → CoT 2:01:11spelling and tokens → BPE 2:04:53jagged intelligence Reinforcement learning 2:07:28from SFT to RL 2:14:42RL on verifiable tasks → GRPO 2:27:47DeepSeek-R1 → s1, TTC 2:42:07AlphaGo, move 37 2:48:26RLHF → reward hacking 3:09:39what comes next Worked number: Llama 3.1 405B saw 15.6T tokens, so 6ND = 6 × 405B × 15.6T ≈ 3.8 × 10^25 FLOPs, matching the 3.8 × 10^25 reported in the Llama 3 paper.
Original sketch. The lecture's chapters on a timeline, grouped into pre-training, supervised fine-tuning and reinforcement learning, with related study pages. Bottom: the pre-training compute of Llama 3.1 405B from 6ND.

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 3.8×10253.8\times10^{25} 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.
  • 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.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Done with this page?

Status