liveBook · Manning

What you will learn in Build a Reasoning Model (From Scratch)

by Sebastian Raschka

Chapter by chapter

Chapter 1: Understanding reasoning models

The chapter introduction motivates reasoning methods for complex LLM tasks and agents, and explains why the book uses checkable math examples while considering the costs of added reasoning machinery.

1.1 Defining reasoning in the context of LLMs · 1.2 Understanding the standard LLM training pipeline · 1.3 Improving LLM reasoning with training and inference techniques · 1.4 Pattern matching vs. logical reasoning · 1.5 Simulating reasoning without explicit rules · 1.6 Why build reasoning models from scratch? · 1.7 A road map to building reasoning models from scratch · 1.8 Summary

What you learn in chapter 1 →

Chapter 2: Generating text with a pretrained LLM

The chapter establishes why it starts with a pretrained base LLM before adding reasoning techniques in later chapters.

2.1 Introducing LLMs for text generation · 2.2 Setting up the coding environment · 2.3 Understanding hardware needs and recommendations · 2.4 Preparing input texts for LLMs · 2.5 Loading pretrained models · 2.6 Understanding the sequential LLM text generation process · 2.7 Coding a minimal text generation function · 2.8 Faster inference via KV caching · 2.9 Faster inference via PyTorch model compilation · 2.10 Summary

What you learn in chapter 2 →

Chapter 3: Evaluating reasoning models

The chapter introduction defines evaluation as quantitative testing against reference answers and identifies math-answer verification as the chapter’s approach.

3.1 Building a math verifier · 3.2 Loading a pretrained model to generate text · 3.3 Implementing a wrapper for easier text generation · 3.4 Extracting the final answer box · 3.5 Normalizing the extracted answer · 3.6 Verifying mathematical equivalence · 3.7 Grading answers · 3.8 Loading the evaluation dataset · 3.9 Evaluating the model · 3.10 Summary

What you learn in chapter 3 →

Chapter 4: Improving reasoning with inference-time scaling

The chapter introduction establishes that reasoning accuracy can improve during text generation without retraining or modifying the model.

4.1 Introduction to inference-time scaling · 4.2 Loading a pretrained model · 4.3 Generating better responses with chain-of-thought prompting · 4.4 Controlling output diversity with temperature scaling · 4.4.1 Understanding the process of selecting the next token · 4.4.2 Rescaling token scores (logits) via a temperature parameter · 4.4.3 Sampling the next token from a probability distribution · 4.4.4 Adding temperature scaling to the text generation function · 4.5 Balancing diversity and coherence with top-p sampling · 4.5.1 Selecting a subset of top-p tokens · 4.5.2 Adding a top-p filter to the text generation function · 4.6 Improving response accuracy with self-consistency · 4.7 Summary

What you learn in chapter 4 →

Chapter 5: Inference-time scaling via self-refinement

Introduces self-refinement as an inference-time scaling technique and contrasts it with self-consistency.

5.1 Scoring and iteratively improving model responses · 5.2 Loading a pretrained model · 5.3 Scoring LLM responses with a rule-based score · 5.4 Understanding token probability scores · 5.5 From token probability scores to log probabilities · 5.6 Scoring model confidence with log probabilities · 5.7 Self-refinement through iterative feedback · 5.8 Coding the self-refinement loop · 5.9 Summary

What you learn in chapter 5 →

Chapter 6: Training reasoning models with reinforcement learning

The introduction places reinforcement learning among the ways to improve reasoning models, contrasting training methods with increased inference compute.

6.1 Introduction to RL for LLMs · 6.1.1 The original RL pipeline with human feedback (RLHF) · 6.1.2 From human feedback to verifiable rewards · 6.2 RLVR using GRPO · 6.2.1 High-level GRPO intuition via a chef analogy · 6.2.2 The high-level GRPO procedure · 6.3 Loading a pretrained model · 6.4 Loading a MATH training subset · 6.5 Sampling rollouts · 6.6 Calculating rewards · 6.7 Preparing learning signals from rollouts via advantages · 6.8 Scoring rollouts with sequence log probabilities · 6.9 From advantages to policy updates via the GRPO loss · 6.10 Putting everything together in a single GRPO function · 6.11 Implementing the GRPO training loop · 6.12 Loading and evaluating saved model checkpoints · 6.13 Summary

What you learn in chapter 6 →

Chapter 7: Improving GRPO for reinforcement learning

The chapter picks up from an implemented GRPO baseline and identifies training instability as a concern during longer runs.

7.1 Improving GRPO · 7.2 Tracking GRPO performance metrics · 7.2.1 Executing a GRPO training run · 7.2.2 Inspecting the GRPO training run · 7.3 Tracking more advanced GRPO performance metrics · 7.3.1 Advantage tracking · 7.3.2 Entropy tracking · 7.3.3 Plotting additional GRPO metrics · 7.4 Stabilizing sequence-level GRPO using clipped policy ratios · 7.4.1 Computing clipped policy ratios · 7.4.2 Training with clipped policy ratios · 7.5 Controlling how much the model changes with a KL term · 7.5.1 Implementing the KL loss term · 7.5.2 Training with a KL loss term · 7.6 Adding an explicit format reward · 7.6.1 Using <think> tokens · 7.6.2 Training a model to emit <think> tokens · 7.6.3 More GRPO modifications, tips, and tricks · 7.7 Summary

What you learn in chapter 7 →

Chapter 8: Distilling reasoning models for efficient reasoning

The chapter introduces distillation as a training-time way to improve a smaller reasoning model using outputs from a larger model.

8.1 Introducing model distillation for reasoning tasks · 8.2 Generating a dataset for reasoning distillation · 8.3 Loading the MATH training dataset for distillation · 8.4 Building training examples · 8.4.1 Loading and understanding the tokenizer · 8.4.2 Formatting and tokenizing the dataset · 8.4.3 Filtering and splitting the dataset · 8.5 Loading a pretrained model · 8.6 Computing the training and validation losses · 8.7 Implementing the training loop for distillation · 8.8 Evaluating the distilled model · 8.9 Future directions for reasoning models · 8.10 Conclusions · 8.10.1 What’s next · 8.10.2 Staying up to date in a fast-moving field · 8.11 Summary

What you learn in chapter 8 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.