I pieced together this first-principles no RL prerequisites...

@ShashwatGoel7
Shashwat Goel@ShashwatGoel7
20 views Feb 21, 2025 ~5 min read
Advertisement
1
I pieced together this first-principles no RL prerequisites explainer on how RL for LLMs works, and why we need it🧵

The main point? RL is exciting because it allows us to scale supervision. We can now learn from just rewards instead of demonstrations. Lets use this framing...
Media image
2
First, what limitations of pretraining on the internet do we wish to solve?
1. The model doesnt chat or answer questions, it outputs the most likely next token.
2. The avg human on the internet is often wrong.
3. Expert reasoning data is underrepresented.
4. Data might run out
Media image
3
Idea 1: Supervised FineTuning (SFT) on human written responses to prompts, let us call this a "golden dataset". We continue using the same next token prediction loss, but on curated demonstrations from annotators.

This can teach the model to chat and answer. However...
Media image
4
It is expensive and slow to get people (especially experts) to write long reasoning chains.

In other words, SFT on human demonstrations doesn't allow scaling data.
Media image
5
Idea 2: SFT with Rejection Sampling. We let the model generate Chain of Thought responses to prompts. We ask humans to pick the best responses, and then train the model to produce these more with SFT.

As rating preferences is easier than generation, this can scale. However...
Media image
6
After 1 round of SFT on top responses, your LLM will improve. But there's still a long way to go. We could generate responses to harder prompts and get human annotations again...

But this doesnt allow scaling iterations :)
Media image
7
Idea 3: Reward Models.
We can automate human annotation by training another model to mimic them. Now we can keep doing rounds of
(generation -> rating -> SFT on top responses) x ♾️

That's too good to be true. Why...
Media image
8
The reward model was still trained on human preferences over the original model’s outputs. The updated model's outputs will soon be out of distribution, and then the reward model doesn't generalize too well... Reward hacking ensues!
Media image
9
Idea 4: Ground-truth rewards.
For code generation, we could use N(test-cases-passed), or time/memory efficiency. For math, correctness of the final answer. Asking the model to rank candidates and picking reasoning chains where the correct answer tops can extend across domains.
Media image
10
But we're still using only the best responses for learning. The compute in generating all of the remaining responses is just wasted. Can we utilize even this negative (or less positive) information? This is where Reinforcement Learning comes in 🎉
Media image
11
Idea 5: REINFORCE.
We simply weigh the likelihoods used in SFT by the reward for each sample. This is principled, RL literature shows the gradient of this loss maximizes expected reward! This "policy gradient" is the underlying principle for modern RL algorithms like PPO, GRPO.
Media image
12
Congrats 🎉, you now understand the fundamentals of LLM RL! Let's take a moment to discuss its power, and the performance that emerges from these simple ideas. We will then continue to GRPO and PPO at the end.
Media image
13
First, the DeepSeek R1 paper shows that "test time compute", "reasoning", and "reflection" are just emergent properties of scaling supervision beyond demonstrations to rewards. These are great capabilities, but not the fundamental reason for using RL imo.
Media image
14
But can RL generalize beyond verifiable domains with ground-truth rewards?

Idea 6: Generator-Verifier Gap.
For some tasks, evaluation is easier than generating solutions. Eg: We can judge Apple UX feels good, even if we can't create it ourselves.
Reward models strike back! 🤖
Media image
15
For evidence of RL improving performance on even subjective tasks, we need to go no further than OpenAI's recent releases. Deliberative Alignment shows rewards based on a safety spec can improve compliance scores. Deep Research shows multi-step tool-use via browsing, reading.
Media image
16
Sold? Now let's buckle up and make the (surprisingly short) trip to GRPO and PPO 🚀

Problem 1 with REINFORCE: A reward of 0.3 can be high for hard samples, and low for easy ones. What's hard at the start of training might become easy in the middle.
Media image
17
Idea 7: Advantage Estimation
We can estimate a "baseline" reward for a given sample based on the current capabilities of the model. Subtracting this baseline from the reward gives the advantage, disincentivizing outputs with lower reward than baseline, and promoting better ones.
Media image
18
Idea 8: GRPO
We can generate multiple responses (Group) to each prompt and find their rewards. Then, we subtract the mean reward as the baseline, and divide the standard deviation to obtain the advantage (Relative). We can now proceed with advantage weighted Policy Optimization.
Media image
19
Problem 2 with REINFORCE: We used the same reward assigned to the sample to weigh loss on all tokens. If the model got 4/5 solution steps right, the final answer being wrong would lead to even the 4 correct steps being disincentivized. We need better credit assignment📊
Media image
20
Idea 9: Value Model, used in PPO.
We train a model that predicts the expected reward at each token, based on the (prompt, generation until now). It has to be trained alongside our main model so that its estimates don't get outdated. This is why PPO is memory intensive⚠️
Media image
21
Idea(s) 10: Efficiency and Stabilization Tricks.
There's a bunch of tricks used in both GRPO and PPO to make the learning process more efficient and stable. These include "Minimizing Approximate KL" "Importance Sampling", "Advantage Clipping", "Reward Normalization" etc.
Media image
22
First principles understanding of these might need a full RL course, and I'm not quite there yet! I encourage you to dig deeper into RL papers and implementations to understand them. I hope the core idea of scaling supervision is clear, and the tricks might evolve anyway!
23
That's it! This was an experiment in converting my slides from a presentation into a twitter thread for broader dissemination. Illustrations and learning heavily borrowed from @AdaptiveML @wellecks etc. for which I'm really grateful! Would love to know about any mistakes I made.
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement