liveBook · Manning

Chapter 8: Distilling reasoning models for efficient reasoning

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

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: distillation, student model, teacher model, reasoning traces, answers

8.1 Introducing model distillation for reasoning tasks

This section introduces reasoning-model distillation, contrasts hard and soft approaches, and explains why training on teacher-generated text is the practical choice for this chapter.

Key terms: model distillation, teacher, student, reasoning trace, hard distillation, soft distillation, supervised fine-tuning, KL divergence, output distribution, teacher logits

8.2 Generating a dataset for reasoning distillation

This section explains how to create teacher-generated training data for hard reasoning distillation and how its supervision differs from RLVR.

Key terms: hard distillation, student model, teacher model, MATH-500 evaluation set, training targets, RLVR, verifier, reward signal, generated tokens, target sequence

8.3 Loading the MATH training dataset for distillation

This section loads a teacher-generated MATH dataset, turns its reasoning traces and answers into distillation targets, and checks the teacher’s accuracy against ground-truth answers.

Key terms: problem, gtruth_answer, message_thinking, message_content, supervised fine-tuning, format_distilled_answer, <think>...</think> tags, reasoning trace, final answer, ground-truth labels

8.4 Building training examples

The section outlines how to turn raw data into reusable distillation training examples and explains why preprocessing them once is efficient.

Key terms: training examples, token IDs, prompt length, distillation, RLVR, training epoch, preprocessing

8.4.1 Loading and understanding the tokenizer

This section explains how to tokenize and format a prompt and teacher answer as one sequence for reasoning distillation.

Key terms: Qwen3 reasoning tokenizer, <think></think> tokens, base tokenizer, --which_model "reasoning", apply_chat_template=True, add_generation_prompt=True, chat_wrapped=False, <|im_start|>user, <|im_end|>, <|im_start|>assistant

8.4.2 Formatting and tokenizing the dataset

This subsection builds tokenized distillation examples from prompts and teacher answers, then checks a decoded example for the required format.

Key terms: build_examples, prompt length, teacher answer, answer tokens, chat template, reasoning trace, <think></think>, <|im_end|>

8.4.3 Filtering and splitting the dataset

This section inspects tokenized example lengths, filters overly long examples, and splits the remaining data for training and validation.

Key terms: sequence lengths, outliers, tokens, 2,048 tokens, sequence length, distillation, fixed random seed, training and validation sets, MATH-500

8.5 Loading a pretrained model

This section chooses a pretrained Qwen3 base model for distillation and retains the previously prepared tokenizer that supports <think></think> tokens.

Key terms: pretrained Qwen3 base model, RL-trained model, distilled reasoning traces, teacher-generated data, base tokenizer, <think></think> token support

8.6 Computing the training and validation losses

The section defines an answer-only cross-entropy loss for distillation and explains how training and validation losses indicate whether the student is improving.

Key terms: cross-entropy, token log probabilities, answer tokens, sequence_logprob, answer-only loss, prompt, teacher’s reasoning trace, logits, targets, cross_entropy

8.7 Implementing the training loop for distillation

This section implements a distillation training loop, runs a small demonstration, and interprets its losses and saved checkpoints.

Key terms: epoch, cross-entropy distillation loss, GRPO loss, optimizer step, validation set, log_every, validation loss, distillation pipeline, maximum sequence length, GPU memory

8.8 Evaluating the distilled model

This section evaluates a distilled reasoning model through validation-loss trends and MATH-500 checkpoint results, then interprets the performance and cost tradeoffs.

Key terms: training loss, validation loss, held-out set, diminishing returns, saved checkpoints, MATH-500, reasoning tokenizer, verifier-based utilities, teacher, student

8.9 Future directions for reasoning models

The section identifies likely directions for reasoning models: stronger teachers and distillation, adaptive inference effort, richer training rewards, and agent applications.

Key terms: reasoning teacher, reasoning traces, student models, RLVR, distillation, inference scaling, application layer, reasoning budget, reasoning effort, final answers

8.10 Conclusions

Closes the book’s main technical material and introduces forthcoming pointers for further learning.

8.10.1 What’s next

The section recommends combining and comparing the book’s methods to find what helps most in a given setting, and points readers to resources for further work.

Key terms: distill, RLVR, inference-time scaling, self-consistency, self-refinement

8.10.2 Staying up to date in a fast-moving field

The section explains how to stay current with reasoning-model research by interpreting new work through durable fundamentals and filtering a fast-moving stream of sources.

Key terms: model evaluation, inference-time, training-time, training losses, reward signals, arXiv, technical summaries, model cards, practitioner discussions, deep research tools

8.11 Summary

The section summarizes how teacher-generated reasoning examples are prepared, used to train a smaller student model, and monitored during distillation.

Concepts explained in this chapter

← Chapter 7: Improving GRPO for reinforcement learning

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.