Overview

1 Understanding reasoning models

This opening chapter introduces reasoning models as the next practical step in large language model development. In this engineering context, “reasoning” means encouraging or training an LLM to generate intermediate problem-solving steps before giving a final answer. These steps may be visible to users or hidden internally, but the goal is the same: spend more computation on multi-step tasks such as math, coding, planning, and logical puzzles. The chapter emphasizes that this does not mean LLMs think like humans or follow deterministic logic; they still generate text probabilistically, one token at a time.

The chapter reviews the standard LLM training pipeline to explain where reasoning enhancements fit. Conventional models are first pre-trained on massive text datasets through next-token prediction, then post-trained with supervised instruction tuning and preference tuning so they can better follow user requests and produce helpful responses. Reasoning capabilities can then be improved through three main approaches: inference-time compute scaling, which improves answers without changing model weights; reinforcement learning, which trains models using reward signals such as verified correctness; and distillation, which transfers reasoning behavior from stronger models into smaller ones.

A major theme is the difference between pattern matching and logical reasoning. Standard LLMs can appear to reason because they have learned many reasoning-like patterns from data, but they do not explicitly apply formal rules or reliably track contradictions. This works well for familiar cases but can fail on novel or complex multi-step problems. The chapter argues that building reasoning methods from scratch is valuable because it reveals how these systems work, when they are useful, and what trade-offs they introduce, including higher cost, longer outputs, extra model calls, and possible overthinking. The book’s roadmap begins with a conventional LLM, adds evaluation methods, then improves reasoning through inference techniques and additional training.

A simplified illustration of how a conventional, non-reasoning LLM might respond to a question with a short answer.
A simplified illustration of how a reasoning LLM might tackle a multi-step reasoning task using a chain-of-thought. Rather than just recalling a fact, the model combines several intermediate reasoning steps to arrive at the correct conclusion. The intermediate reasoning steps may or may not be shown to the user, depending on the implementation.
Overview of a typical LLM training pipeline. The process begins with an initial model initialized with random weights, followed by pre-training on large-scale text data to learn language patterns by predicting the next token. Post-training then refines the model through instruction fine-tuning and preference fine-tuning, which enables the LLM to follow human instructions better and align with human preferences.
Example responses from a language model at different training stages. The prompt asks for a summary of the relationship between sleep and health. The pre-trained LLM produces a relevant but unfocused answer without directly following the instructions. The instruction-tuned LLM generates a concise and accurate summary aligned with the prompt. The preference-tuned LLM further improves the response by using a friendly tone and engaging language, which makes the answer more relatable and user-centered.
Three approaches commonly used to improve reasoning capabilities in LLMs. These methods (inference-compute scaling, reinforcement learning, and distillation) are typically applied after the conventional training stages (initial model training, pre-training, and post-training with instruction and preference tuning), but reasoning techniques can also be applied to the pre-trained base model.
Contradictory premises lead to a logical inconsistency. From "All birds can fly" and "A penguin is a bird," we infer "Penguin can fly." This conclusion conflicts with the established fact "Penguin cannot fly," which results in a contradiction.
An illustrative example of how a language model (GPT-4o in ChatGPT) appears to "reason" about a contradictory premise.
Token-by-token generation in an LLM. At each step, the LLM takes the full sequence generated so far and predicts the next token, which may represent a word, subword, or punctuation mark depending on the tokenizer. The newly generated token is appended to the sequence and used as input for the next step. This iterative decoding process is used in both standard language models and reasoning-focused models.
A high-level roadmap of what we build in this book. We start with a conventional LLM, add evaluation methods so that we can measure progress, and then explore two broad families of reasoning improvements, namely, inference techniques and training techniques.
A detailed roadmap of the chapter-level substeps. After loading the base model, we cover benchmark-based and judgment-based evaluation, then inference-time methods such as advanced text generation and voting plus self-refinement, and finally training-time methods based on reinforcement learning and distillation.

Summary

  • Conventional LLM training occurs in several stages:
    • Pre-training, where the model learns language patterns from vast amounts of text.
    • Instruction fine-tuning, which improves the model's responses to user prompts.
    • Preference tuning, which aligns model outputs with human preferences.
  • Reasoning methods are applied on top of a conventional LLM.
  • Reasoning in LLMs refers to improving a model so that it explicitly generates intermediate steps (chain-of-thought) before producing a final answer, which often increases accuracy on multi-step tasks.
  • Reasoning in LLMs is different from rule-based reasoning and it also likely works differently than human reasoning; currently, the common consensus is that reasoning in LLMs relies on statistical pattern matching.
  • Pattern matching in LLMs relies purely on statistical associations learned from data, which enables fluent text generation but lacks explicit logical inference.
  • Improving reasoning in LLMs can be achieved through:
    • Inference-time compute scaling, enhancing reasoning without retraining (e.g., chain-of-thought prompting).
    • Reinforcement learning, training models explicitly with reward signals.
    • Supervised fine-tuning and distillation, using examples from stronger reasoning models.
  • Building reasoning models from scratch provides practical insights into LLM capabilities, limitations, and computational trade-offs.

FAQ

What does “reasoning” mean in the context of LLMs?

In this chapter, reasoning is used in a practical engineering sense: an LLM generates intermediate steps before producing a final answer. These steps may be visible to the user as a step-by-step explanation or hidden inside special tags such as <think>...</think>.

What is a reasoning model?

A reasoning model is an LLM that has been improved, through training or prompting techniques, to produce intermediate problem-solving steps. This often improves accuracy on complex tasks such as math problems, coding tasks, and logical puzzles.

What is chain-of-thought reasoning?

Chain-of-thought, or CoT, refers to a style of generation where the model works through a problem step by step before giving a final answer. Engineers often describe this as the model “thinking” through the problem, but this does not mean that LLMs think or reason in the same way humans do.

How is LLM reasoning different from traditional symbolic reasoning?

Traditional symbolic reasoning systems, such as theorem provers or logic engines, follow explicit rules and can produce deterministic, logically guaranteed results. LLMs, by contrast, generate text autoregressively by predicting one token at a time based on statistical patterns. Their reasoning steps may look convincing, but they are not guaranteed to be logically sound.

What are the main stages in the standard LLM training pipeline?

Conventional LLM training usually has two major stages: pre-training and post-training. During pre-training, the model learns to predict the next token from massive text datasets. During post-training, techniques such as supervised fine-tuning and preference tuning help the model follow instructions and produce responses that better match human preferences.

What is the difference between pre-training and post-training?

Pre-training teaches the model general language patterns through next-token prediction on large-scale text data. Post-training refines the model so it can better respond to user instructions. This includes instruction tuning, also called supervised fine-tuning, and preference tuning, often implemented with methods such as reinforcement learning with human feedback.

What are the three broad approaches to improving reasoning in LLMs?

The chapter groups reasoning-improvement methods into three categories: inference-time compute scaling, reinforcement learning, and distillation. Inference-time compute scaling improves performance without changing model weights. Reinforcement learning updates the model through reward signals. Distillation transfers reasoning behavior from a larger or stronger model into a smaller or more efficient one.

How does inference-time compute scaling improve reasoning?

Inference-time compute scaling improves reasoning during inference, when the user prompts the model, without modifying the underlying model weights. It trades additional computation for better performance using methods such as chain-of-thought prompting, sampling multiple answers, voting, or self-refinement.

How does pattern matching differ from logical reasoning in LLMs?

Pattern matching means the model completes text based on statistical associations learned during training. For example, answering “Berlin” to “The capital of Germany is…” reflects a strong learned association. Logical reasoning, in contrast, involves systematically deriving conclusions from premises using rules and recognizing contradictions or implications.

Why build reasoning models from scratch?

Building reasoning models from scratch helps reveal how reasoning methods actually work and what trade-offs they introduce. Reasoning models can be powerful for complex math, coding, planning, and agent tasks, but they can also be more expensive, slower, more verbose, and sometimes prone to overthinking. Implementing the methods directly makes it easier to understand when reasoning machinery is worth using.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free