hands-on-modern-rl README

The project's README from github.com/walkinglabs/hands-on-modern-rl. As one markdown file: README.md.

Hands-On Modern RL

From Markov decision processes and policy optimization to reasoning models, agents, and multimodal systems

Online Course PDF Download CC BY-NC-SA 4.0 License Node >= 18 VitePress

English · 中文

Train on ModelScope · Run the CartPole Notebook · ModelScope Script

Discussion Group (WeChat)

Book Features · About This Book · News · Contents · Book Structure · Experiment Code · Quick Start · Contributing

📣 Announcement

We sincerely thank everyone for your support of this tutorial! A new version is coming soon. Many sections are still being organized and refined, so we appreciate your patience. Suggestions and feedback are always welcome!

News

Note: This course was created with AI assistance and has not yet been fully reviewed. It may contain factual mistakes or code that does not run as expected. Issues and pull requests are very welcome.

Online Training Notebooks

WalkingLab is collaborating with ModelScope to provide online training environments for classic reinforcement learning experiments. A ModelScope Studio brings the experiment interface, runtime, and training entry point together on one page, so learners can start training in a browser and observe the agent without first configuring a local environment.

Every Studio has a companion notebook under code/online-experiments. The notebook imports the same training runtime as the Studio, exposes the experiment parameters, prints the full training log, plots checkpoint evaluations, and displays the learned-policy replay or result artifact.

Experiment Resource Companion notebook Live Studio
01 · CartPole PPO CPU Run Notebook Open Studio
Gymnasium Playground CPU Run Notebook Open Studio
02 · ViZDoom CPU Run Notebook Open Studio
03 · Atari / ALE xGPU Run Notebook Open Studio
04 · Board Games & Self-Play CPU Run Notebook Open Studio
05 · Multi-Agent Games CPU Run Notebook Open Studio
06 · MiniGrid Adventures CPU Run Notebook Open Studio
07 · JAX MinAtar CPU Run Notebook Open Studio
08 · ManiSkill xGPU Run Notebook Open Studio
10 · MineStudio / Minecraft xGPU Run Notebook Open Studio
11 · Unity ML-Agents xGPU Run Notebook Open Studio
12 · AI2-THOR xGPU Run Notebook Open Studio

CPU entries run on an ordinary notebook instance. Experiments 03, 08, 10, 11, and 12 require a scheduled ModelScope xGPU Notebook and check CUDA before training.

Book Features

Course learning map screenshot
One continuous learning path
Begin with a CartPole trial and progress through value learning, policy optimization, and modern agents.
PPO code focus screenshot
Equations meet code
Key PPO, DPO, and GRPO derivations sit beside their implementations, with every tensor accounted for.
CartPole training metrics screenshot
Claims tested by experiments
Real training curves, ablations, and failure signals show when an algorithm works and when it does not.
RLHF pipeline screenshot
Classic RL to language models
Policy gradients and PPO lead naturally into RLHF, DPO, GRPO, and RLVR.
Agentic RL experiment page screenshot
Agents as sequential decisions
Tool use, browser interaction, and code repair become problems of states, actions, trajectories, and credit assignment.
Atari Pong DQN experiment page screenshot
Phenomena before abstractions
CartPole, LunarLander, Atari, and LLM experiments pose the problem before introducing the mathematics.

[!NOTE] We hope this open course gives more learners the courage to climb toward the frontier of intelligence and solve more of the hard problems on the path to AGI.

The course is evolving quickly. We recommend focusing on chapters that are not marked as under construction; chapters still in progress may contain mistakes, and corrections or suggestions are welcome.

Help Wanted

Because compute resources are limited, we are seeking GPU support. If you can help with GPU access, please contact [email protected].

Contents

About This Book

Reinforcement learning studies a simple but difficult problem: a system acts, observes the consequences, and uses them to improve its next action. When rewards arrive late, observations are incomplete, and each update changes the distribution of future experience, the familiar supervised-learning model of inputs and labels is no longer enough. We need a language for interaction, a way to estimate long-term return, and methods that improve a policy stably from limited data.

Hands-On Modern RL follows that problem from beginning to end. CartPole and multi-armed bandits first make states, actions, rewards, and policies observable. Markov decision processes, value functions, and Bellman equations then provide a common language. From there, the book develops DQN, policy gradients, actor-critic methods, PPO, continuous control, and offline reinforcement learning. With those foundations in place, RLHF, DPO, GRPO, and RLVR become extensions of the same sequential-decision framework rather than an isolated collection of acronyms.

The second half expands the environment to tools, browsers, code repositories, vision, and audio. An action may be a passage of text, a function call, or a sequence of interface operations. A reward may come from human preference, a rule-based verifier, or a process reward model. The setting changes, but three questions run through the entire book: How should the decision process be represented? How should an outcome be credited to earlier actions? How can we tell whether a policy has actually improved?

How the Material Is Taught

Each chapter follows a problem–method–experiment–reflection rhythm. A concrete task first exposes the difficulty. The concepts and equations needed to solve it come next. Runnable code, training curves, and evaluation metrics then test the argument. The chapter closes by examining assumptions, failure modes, and the limits of the method. Mathematics explains observed behavior; experiments check the mathematics.

Implementations retain the visible skeleton of each algorithm. Readers can trace trajectory collection, advantage estimation, loss construction, and metric changes—and see how reward hacking, KL drift, entropy collapse, distribution shift, or evaluation leakage can invalidate an apparently successful run.

Who Should Read It

This book is for students, researchers, and engineers with basic machine-learning experience who want a systematic understanding of modern reinforcement learning. Readers should be comfortable with Python and basic PyTorch, and should know introductory linear algebra, probability, and calculus. The mathematical appendices rebuild these tools to the depth required by the chapters, so a separate advanced-mathematics sequence is not a prerequisite.

After completing the core chapters and labs, you should be able to:

Current Status

This repository is an active courseware project. Content is being expanded chapter by chapter, with emphasis on correctness, runnable examples, and a stable learning path.

Issues and pull requests are welcome for typo fixes, conceptual corrections, reproducibility improvements, references, and focused course extensions.

Roadmap

The course is under active development. Planned milestones:

Structure of the Book

The book contains seven parts and twenty-six chapters. Parts I–III establish the common language and algorithmic foundations of reinforcement learning. Part IV brings those tools into LLM post-training. Parts V and VI study what changes when the action space expands to tools and multimodal environments. Part VII asks how to detect failures, build trustworthy evaluations, and move the research frontier forward. The appendices provide implementation, mathematics, and engineering references.

Prologue: From Trial and Error to Modern Agents

Reading Central question
Introduction to Reinforcement Learning What does RL study, and how does the book connect classical methods to modern language models?
A History of Reinforcement Learning How did control, TD learning, DQN, AlphaGo, RLHF, and reasoning models develop?
Environment Setup How do you prepare the environments for documentation, control tasks, and LLM experiments?

Part I: The Language of Sequential Decisions

The book first makes an agent's failures and improvements observable, then develops the mathematical objects needed to describe long-term decisions.

Ch. Topic Through line
1 Starting with CartPole Use states, actions, rewards, policies, and training curves to see a complete RL loop.
2 RL Problems and Definitions Move from exploration and exploitation to MDPs, returns, trajectories, and partial observability.
3 Value Functions and Bellman Equations Express how a present action changes the future through state values, action values, and recursion.
4 Classical RL Methods Compare dynamic programming, Monte Carlo, and tempor

hands-on-modern-rl (walkinglabs/hands-on-modern-rl)

Searching Database…

这是什么?Hands-On Modern RL 是一门开源课程兼图书,带领学习者从基础的强化学习概念出发,经过大语言模型对齐(RLHF、DPO、GRPO、RLVR),一直学到高级智能体系统,理论配有可运行的代码。
这是一本书、一门课程,还是一个代码库?它主要是一个按章节组织的图书/课程网站(用 VitePress 构建),配有可运行的实验代码和 notebook,而不是一个可安装的库。
怎么开始学习并运行实验?在课程网站上阅读各章节,然后运行 code/online-experiments 下配套的 Jupyter notebook,或者在浏览器里打开配套的 ModelScope Studio,无需本地配置即可训练。
开始之前需要哪些基础知识和工具?你应该熟练使用 Python 和基础 PyTorch,了解线性代数、概率论和微积分的入门内容;部分实验还需要通过 ModelScope 使用 GPU。
内容已经完成且可靠吗?这门课程是在 AI 辅助下持续创作中的作品,尚未完全审校,因此部分章节可能仍有事实错误或无法运行的代码,还有几章被标记为建设中。
这门课程面向谁?面向有一定机器学习基础、想系统且动手地理解现代强化学习及其在大语言模型和智能体方向延伸的学生、研究者和工程师。
在哪里可以运行训练实验?纯 CPU 的实验在普通 notebook 实例中即可运行,而重度依赖 GPU 的实验(Atari/ALE、ManiSkill、Minecraft、Unity ML-Agents、AI2-THOR)需要一个预约的、配备 CUDA 的 ModelScope xGPU Notebook。
这本书的结构是怎样的?全书共七部分二十六章:从经典强化学习基础(第 I-III 部分)讲到大语言模型后训练如 RLHF/DPO/GRPO(第 IV 部分),再到工具使用、多模态与具身智能体(第 V-VI 部分),最后是评估与失败分析(第 VII 部分),另附数学和工程附录。
这门课程有英语以外的语言版本吗?有。除了完整的英文版之外还有完整的中文版,两个版本的 PDF 都通过 CI 自动生成。
这与只读一本强化学习教材有什么不同?每个算法(DQN、PPO、DPO、GRPO 等)都配有可运行的代码、真实的训练曲线,以及奖励劫持或熵坍缩之类的失效模式分析,结论都经过实验验证,而不只是数学推导。
不做任何本地配置也能尝试实验吗?可以。每个实验都有一个在线 ModelScope Studio,在浏览器里打开就能立即训练并观察智能体,此外还有配套 notebook。
Size
153 MB
Stars
4.7K
Age
6mo
Commits · 90 Days