Module 1 · Chapter 1
Understanding reasoning models
Before writing any code, get a precise picture of what “reasoning” means for a language model, where it comes from in the training pipeline, which levers exist to improve it, and what it costs.
You will learn to
- State the engineering definition of reasoning for LLMs (intermediate steps before the answer) and what it does not claim
- Describe the conventional pipeline: pretraining → instruction tuning → preference tuning, and what data and objective each stage uses
- Classify a technique as inference-time scaling, reinforcement learning, or distillation, and say whether it changes the weights
- Explain the difference between pattern matching and logical reasoning, and predict when pattern matching fails
- Estimate why reasoning models are more expensive to run
- Find your way around the course road map and set up your lab environment
Hook Same model, two very different answers
Ask a language model: “A train leaves at 2:40 pm and the trip takes 95 minutes. When does it arrive?” A model that answers immediately has to produce the time in its very first tokens. It might say “4:35 pm” (it added 1:55 instead of 1:35) and sound completely sure about it.
Now ask the same model to write out its work first: “95 minutes is 1 hour 35 minutes. 2:40 plus 1 hour is 3:40. Plus 35 minutes is 4:15. It arrives at 4:15 pm.” Each step is small and easy, and the final answer is right.
Nothing about the network changed between the two answers. What changed is that the model got to spend tokens, and therefore computation, on intermediate steps. That simple observation is the seed of everything in this course: how do we get models to produce useful intermediate steps, and how do we make them better at it?
Concept What “reasoning” means here
The book uses reasoning in a deliberately practical, engineering sense: an LLM reasons when it generates intermediate steps before giving its final answer. A reasoning model is an LLM that has been improved, by prompting or by training, to produce such steps, which usually raises accuracy on multi-step problems like math, puzzles and code.
<think>…</think> tags. (Original diagram; compare Book Figs. 1.1–1.2.)This style of output is called chain of thought (CoT). People say the model “thinks step by step”; the book uses reasoning and thinking in this loose engineering sense only.
It does not say LLMs reason like humans, and it does not say the steps are logically valid. An LLM produces its steps autoregressively: one token at a time, each chosen from a probability distribution learned from text. The steps can look convincing and still be wrong. A symbolic logic engine or theorem prover, by contrast, applies fixed rules and gives the same, guaranteed-consistent result every time, like following a recipe exactly.
| LLM “reasoning” | Rule-based / human deliberate reasoning | |
|---|---|---|
| Mechanism | Predicts the next token from learned statistical patterns | Applies explicit rules or an internal model of the world |
| Determinism | Probabilistic; can vary between runs | Same facts + same steps → same conclusion |
| Guarantees | None: plausible-looking steps can be invalid | Consistency guaranteed by the rules |
| Strength | Flexible, learned from huge data, no hand-written rules | Transparent and verifiable, but rules are hard to write |
Book §1.1 (definition, chain of thought, LLM vs. human reasoning)
Concept How a conventional LLM is trained
Reasoning methods are added on top of an existing LLM, so we first need to know what that LLM already is. Conventional training has two big phases:
- Pretraining. The randomly initialized model reads trillions of tokens of unlabeled text (web pages, books, code) and learns one thing: predict the next token. This is by far the most expensive stage: thousands of GPUs for months. The result, a base model, writes fluent text and shows “emergent” skills such as translation, but it continues text rather than answering questions. (Some papers add a mid-training stage, e.g. extra code or long documents; the book groups it with pretraining.)
- Post-training, in two steps:
- Instruction tuning (supervised fine-tuning, SFT): train on example (instruction, good response) pairs so the model learns to answer, summarize, translate on request.
- Preference tuning: make responses people prefer more likely. RLHF (reinforcement learning from human feedback) is one well-known way to do it.
A useful one-liner: pretraining gives raw language prediction, instruction tuning gives task understanding, preference tuning gives preferred style. Even then the model is not yet a chatbot: a chat app adds a system prompt and conversation history around it (the book builds one in Appendix G).
Try: step through stages 0 → 3 and read the output for the same prompt at each stage, then click the three reasoning methods. Notice: every conventional stage changes the weights with a different data + objective pair; the pretrained model ignores the instruction and keeps writing a “document”; and only inference-time scaling leaves the weights untouched.
In Chapter 2 we load a base model (Qwen3 0.6B base), i.e. the output of pretraining only. Starting from a base model makes it easier to see which abilities the reasoning methods add, rather than ones inherited from instruction or preference tuning.
Book §1.2 (standard training pipeline, Figs. 1.3–1.4)
Concept Three ways to improve reasoning
Reasoning entered the spotlight with OpenAI's o1 (September 2024), a model family “designed to spend more time thinking before they respond”. In January 2025 DeepSeek-R1 followed with an open model and a detailed recipe. The methods behind such models fall into three families:
- A
- Inference-time compute scaling (also “test-time scaling”): spend more computation when answering, without changing any weights. Examples: asking for step-by-step reasoning, sampling several answers and taking a majority vote, critiquing and refining a draft. Trade compute for accuracy.
- B
- Reinforcement learning (RL): the model tries, receives a reward, and its weights are updated to make rewarded behavior more likely. For reasoning, rewards are often verifiable: is the final math answer correct? Does the code pass the tests?
- C
- Distillation: generate high-quality reasoning traces with a large “teacher” model and fine-tune a smaller “student” on them (supervised fine-tuning). In classic deep learning, distillation also matches the teacher's logits; in LLM practice it usually means training on the teacher's outputs only.
Both use the same RL machinery. The difference is where the reward comes from. RLHF (preference tuning) uses human rankings of responses, or a reward model trained on them: subjective, aligned with taste. RL for reasoning uses an automatic verifier or environment: objective and cheap to compute, but it only checks what it can check (e.g. the final number), not whether people like the answer.
Book §1.3 (inference-time scaling, RL, distillation; sidebar on RL vs. RLHF)
Concept Pattern matching vs. logical reasoning
Prompt: “The capital of Germany is …”. The model answers “Berlin”. It did not deduce anything; it completed a pattern it saw countless times in training. This is pattern matching: continuing text according to learned correlations.
Logical reasoning is different: it derives conclusions from premises with rules, through intermediate steps, and notices contradictions. Consider:
Closed world (prompt only)
Using only the two premises, the valid conclusion is “yes”. Logic does not care whether the premises are true, only what follows from them.
Open world (with background knowledge)
Now the conclusion clashes with a known fact: a contradiction. A careful reasoner flags it, asks for clarification, or weakens a premise (“most birds can fly”).
A pure pattern matcher does neither explicitly. It predicts what text usually follows. Large models such as GPT-4o often appear to handle the penguin case well, because the internet is full of text explaining that penguins are flightless birds; the model has learned the association, not a contradiction-checking procedure. That works impressively in familiar territory, and tends to break in two situations:
- Novel scenarios that do not resemble the training data, including familiar puzzles with a small twist (the model answers the famous version instead of the one asked).
- High complexity: many interdependent steps, where one slip derails the rest.
Reasoning models do not add a rule engine. They still predict tokens. Inference-time methods and RL make them better at producing and using intermediate steps, so models sit on a spectrum: even older LLMs could write step-by-step answers; “reasoning models” are a more refined version of that behavior.
Expert systems (popular in the 1980s–90s, still used in medicine, law, aerospace) are transparent but depend on hand-crafted rules and heuristics, which are hard to write and maintain. Neural networks learn their decision patterns from data and are far more flexible at scale.
Reasoning is not free
Reasoning helps on puzzles, hard math, challenging code and agent planning, but it is unnecessary for summarizing, translating or simple fact lookup. It can even hurt (“overthinking”). And it costs more, for two reasons:
- Longer outputs. An LLM generates one token per forward pass (you will implement exactly this loop in Module 2). Twice as many tokens means roughly twice the compute.
- More calls. Many reasoning workflows run the model several times per question: sample several candidates, run a verifier, refine a draft.
Try: set 0 reasoning tokens and 1 call, then raise the reasoning tokens to 500 and the calls to 8. Notice: the two factors multiply, so the cost ratio quickly reaches the hundreds. That is why “know when to think long and when not to” is a real design goal for model providers.
Book §1.4–1.6 (pattern matching, simulating reasoning, why build reasoning models, Fig. 1.8)
Play The road map of this course
The book follows four stages. Stage 1 loads an existing pretrained LLM (we never pretrain from scratch). Stage 2 builds the evaluation tools. Stage 3 improves reasoning at inference time; stage 4 improves the model itself by training. After every change in stages 3 and 4 we go back to stage 2 and measure.
Try: click each module and check the “weights change” line. Then mark a section of this lesson complete (button at the end of each section) and watch the tracker update. Notice: Modules 4–5 never touch the weights, Modules 6–8 always do, and every one of them depends on Module 3's evaluator to prove it helped.
Book §1.7 (Figs. 1.9–1.10)
Check Check your understanding
Build Set up your environment
This chapter is conceptual, so there is no lab. Use the time to prepare the environment that every later lab uses. Full details are in labs/README.md; the book's own setup options (pip or uv) are in Book §2.2.
cd labs python3.12 -m venv .venv .venv/bin/pip install -r requirements.txtOr run
./labs/setup_venv.sh. On an exFAT/FAT drive, put the venv on your internal disk:RMFS_VENV_DIR=~/.venvs/rmfs ./labs/setup_venv.sh..venv/bin/python -m ipykernel install --user --name rmfs --display-name "Python (rmfs)"import torch print(torch.__version__) if torch.cuda.is_available(): print("CUDA GPU:", torch.cuda.get_device_name(0)) elif torch.backends.mps.is_available(): print("Apple Silicon GPU (MPS)") elif torch.xpu.is_available(): print("Intel GPU") else: print("CPU only")
These checkboxes are just for you; they are not saved.
Stretch Exercises and challenges
Chapter 1 has no numbered book exercises. These challenges check that the concepts stick.
Challenge 1: Sort the techniques extra
For each technique, decide: inference-time (weights frozen) or training-time (weights updated)? If training-time, is it RL or distillation (or neither)? (a) best-of-N sampling with a verifier picking the answer, (b) GRPO with a correctness reward, (c) SFT on DeepSeek-R1 traces, (d) RLHF with human rankings, (e) self-refinement, (f) instruction tuning on human-written answers, (g) majority voting over 16 samples.
Hint
Ask one question per item: does the procedure end with a different set of weights? If yes, where does its learning signal come from: a reward, or example outputs to imitate?
Solution
Inference-time: (a), (e), (g). Training-time RL: (b) (verifiable reward) and (d) (human-preference reward, i.e. preference tuning rather than reasoning RL). Distillation: (c), because the imitated outputs come from a stronger model. (f) is ordinary instruction tuning (SFT on human data): training-time, but neither reasoning RL nor distillation.
Challenge 2: Design a pattern-matching trap extra
Take a famous riddle or puzzle and change one detail so that the famous answer becomes wrong. Predict what a conventional LLM will answer, and why a step-by-step answer is more likely to be right.
Hint
Classic candidates: the “feathers vs. bricks” question, river-crossing puzzles, the Monty Hall problem. Change a quantity or a rule.
Solution
Example: “A farmer must cross a river with a goat. The boat holds the farmer and two animals. How many trips?” The famous version (wolf, goat, cabbage; boat holds one item) needs 7 crossings, and pattern matching tends to reproduce that elaborate plan. Here a single crossing suffices. Writing intermediate steps (“only one animal, boat has room, so cross once”) forces the model to process the actual constraints instead of the memorized ones. It is not guaranteed to work: the steps themselves are still generated by pattern matching, just in smaller, more checkable pieces.
Challenge 3: Latency budget extra
A non-reasoning model answers in about 150 tokens; a reasoning model averages 1,500 tokens. You run 8-sample self-consistency with the reasoning model, sequentially, at 50 tokens per second. How long does one question take in each case? What would you change to cut the reasoning latency?
Hint
Time ≈ total generated tokens / speed.
Solution
Non-reasoning: 150 / 50 = 3 s. Reasoning with 8 samples: 8 × 1,500 / 50 = 240 s = 4 minutes, 80 times slower. Options: generate the 8 samples in parallel as a batch (Appendix E), stop sampling early once a majority is clear (Exercise 4.4), use fewer samples, cap the reasoning length, use a faster generation loop (KV cache, compilation: Module 2), or route easy questions to the non-reasoning mode.
Challenge 4: Remove the ambiguity extra
Rewrite the penguin prompt twice: once so that the intended answer is unambiguously the closed-world one, once so that it is unambiguously the open-world one.
Solution
Closed world: “Assume only the following statements are true, even if they contradict reality: all birds can fly; a penguin is a bird. According to these statements alone, can a penguin fly?” (answer: yes). Open world: “Is the statement ‘all birds can fly’ consistent with what you know about penguins? Explain.” (answer: no, penguins are flightless birds, so the generalization is false).
Recap Key takeaways
- For LLMs, reasoning = generating intermediate steps before the answer (chain of thought). It makes no claim about human-like thought or guaranteed validity.
- Conventional LLMs come from pretraining (next-token prediction) plus post-training (instruction tuning, then preference tuning). Reasoning methods are applied on top, in this book to a base model.
- Three families improve reasoning: inference-time scaling (weights frozen, more compute per answer), reinforcement learning (weights updated from rewards, often verifiable), and distillation (a small model imitates a big model's traces).
- LLMs pattern-match; they simulate logical reasoning well in familiar settings and fail on novel twists and long multi-step problems.
- Reasoning costs more: one forward pass per token, longer outputs and multiple calls multiply the work.
- The course road map: load an LLM → evaluate → improve at inference time / by training → evaluate again.
Cheat sheet: Chapter 1 vocabulary
- Reasoning (LLM)
- intermediate steps before the final answer, visible or inside
<think>tags - Pretraining
- next-token prediction on trillions of unlabeled tokens → base model
- SFT / instruction tuning
- imitate (instruction, response) examples
- Preference tuning
- prefer human-favoured responses; RLHF is one method
- Inference-time scaling
- more compute at answer time; weights frozen (Ch. 4–5)
- RL for reasoning
- reward verified-correct answers, update weights (Ch. 6–7)
- Distillation
- SFT of a small student on a large teacher's traces (Ch. 8)
- Pattern matching
- completing text by learned correlations, not explicit rules