← all repositories
rasbt/reasoning-from-scratch

Turning a base LLM into a reasoner, with code and no hype

To demystify reasoning LLMs by coding inference-time scaling, RL, and distillation on top of a pretrained model, step by step.

4.8k stars Jupyter Notebook Language ModelsML FrameworksLearning
reasoning-from-scratch
Velocity · 7d
+7.9
★ / day
Trend
accelerating
star history

What it does

This is the companion code for Sebastian Raschka’s book Build a Reasoning Model (From Scratch). It takes a pretrained open-source Qwen3 model and layers on reasoning techniques—chain-of-thought prompting, self-consistency, self-refinement, GRPO reinforcement learning, and distillation—using PyTorch in Jupyter notebooks. The goal is educational transparency: you see exactly how these methods work rather than reading about them in theory.

The interesting bit

Most explanations of reasoning LLMs stay theoretical. This repo takes the opposite approach, implementing inference-time scaling and GRPO training loops from scratch so you can watch the model learn to verify its own math answers. It even includes batched GRPO scripts and distillation pipelines that mirror the training regimes of production-grade reasoning models.

Key highlights

  • Starts from a pretrained Qwen3 base and adds reasoning capabilities incrementally
  • Covers inference-time scaling (CoT, self-consistency, Best-of-N, self-refinement) and training-time methods (GRPO, distillation)
  • Includes advanced GRPO variants inspired by DeepSeek-V3.2, Olmo3, and GDPO training styles
  • Most main chapters run on consumer hardware; GPU recommended only for chapters 5–6
  • Provides MATH-500 evaluation scripts, hybrid LaTeX parsers, and a chat interface appendix

Caveats

  • The repository is locked to the print book’s contents, so pull requests extending the main chapter code are not accepted
  • It is explicitly a small-but-functional educational implementation, not a production framework

Verdict

Worth bookmarking if you are a practitioner or student who wants to understand why reasoning models work rather than just that they work. Skip it if you are looking for a production training framework rather than an educational dissection.

Frequently asked

What is rasbt/reasoning-from-scratch?
To demystify reasoning LLMs by coding inference-time scaling, RL, and distillation on top of a pretrained model, step by step.
Is reasoning-from-scratch open source?
Yes — rasbt/reasoning-from-scratch is open source, released under the Apache-2.0 license.
What language is reasoning-from-scratch written in?
rasbt/reasoning-from-scratch is primarily written in Jupyter Notebook.
How popular is reasoning-from-scratch?
rasbt/reasoning-from-scratch has 4.8k stars on GitHub and is currently accelerating.
Where can I find reasoning-from-scratch?
rasbt/reasoning-from-scratch is on GitHub at https://github.com/rasbt/reasoning-from-scratch.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.