Build a Reasoning Model (From Scratch)
by Sebastian Raschka / Manning
Implement inference-time scaling, GRPO and distillation by hand in PyTorch, starting from a plain pre-trained LLM.
Overview
Raschka applies the method that made his previous book a bestseller: no wrapper libraries, just Python and PyTorch, with every mechanism implemented by hand so you can see what it does. The book runs to 440 pages printed in colour, across eight chapters and seven substantial appendixes (ISBN 9781633434677, Manning). Chapter 1 defines what a reasoning model actually is and how it differs from a well-prompted base model. Chapter 2 loads a pre-trained LLM and builds text generation with KV caching. Chapter 3 constructs the evaluation harness — deliberately placed before any technique is introduced, so every later improvement is measured rather than asserted. Chapter 4 covers inference-time scaling: chain-of-thought prompting, sampling strategies, self-consistency and best-of-N. Chapter 5 adds self-refinement. Chapters 6 and 7 move to training-based methods, implementing GRPO reinforcement learning from scratch and then the refinements that make it stable in practice. Chapter 8 covers distilling a large reasoning model's behaviour into a smaller one. The companion repository, rasbt/reasoning-from-scratch, carries a main notebook plus exercise solutions for every chapter under Apache-2.0 and has passed 5,000 stars. The code is deliberately sized for consumer hardware: chapters 2 through 4 run acceptably on a CPU, and only the RL chapters really want a GPU.
At a Glance
- Topic
- Fine-Tuning
- Level
- Intermediate
- Format
- Book
- Cost
- Paid
- Duration
- 440 pages across 8 chapters and 7 appendixes — roughly 25-35 hours if you run the notebooks alongside
- Provider
- Sebastian Raschka / Manning
- Hands-on
- Yes — code/exercises
- Certificate
- None
What You’ll Learn
- ✓Implement text generation and KV caching from scratch on top of a pre-trained LLM
- ✓Build an evaluation harness for reasoning tasks before adding any reasoning technique
- ✓Apply inference-time scaling methods including chain-of-thought, self-consistency and best-of-N sampling
- ✓Write a self-refinement loop where the model critiques and revises its own output
- ✓Implement GRPO reinforcement learning by hand and understand each term in the objective
- ✓Apply the stability refinements that make GRPO training actually converge in practice
- ✓Distil a large reasoning model's behaviour into a smaller, cheaper student model
Highlights
- •Everything is implemented from scratch in PyTorch — no TRL, no verl, no framework hiding the algorithm
- •Evaluation is built in Chapter 3, before any technique, so improvements are measured not claimed
- •Companion repo has 5,000+ stars with per-chapter notebooks and exercise solutions under Apache-2.0
- •Code is sized for a laptop: chapters 2-4 run on CPU, only the RL chapters want a GPU
- •Written by the author of the bestselling Build a Large Language Model (From Scratch), so the pedagogy is proven
Who It’s For
Best For
- ✓Engineers who want to understand GRPO and inference-time scaling at the implementation level
- ✓Readers who finished Build a Large Language Model (From Scratch) and want the next step
- ✓ML practitioners deciding whether to fine-tune for reasoning or just prompt harder
Prerequisites
- •Solid Python, and comfort reading and modifying PyTorch training code
- •Basic machine learning knowledge — gradients, loss functions, training loops
- •Helpful but not required: prior exposure to transformer internals, which the book briefly reviews
FAQ
What is Build a Reasoning Model (From Scratch)?
Sebastian Raschka's follow-up to Build a Large Language Model (From Scratch) takes a conventional pre-trained LLM and adds reasoning to it step by step, in plain PyTorch with no black-box libraries. It covers evaluation, inference-time scaling, self-refinement, GRPO reinforcement learning and distillation — the same family of methods behind DeepSeek-R1-style models — with code sized to run on consumer hardware.
Is Build a Reasoning Model (From Scratch) free?
Build a Reasoning Model (From Scratch) is a paid resource.
What level is Build a Reasoning Model (From Scratch) for?
Build a Reasoning Model (From Scratch) is aimed at a intermediate audience. Recommended background: Solid Python, and comfort reading and modifying PyTorch training code, Basic machine learning knowledge — gradients, loss functions, training loops, Helpful but not required: prior exposure to transformer internals, which the book briefly reviews.
How long does Build a Reasoning Model (From Scratch) take?
Expect roughly 440 pages across 8 chapters and 7 appendixes — roughly 25-35 hours if you run the notebooks alongside. Most learners work through it at their own pace.
What will I learn from Build a Reasoning Model (From Scratch)?
You'll learn: Implement text generation and KV caching from scratch on top of a pre-trained LLM; Build an evaluation harness for reasoning tasks before adding any reasoning technique; Apply inference-time scaling methods including chain-of-thought, self-consistency and best-of-N sampling; Write a self-refinement loop where the model critiques and revises its own output; Implement GRPO reinforcement learning by hand and understand each term in the objective; Apply the stability refinements that make GRPO training actually converge in practice; Distil a large reasoning model's behaviour into a smaller, cheaper student model.
Topics
Sources
This page was written from 3 sources, 2 on domains other than manning.com.