rasbt/reasoning-from-scratch
rasbt/reasoning-from-scratch has 5,815 GitHub stars and 939 forks. GitHot measured +38 in 7 days. Last checked 2026-11-11 04:13 UTC. Last push 2026-11-02.
PyTorch로 추론형 LLM을 처음부터 단계별로 구현
측정된 스타 증가
- in 24h
- 업데이트 지연
- in 7 days
- +38
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalBuild A Reasoning Model (From Scratch)
This repository contains the code for developing an LLM reasoning model and is the official code repository for the book Build a Reasoning Model (From Scratch).
(Printed in color.)
In Build a Reasoning Model (From Scratch), you will learn and understand how a reasoning large language model (LLM) works.
Reasoning is one of the most exciting and important recent advances in improving LLMs, but it’s also one of the easiest to misunderstand if you only hear the term reasoning and read about it in theory. This is why this book takes a hands-on approach. We will start with a pre-trained base LLM and then add reasoning capabilities ourselves, step by step in code, so you can see exactly how it works.
The methods described in this book walk you through the process of developing your own small-but-functional reasoning model for educational purposes. It mirrors the approaches used in creating large-scale reasoning models such as DeepSeek R1, GPT-5 Thinking, and others. In addition, this book includes code for loading the weights of existing, pretrained models.
- Link to the official source code repository
- Link to the book at Manning (the publisher's website)
- Link to the book page on Amazon.com
- ISBN 9781633434677
To download a copy of this repository, click on the Download ZIP button or execute the following command in your terminal:
git clone --depth 1 https://github.com/rasbt/reasoning-from-scratch.git
Tip: Chapter 2 provides additional tips on installing Python, managing Python packages, and setting up your coding environment.
Table of Contents
| Chapter Title | Main Code |
|---|---|
| Ch 1: Understanding reasoning Models | No code |
| Ch 2: Generating Text with a Pre-trained LLM | - ch02_main.ipynb - ch02_exercise-solutions.ipynb |
| Ch 3: Evaluating Reasoning Models | - ch03_main.ipynb - ch03_exercise-solutions.ipynb |
| Ch 4: Improving Reasoning with Inference-Time Scaling | - ch04_main.ipynb - ch04_exercise-solutions.ipynb |
| Ch 5: Inference-Time Scaling via Self-Refinement | - ch05_main.ipynb - ch05_exercise-solutions.ipynb |
| Ch 6: Training Reasoning Models with Reinforcement Learning | - ch06_main.ipynb - ch06_exercise-solutions.ipynb |
| Ch 7: Improving GRPO for Reinforcement Learning | - ch07_main.ipynb - ch07_exercise-solutions.ipynb |
| Ch 8: Distilling Reasoning Models for Efficient Reasoning | - ch08_main.ipynb - ch08_exercise-solutions.ipynb |
| Appendix A: References and Further Reading | No code |
| Appendix B: Exercise Solutions | Code and solutions are in each chapter's subfolder |
| Appendix C: Qwen3 LLM Source Code | - chC_main.ipynb |
| Appendix D: Using larger LLMs | - chD_main.ipynb |
| Appendix E: Batching and throughput-oriented execution | - chE_main.ipynb |
| Appendix F: Common Approaches to LLM Evaluation | - chF_main.ipynb |
| Appendix G: Building a Chat Interface | - chG |
The mental model below summarizes the main techniques covered in this book.

Companion Book
Please note that Build A Reasoning Model (From Scratch) is a standalone book focused on methods to improve LLM reasoning.
In this book, we work with a pre-trained open-source base LLM (Qwen3) on top of which we code apply reasoning methods from scratch. This includes inference-time scaling, reinforcement learning, and distillation.
However, if you are interested in understanding how a conventional base LLM is implemented, you may like my previous book, Build a Large Language Model (From Scratch).
Hardware Requirements
The code in the main chapters of this book is designed to mostly run on consumer hardware within a reasonable timeframe and does not require specialized server hardware. This approach ensures that a wide audience can engage with the material. Additionally, the code automatically utilizes GPUs if they are available. That being said, chapters 2-4 will work well on CPUs and GPUs. For chapters 5 and 6, it is recommended to use a GPU if you want to replicate the results in the chapter.
(Please see the setup_tips doc for additional recommendations.)
Exercises
Each chapter of the book includes several exercises. The solutions are summarized in Appendix B, and the corresponding code notebooks are available in the main chapter folders of this repository (for example, ch02/01_main-chapter-code/ch02_exercise-solutions.ipynb).
Bonus Material
Several folders contain optional materials as a bonus for interested readers:
- Chapter 2: Generating Text with a Pre-trained LLM
- Chapter 3: Evaluating LLMs
- MATH-500 Verifier Scripts
- Advanced Parser (hybrid LaTeX parser)
- Chapter 4: Improving Reasoning with Inference-Time Scaling
- Inference Scaling on MATH-500 (CoT prompting, self-consistency)
- Chapter 5: Inference-Time Scaling Via Self-Refinement
- More Inference Scaling on MATH-500 (Best-of-N, self-refinement)
- Chapter 6: Training Reasoning Models with Reinforcement Learning
- GRPO scripts with a batched mode
- Chapter 7: Improving GRPO for Reinforcement Learning
- Advanced GRPO scripts (including DeepSeek-V3.2-, Olmo3-, and GDPO-style training)
- Download training checkpoints (how to download and use the chapter 6 and 7 GRPO checkpoints)
- Chapter 8: Distilling Reasoning Models for Efficient Reasoning
- Generate distillation data (teacher-output generation via Ollama or OpenRouter)
- Train with distillation (including single-example and batched distillation scripts)
- Download training checkpoints (how to download and use the chapter 8 distillation checkpoints)
- Use Qwen3 with Hugging Face (how to use the base model and chapter 6-8 checkpoints with
transformers)
- Appendix F: Common Approaches to LLM Evaluation
- Appendix G: Building a Chat Interface
Questions, Feedback, and Contributing to This Repository
For common problems, please see the Troubleshooting Guide.
I welcome all sorts of feedback, best shared via the Manning Discussion Forum or GitHub Discussions. Likewise, if you have any questions or just want to bounce ideas off others, please don't hesitate to post these in the forum as well.
Please note that since this repository contains the code corresponding to a print book, I currently cannot accept contributions that would extend the contents of the main chapter code, as it would introduce deviations from the physical book. Keeping it consistent helps ensure a smooth experience for everyone.
Citation
If you find this book or code useful for your research, please consider citing it.
Chicago-style citation:
Raschka, Sebastian. Build A Reasoning Model (From Scratch). Manning, 2025. ISBN: 9781633434677.
BibTeX entry:
@book{build-llms-from-scratch-book,
author = {Sebastian Raschka},
title = {Build A Reasoning Model (From Scratch)},
publisher = {Manning},
year = {2025},
isbn = {9781633434677},
url = {https://mng.bz/lZ5B},
github = {https://github.com/rasbt/reasoning-from-scratch}
}
관련 프로젝트 살펴보기
tensorflow/tensorflow
모두를 위한 오픈소스 머신러닝 프레임워크
201,427 스타huggingface/transformers
🤗 Transformers: 텍스트, 비전, 오디오, 멀티모달 분야의 최첨단 머신러닝 모델을 위한 모델 정의 프레임워크로, 추론과 학습을 모두 지원합니다.
168,711 스타AUTOMATIC1111/stable-diffusion-webui
Stable Diffusion 웹 UI
165,289 스타Comfy-Org/ComfyUI
그래프와 노드로 구성된 인터페이스를 갖춘, 가장 강력하고 모듈성이 뛰어난 확산 모델 GUI, API, 백엔드입니다. 세계에서 가장 빠른 로컬 추론 엔진입니다.
146,271 스타
