InterviewKata
AI engineering · Module 03a · Level 1: How AI works

From base model to agent

Module 03 explained where a model's knowledge comes from. This module follows the whole production line: how training adjusts the weights, why a freshly pretrained "base model" can't hold a conversation, and the stages that turn it into an assistant, then a reasoning model, then an agent that calls tools. Each stage uses a different kind of data and a different way of rewarding the model.

A 4-minute conversation: Sam asks, Priya explains
0:00 / 4:20

1. The idea

Training a doctor. First, years of reading every textbook and journal: broad knowledge, but no bedside manner (pretraining). Then supervised residency: watching and copying how senior doctors handle real patients (supervised fine-tuning). Then feedback from patients and seniors on which of two approaches was better (preference tuning). Then practice cases with a right answer, solved again and again until the reasoning is reliable (reinforcement learning). Finally, learning to order tests and read the results instead of guessing (tool use).
StageDataWhat the model learnsResult
PretrainingTrillions of tokens of text and code (Llama 3: over 15 trillion)Predict the next tokenBase model: knows a lot, continues any text, doesn't follow instructions
Supervised fine-tuning (SFT)Thousands to millions of example conversations, written or checked by people, in the chat templateAnswer in the assistant's role and formatInstruction-following model
Preference tuningPairs of answers where people (or a model) picked the better onePrefer helpful, honest, safe answersAssistant that people prefer
Reinforcement learning with verifiable rewardsProblems with checkable answers: maths with known results, code with testsThink step by step until the answer is rightReasoning model
Tool-use and agentic trainingConversations with tool definitions, tool calls and results; multi-step tasksWhen and how to call tools, and use their resultsAgentic model

Everything after pretraining is called post-training. It uses a tiny fraction of the compute, but it decides how the model behaves.

2. How it works

How training changes the weights

Every stage uses the same machinery. Show the model some text, let it predict, measure how wrong it was with a loss (for next-token prediction, how low a probability it gave the real next token), then nudge every weight slightly in the direction that would have made the loss smaller. That nudge is gradient descent, and working out the direction for billions of weights at once is backpropagation. Repeat for trillions of tokens.

The same prompt, through each stage

Watch the support question from Module 01b at each stage of the production line:

Reinforcement learning for reasoning, in more detail

DeepSeek's R1 paper (published in Nature in 2025) showed that reasoning can be taught with reinforcement learning on problems whose answers can be checked automatically, without people writing out reasoning steps:

3. Try it yourself

One training step, for real

A toy model has learned scores for the next word after "The order will arrive". The training example says the right word is tomorrow. Press Train one step: the scores move exactly as gradient descent on the cross-entropy loss moves them (score += learning rate × (target − probability)). Watch the loss fall.

The order will arrive … ?

Which stage teaches this?

    4. Why it matters at work

    Fact about trainingWhat it means for you
    Knowledge comes from pretraining and stops at a cutoffgpt-oss's knowledge cutoff is June 2024. Recent facts must come from your prompt, retrieval or tools (Modules 03, 15).
    Post-training shapes behaviour, and a smaller well-tuned model can beat a bigger raw oneIn InstructGPT, people preferred a 1.3B-parameter tuned model over the 175B-parameter GPT-3. Don't choose models by size alone.
    Reasoning is trained with checkable rewardsReasoning models shine on maths, code and logic, where answers can be verified; gains are smaller on open-ended writing.
    Reward models can be gamedDeepSeek avoided learned reward models for reasoning because of reward hacking. Your own evals (Module 17) must check real outcomes, not proxies.
    Agentic ability is trained in a specific formatOpen models expect their own chat and tool format (gpt-oss: harmony). Use the official template, or tool calling degrades.
    You can do the later stages yourselfFine-tuning on your data is SFT or preference tuning on top of an existing model; gpt-oss-120b can be fine-tuned on a single H100 node. Try prompting and retrieval first: they're cheaper and easier to change.

    The training stack

    1. Data pipelines collect, filter and deduplicate text, then tokenize it (Module 01a) into training sequences.
    2. A framework such as PyTorch defines the network and computes gradients automatically.
    3. Thousands of GPUs train together: the data, the layers and even single matrices are split across machines (data, pipeline and tensor parallelism), with mixed precision to save memory.
    4. Checkpoints save the weights regularly, as safetensors files, so a crash doesn't lose weeks of work.
    5. Post-training reuses the same stack with smaller datasets: demonstrations for SFT, preference pairs for DPO, and for RL a loop that samples answers, scores them and updates the weights.
    The honest caveatsFrontier labs publish few details of their training data and post-training recipes; open-weight models (gpt-oss, Llama, DeepSeek) are the best public evidence, and even they leave much out. The stage list here is a simplification: real pipelines mix stages, repeat them and add safety training throughout. And "agentic training" is the least documented stage of all.

    5. Training methods you'll hear about

    Checked 1 November 2026.

    MethodHow it worksKnown from
    SFT (supervised fine-tuning)Train on example conversations in the chat template, with the same next-token loss as pretrainingEvery assistant model
    RLHF with a reward model (PPO)Collect rankings of answers, train a reward model on them, then optimise the model with reinforcement learning to score highlyInstructGPT (OpenAI, 2022)
    DPO (direct preference optimization)Train directly on preference pairs with a classification-style loss: no reward model and no RL loopRafailov et al., 2023; used alongside PPO in Llama 3
    Rejection samplingGenerate many answers, keep the best (by a checker or reward model), fine-tune on thoseLlama 3; DeepSeek-R1's third stage
    GRPOSample a group of answers per question, score each, and push the model towards the above-average ones; no separate critic modelDeepSeek-R1 (2025)
    Chain-of-thought RLReward correct final answers so the model learns to reason first; reasoning effort becomes adjustablegpt-oss ("similar to OpenAI o3"), DeepSeek-R1
    DistillationTrain a smaller model on a larger model's outputs, including its reasoningDeepSeek-R1's smaller distilled models

    6. Remember it

    Memory hook: "Read everything, copy the best, learn what people prefer, practise until right, then use tools"Pretraining, SFT, preference tuning, reinforcement learning, tool use.
    How this hook works: what the five phrases mean

    What the slogan means, phrase by phrase

    “Read everything”
    Pretraining on trillions of tokens: the base model.
    “copy the best”
    SFT on example conversations.
    “learn what people prefer”
    Preference tuning: RLHF or DPO.
    “practise until right”
    RL with verifiable rewards: reasoning.
    “then use tools”
    Training on tool calls and multi-step tasks: an agent.

    Why this picture fits: it's the order a professional is trained in, and the order labs train models in.

    The story → the concept

    Doctor's trainingModel training
    Medical school readingPretraining
    ResidencySupervised fine-tuning
    Feedback on bedside mannerPreference tuning
    Practice cases with answersRL with verifiable rewards
    Ordering testsTool use

    The trap it saves you from

    Thinking an assistant is "just" a big pretrained model. Most of what makes it useful, safe and agentic comes from post-training.

    7. Common mistakes

    Fine-tuning to add factsFine-tuning is good at behaviour and format, poor at adding reliable knowledge. Use retrieval for facts that change.
    Chatting with a base modelA base model continues text; it may write the next question instead of answering. Use an instruction-tuned model.
    Choosing by parameter countPost-training matters as much as size; compare models on your own tasks (Module 20).
    Ignoring the format a model was trained onTool calls and roles only work reliably in the model's own template.
    Trusting reasoning everywhereReasoning training targets checkable problems; for judgement calls, still check the output.

    8. Hands-on lab (roadmap week 3)

    1. Base versus instruct: on Hugging Face, find a base model and its instruct version (for example a Llama or Qwen pair). Give both the same question and compare.
    2. Read a model card: in the gpt-oss model card, find the pretraining data, knowledge cutoff and post-training method.
    3. Feel reasoning effort: ask a reasoning model the same logic puzzle at low and high effort; compare thinking length, time and accuracy.
    4. Write SFT data: write five example conversations for your support use case in a chat format. What would a sixth need to cover?
    5. Write preference pairs: for two of them, write a worse answer too. What makes the better one better?

    9. Self-check quiz

    What does a base model do with "Where is my order A-1042?"

    Following instructions comes from SFT and preference tuning.

    What does one gradient-descent step do?

    Backpropagation computes that direction for all weights at once.

    What was InstructGPT's headline result?

    Post-training can matter more than size.

    How does DPO differ from classic RLHF?

    A simple classification-style loss replaces the reward model and PPO.

    What did DeepSeek-R1's reinforcement learning reward?

    Rule-based accuracy and format rewards; learned reward models were avoided because of reward hacking.

    Your model must know this week's prices. Best approach?

    Fine-tuning teaches behaviour; changing facts belong in the prompt via retrieval or tools.

    10. Go deeper

    ResourceTimeWhy
    Training language models to follow instructions with human feedback (InstructGPT, OpenAI, 2022)45 minThe SFT → reward model → PPO recipe behind the first chat assistants.
    Direct Preference Optimization (Rafailov et al., 2023)40 minPreference tuning without a reward model or RL.
    DeepSeek-R1 (DeepSeek-AI, 2025; Nature)60 minReasoning from reinforcement learning: GRPO, rewards, the "aha moment", the four-stage pipeline.
    gpt-oss model card (OpenAI)30 minPretraining data, cutoff, chain-of-thought RL and the harmony format for an open agentic model.
    Introducing Meta Llama 3 (Meta)15 min15 trillion pretraining tokens, and post-training with SFT, rejection sampling, PPO and DPO.
    Chat templates (Hugging Face)15 minHow SFT data is formatted, and why base models just continue text.