@Zen_with_AI: 感恩节放假爱学习的有福了: Raschka 免费 11 小时课,从零手写推理模型 这套视频课,从预训练的 Qwen3 0.6B 出发,用 Python 和 PyTorch 手写推理方法。课程按验证器、推理时扩展、GRPO 强化学习、蒸馏的…
摘要
Sebastian Raschka 发布免费 11 小时视频课程,从预训练 Qwen3 0.6B 出发,用 Python/PyTorch 手写实现验证器、推理时扩展、GRPO 强化学习与蒸馏,完整搭建推理模型管线。
查看缓存全文
缓存时间: 2026/11/22 00:29
感恩节放假爱学习的有福了:
Raschka 免费 11 小时课,从零手写推理模型
这套视频课,从预训练的 Qwen3 0.6B 出发,用 Python 和 PyTorch 手写推理方法。课程按验证器、推理时扩展、GRPO 强化学习、蒸馏的顺序,把整条推理管线搭起来。
https://t.co/KgrrsGZ5UN
Build Your Own Reasoning Model: A Full Video Course
Source: https://magazine.sebastianraschka.com/p/building-reasoning-models I have written a lot about reasoning models here over the last two years on Ahead of AI, including a recent article on mechanisms tocontrol reasoning effort levels in contemporary LLMs. Reasoning models are still as relevant as ever. In fact, almost all current-generation LLMs today are reasoning models or offer a reasoning mode.
For those who are interested in how reasoning models work, including inference scaling, reinforcement learning, and distillation, I wrote my recentBuild Reasoning Model (From Scratch),which implements these from the ground up in PyTorch, which, in my experience, is still the best way to understand and learn how things really work.
Now, in the last few months, I also sat down and recorded accompanying lectures I wanted to share with you. So, below, you will find eight reasoning model-from-scratch coding videos (11 hours of content).
We start with a pre-trained LLM and implement methods to evaluate and improve it in Python and PyTorch. So, if you enjoyed myCoding LLMs from the Ground Upcourse last year, this is essentially the sequel (but you can also watch it without the prior course as a prerequisite).
I’m currently taking a short break and will be back soon with more exciting LLM research roundups next month. In the meantime, I hope you enjoy coding along!
As a small side note, and since I often get asked how reasoning models relate to today’s AI agents, here’s a short section on this before getting started with the videos.
A reasoning model is essentially an upgrade from a conventional LLM, that is, adding more post-training via reinforcement learning with verifiable rewards (and optionally inference scaling techniques) to make it more capable of solving more challenging problems. Classically, reasoning models are developed for math and code, but the capabilities can generalize to other problem domains as well.
A reasoning model then functions as the engine inside an agent harness, where the agent harness is a software or tooling framework around the LLM/reasoning model to tackle even more challenging problems (bigger coding tasks, travel booking, and all other sorts of personal assistant tasks). The task of the harness is sophisticated context management and giving the LLM access to tools.
Figure 1: An engine analogy for conventional LLMs, reasoning models, and agent harnesses. Figure from myComponents of a Coding Agentarticle.
In this analogy depicted in the figure above, the model is the engine, and the agent harness adds the machinery that lets us use it for various things (as an upgrade from a simple chatbot interface). An agent can use either a conventional LLM or a reasoning model, but reasoning models are the more typical choice as they are more capable. (As mentioned above, most current-gen LLMs are reasoning models with variable reasoning effort settings.)
So, the bottom line is that reasoning models, as the “engine,” remain an important part of understanding modern LLM agents.
The resources accompanying these topics shown above are:
- TheBuild a Large Language Model (From Scratch)bookandvideos
- TheBuild A Reasoning Model (From Scratch)book(and videos below)
- TheComponents of a Coding Agentarticleon Substack
The videos below focus on developing the reasoning model that can power such a system.
The reasoning-from-scratch videos focus on a small pre-trained Qwen3 model, where we implement the reasoning methods ourselves in Python and PyTorch. Starting with a pre-trained model lets us focus on the interesting part: evaluation, inference-time scaling, reinforcement learning, and distillation.
Regarding the prerequisites, I recommend being comfortable with Python and PyTorch. I designed the reasoning materials as standalone content, so the previous Build A Large Language Model (From Scratch) content is recommended but not strictly required.
Compute-resource-wise, you can work through the early text-generation and evaluation examples on a CPU. For the later experiments, especially training, a GPU makes the work much more practical. The first video covers the setup and some more recommendations; the repository also includeshardware and environment recommendations.
Figure 2: An overview of the topics being covered.
These videos accompany my book,Build a Reasoning Model (From Scratch). If you like to read through the explanation in more detail and at your own pace, work through exercises, and so on, I recommend the book as a companion here.
For the most in-depth learning experience, my suggestion is to read a chapter, work through its code alongside the corresponding video, and then try the exercises.
The book is available from**ManningandAmazon**, and the print edition is in color!
Figure 3: A random excerpt from theBuild a Reasoning Model (From Scratch)print book.
Thank you to everyone who has picked up a copy or recommended it to a friend. Your support helps me keep creating these materials.
As a last, quick side note before getting to the main videos below: For a shorter, more conceptual overview, I also recommend myAI Reasoning Models course on LinkedIn Learning(it should be free for 24h when accessing it via the link there, which shouldn’t then require a LinkedIn Premium subscription).
The course is about 90 minutes and explains how reasoning models work, covering the main ideas behind inference-time scaling, reinforcement learning, and distillation. It’s a good optional preview if you’d like the main ideas without working through the full implementations below.
To get to the main part of this article, here are the eight main lecture videos.
The first video starts with an explanation of the relationship between conventional LLMs, reasoning models, and agents. Next, the main topic of the video is setting up the coding environment. This includes installing the Python and PyTorch dependencies (with uv), among others. I also discuss hardware choices and common setup issues.
Topics covered
- The relationship between conventional LLMs, reasoning models, and agent harnesses
- On the benefits of learning through code implementations
- The scope of this video series
- Installing Python dependencies
- Choosing hardware and checking CUDA or Apple Silicon support
- Using a remote GPU with VS Code and troubleshooting the environment
Watch video 1·Setup instructions
Before adding reasoning methods in the upcoming videos, we need a working base model. Instead of training it from scratch, since that would be a whole other book (seeBuild A Large Language Model (From Scratch)), we start with a pre-trained model.
Here, we load the pre-trained weights of a Qwen3 0.6B model. Then, we implement the text-generation process via a streaming text generator and add KV caching and model compilation to make text generation more efficient.
These implementations give us the baseline and base components we will evaluate and improve in the following videos.
Topics covered
- Encoding text as tokens and decoding it back into text
- Downloading Qwen3 weights and loading the model on the selected compute device
- Going over tensor shapes, logits, and next-token predictions
- Implementing greedy decoding and streaming text generation
- Handling end-of-sequence tokens and measuring generation speed
- Adding a KV cache to reuse attention keys and values
- Combining KV caching with
torch\.compileand comparing hardware performance
In this lecture, we build a math-answer verifier step by step, from answer extraction to normalization and checking mathematical equivalence. We then use it to evaluate the model on MATH-500.
We use this verifier to evaluate the base model’s performance on the MATH-500 evaluation dataset.
However, the verifier also has a second job later in the series: providing the reward signal for reinforcement learning with verifiable rewards (RLVR).
Topics covered
- Intro to verifiers and how they fit into LLM evaluation methods (other methods are covered in the book’s appendix)
- Reusing answer verification as a reward signal for RLVR (more on that in chapter 6)
- The verifier flow, including extracting final answers, normalizing answers and checking mathematical equivalence
- Building an answer grader and an evaluation loop for MATH-500
- Comparing base and reasoning models on MATH-500
Now we explore ways to improve answers while keeping the model weights fixed. But before implementing specific inference-scaling techniques, we first implement methods to generate diverse answers from the same prompt (this is standard practice in proprietary LLM chatbots, such as ChatGPT).
Concretely, we implement temperature scaling, multinomial sampling, and top-p filtering to generate diverse responses. Then we combine multiple responses through self-consistency, using majority voting over their final answers.
We also examine the tradeoff between answer accuracy and the extra computation needed to generate more candidates.
Topics covered
- Comparing how additional compute benefits model performance during training and during inference
- A gentle intro to inference-scaling through chain-of-thought prompts
- Implementing temperature scaling and multinomial sampling to generate diverse answers
- Adding top-p filtering to control the quality of the diverse answers
- Combining candidate answers through self-consistency, one of the most popular inference scaling techniques
- Evaluating MATH-500 accuracy against the cost of additional inference compute
Building on the previous video, we implement scoring functions to compare multiple answers generated from the same prompt. We can also use these scoring methods to break ties in self-consistency (covered in the previous lecture).
The scoring methods covered here include computing token and sequence log probabilities (this will also be relevant in the later reinforcement learning chapters). We then implement a self-refinement loop in which the model critiques an answer and attempts a revision.
The evaluation lets us check how useful those additional steps are for our model.
Topics covered
- Using scoring functions for comparing multiple answers and breaking ties
- Implementing a simple heuristic scorer
- Computing token probabilities and sequence likelihoods (also relevant for the following lectures)
- Using log probabilities for improved numerical stability
- Building a self-refinement loop for generating critiques and revised answers
- Evaluating self-refinement on MATH-500
In this lecture, we move on to implementing a training technique called Reinforcement Learning with Verifiable Rewards (RLVR). We first implement a simplified version of Group Relative Policy Optimization (GRPO), generate groups of responses, score them with our verifier, and use their relative rewards for the model weight updates during training.
Topics covered
- Generating reasoning traces and understanding the relationship between answer lengths and problem-solving abilities
- Discussion and comparison of two important LLM post-training methods: Reinforcement Learning with Human Feedback (RLHF) and Reinforcement Learning with Verifiable Rewards (RLVR)
- Turning verifier scores into rewards and relative advantages
- Computing sequence log probabilities and a simplified GRPO loss
- Assembling the training loop with logging and checkpoint saves
- Evaluating checkpoints and checking training stability and memory needs
Now that we implemented the training loop in the previous lecture, we can revisit it and analyze the training runs in more detail.
Concretely, this video adds more training metrics for inspection and analysis, including entropy and advantage statistics, clipped policy ratios, KL loss term values, and formatted rewards.
We then review the training logs and evaluation results to understand what these additions do and whether additions such as clipped policy ratios and KL loss terms are helpful.
Topics covered
- Running longer training experiments and interpreting their logs
- Tracking advantages and entropy to understand training behavior
- Implementing clipping in the policy loss and analyzing its effects
- Adding a KL loss term and discussing reward hacking
- Understanding limitations of the simplified KL formulation
- Implementing format rewards and conditioning them on answer correctness
- Comparing checkpoints on MATH-500 and exploring further GRPO research
Finally, we explore another way to train a small reasoning model, that is, learning from answers generated by a stronger (and bigger) teacher model. We discuss different forms of distillation, prepare reasoning data, and implement the supervised training loop.
We finish this lecture and course by evaluating the distilled model on MATH-500 and comparing the results. This rounds out the series with an alternative to developing reasoning capabilities through reinforcement learning.
Topics covered
- Comparing the different combination and approaches to distillation, including soft and hard distillation, and on-policy and off-policy distillation
- Creating and collecting teacher-generated answers for the MATH dataset (using DeepSeek R1)
- Preparing the distillation dataset, including tokenization and training/validation/test splits
- Computing answer-token log probabilities and understanding the cross-entropy loss
- Implementing supervised training and tracking training and validation losses
- Evaluating checkpoints on MATH-500 and comparing distillation results
As you watch these lectures, I encourage you to pause occasionally and try a small experiment of your own if something interesting comes to mind.
For example, feel free to change the sampling settings, inspect a few failed answers, or try variations of different ideas similar to the suggestions in the exercises.
And if you would like the full written walkthrough, figures, and exercises alongside the videos, you can find*Build a Reasoning Model (From Scratch)*atManningandAmazon.
Thanks for reading and supporting Ahead of AI. I am taking a short break to regenerate, and I look forward to being back with the next round of LLM research articles next month.
In the meantime, happy viewing and tinkering!
Discussion about this post
Ready for more?
相似文章
@Zen_with_AI: 跟着 Raschka 手搓推理模型 第 1 期 (新栏目 一共8期) 推理模型不是从零长出来的新物种,是普通大模型多练了一段“后训练”。 Raschka 这门新课一句话点透:推理模型 = 常规 LLM + 可验证奖励的强化学习,再加上推理…
Raschka 推出 8 期新课《跟着 Raschka 手搓推理模型》,从预训练的 Qwen3 0.6B 出发,用 Python/PyTorch 实现评测、推理时扩展、强化学习与蒸馏,共 11 小时,并配套新书《Build a Reasoning Model (From Scratch)》。文章点透推理模型 = 常规 LLM + 可验证奖励的 RL + 推理时扩展,强调引擎(模型)与 agent harness 的关系。
@shao__meng: 9集、230分钟 @jbhuang0604 系列视频「AI Training and Inference」把基座模型训练和推理基础讲清楚了,覆盖整个训推架构:单卡显存 → 千卡并行 → 便宜微调 → 推理加速 → 小模型蒸馏 → 推理 R…
博主分享 Jia-Bin Huang 制作的 9 集、230 分钟系列视频「AI Training and Inference」,系统覆盖基座模型训推架构:从 ZeRO/FSDP 显存优化、五维并行、LoRA 变体、投机解码、On-policy 蒸馏、GRPO 强化学习,到 AdamW/Muon 优化器及 LLM 服务。
@0xQiYan: 花 15,000 美元上个AI速成营?不如把这份免费清单收好。30 天,学到的东西只多不少。 1. 3Blue1Brown—— 用最直观的动画,把 ChatGPT 背后的数学原理拆给你看。看不懂神经网络?看完就懂了。 → https://…
推荐10个免费的AI学习资源,包括3Blue1Brown、Karpathy的课程、Andrew Ng的周刊、播客、Kaggle和Hugging Face等,声称30天可学到比付费速成营更多的内容。
Sebastian Raschka 从零构建推理模型的视频课程
Sebastian Raschka 发布了一套时长 11 小时、共 8 个视频的课程,讲解如何在 PyTorch 中从零构建推理模型,涵盖评估、推理扩展、基于可验证奖励的强化学习以及知识蒸馏等内容,是其此前《Coding LLMs from the Ground Up》课程的续作。
@Zen_with_AI: ML 铅笔手稿 第 30 期 主题:推理时扩展——答题时多想几步,有时比换个更大的脑子管用 上期的问题:第 29 期讲 RL——R1 不靠教师示范,直接在基座模型上跑 GRPO,AIME 2024 pass@1 从 15.6% 涨到 71…
第 30 期《ML 铅笔手稿》讲解推理时扩展(test-time compute / inference scaling):通过自洽性投票、Best-of-N 加验证器、树搜索加过程奖励模型等方法,让同一模型在答题时多想几步,难题上甚至能胜过 14 倍大的模型。