Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

RL in the Age of LLMs

TLDR

A Home Cook’s Guide to RL

Learning to bake a cake is a fun afternoon’s activity, and this is the vibe of this section of the guidebook. Each tutorial is a self contained recipe with an entire implementation of the algorithm and a verbal explanation, all built on an LLM you can train yourself -- on a laptop.

Generated by Gemini Nano Banana which is trained in part by Reinforcement Learning.

Figure 1:Generated by Gemini Nano Banana which is trained in part by Reinforcement Learning.

This section contains:

Every piece of terminology is introduced in this guide and runs on a single laptop, so we can keep this guide largely self contained and minimal. Here’s how it contrasts with other sources out there.

From Research Papers

Imagine trying to learn how to bake a cake by reading Water Absorption Capacity Determines the Functionality of Vital Gluten Related to Specific Bread Volume. Research papers are important, but they are written for other researchers, not practitioners looking to learn fundamentals.

From Production Code Libraries

There are already great code libraries for RL out there, but they’re written for computational efficiency at scale. This means the core ideas are abstracted.

Not the best place to learn how to bake a loaf of bread.

Figure 2:Not the best place to learn how to bake a loaf of bread.

It’s like trying to learn how to bake a loaf at a production volume bread factory -- good luck separating the bread recipe from all the considerations made for large scale baking! And you’ll waste a lot of money if you’re learning by tweaking the formula in this setting.

From General Reinforcement Learning Guides

General reinforcement learning guides cover the basics that apply to all recipes, bread, pies, cakes, pizzas, basically anything that is baked. You should still read them, but here we want to focus on just how RL is applied to modern LLMs.

Who Should Read this and Why

This is for three types of people:

  1. Those curious about how RL shapes LLMs and want to see how the sausage is made, not just read a text description.

  2. Applied folks training LLMs that need a deeper understanding of how to use existing LLM libraries and interpret their outputs.

  3. Future LLM RL developers and researchers that want a bridge to the more complicated papers and code out there.

The challenge is learning LLM RL is the ideas are spread across decades of research and many domains. LLM specific libraries are often production grade, which means the core logic is hidden behind APIs, or designed to optimize computational throughput, and not written for human learning.

Our Learning Trajectory

All of this is why I wrote this practitioner’s guide to RL for LLMs. I showcase the most widely used RL algorithms for LLM post training, that actually shape LLMs’ behavior.

We’ll cover the absolute basics RL with IceMaze to ensure the fundamentals are understood, and then we’ll start implementing RL on a tiny LLM. Papers and YouTube videos have their place, but they give you the end product, without the messy intermediate parts (which actually represent the majority of the actual work). By contrast, actually playing with working code yourself will give you the deepest understanding.

What Is Omitted

To make this a home cooking guide, here’s what we left out:

How to Read this Guide

Again, this guide is meant to be more than a static set of words and code files. Take the content here as a guide and make it your own.

In particular:

Use NotebookLM and other LLMs

Using NotebookLM, you can read, listen, watch, generate flash cards, or even quiz yourself on the content! I’ve preloaded a NotebookLM instance for you. I encourage you to also add in your own sources and notes, such as the references provided throughout this guidebook.

A NotebookLM preloaded with this RL Guidebook to speed up your learning.

Figure 3:A NotebookLM preloaded with this RL Guidebook to speed up your learning.

I also provide suggested prompts in each section. These prompts are meant to help you find supporting information for the content, or push your understanding one step further. More holistically though, they are encouragement for you to read beyond this guidebook into the areas that are of most interest to you.

Contributions Welcome!

If you see any issues or have suggestions open an issue or pull request!

Suggested Prompts

References

These are the more concise references for the field as a whole that I could find. If you’re looking to dive in more deeply, I recommend these rather than piecing the knowledge together yourself.

General RL

LLM Specific

Written On My Own

As with the rest of the guidebook this is written entirely on my own without involvement from any other organization.