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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>PPO, GRPO, & DAPO: Core Concepts and Comparison</title>
|
8 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
font-family: 'Inter', sans-serif;
|
12 |
+
line-height: 1.7;
|
13 |
+
margin: 0;
|
14 |
+
padding: 0;
|
15 |
+
background-color: #fdfdff;
|
16 |
+
/* Slightly off-white */
|
17 |
+
color: #333;
|
18 |
+
}
|
19 |
+
|
20 |
+
.container {
|
21 |
+
max-width: 900px;
|
22 |
+
margin: 25px auto;
|
23 |
+
padding: 25px;
|
24 |
+
background-color: #ffffff;
|
25 |
+
border-radius: 10px;
|
26 |
+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
27 |
+
}
|
28 |
+
|
29 |
+
h1,
|
30 |
+
h2,
|
31 |
+
h3,
|
32 |
+
h4 {
|
33 |
+
color: #005A9C;
|
34 |
+
/* Deep blue for headings */
|
35 |
+
margin-top: 1.6em;
|
36 |
+
margin-bottom: 0.7em;
|
37 |
+
}
|
38 |
+
|
39 |
+
h1 {
|
40 |
+
font-size: 2.2em;
|
41 |
+
text-align: center;
|
42 |
+
border-bottom: 2px solid #007BFF;
|
43 |
+
/* Brighter blue accent */
|
44 |
+
padding-bottom: 0.5em;
|
45 |
+
margin-top: 0;
|
46 |
+
}
|
47 |
+
|
48 |
+
h2 {
|
49 |
+
font-size: 1.75em;
|
50 |
+
border-bottom: 1px solid #e0e0e0;
|
51 |
+
/* Light grey separator */
|
52 |
+
padding-bottom: 0.3em;
|
53 |
+
}
|
54 |
+
|
55 |
+
h3 {
|
56 |
+
font-size: 1.4em;
|
57 |
+
color: #0067B3;
|
58 |
+
/* Medium blue */
|
59 |
+
}
|
60 |
+
|
61 |
+
h4 {
|
62 |
+
font-size: 1.15em;
|
63 |
+
color: #0072C6; /* Slightly lighter blue for sub-examples */
|
64 |
+
}
|
65 |
+
|
66 |
+
p {
|
67 |
+
margin-bottom: 1.1em;
|
68 |
+
text-align: left;
|
69 |
+
/* Changed from justify for better readability */
|
70 |
+
font-size: 1em;
|
71 |
+
}
|
72 |
+
|
73 |
+
code,
|
74 |
+
.code-inline {
|
75 |
+
background-color: #e8f4ff;
|
76 |
+
/* Very light blue */
|
77 |
+
padding: 0.2em 0.4em;
|
78 |
+
border-radius: 4px;
|
79 |
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
80 |
+
font-size: 0.9em;
|
81 |
+
border: 1px solid #cce0ff;
|
82 |
+
/* Light blue border */
|
83 |
+
color: #004a80;
|
84 |
+
}
|
85 |
+
|
86 |
+
.formula {
|
87 |
+
display: block;
|
88 |
+
background-color: #f5f9ff;
|
89 |
+
/* Lighter blue-tinted background */
|
90 |
+
border-left: 4px solid #007BFF;
|
91 |
+
padding: 15px;
|
92 |
+
margin: 15px 0;
|
93 |
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
94 |
+
font-size: 1em;
|
95 |
+
overflow-x: auto;
|
96 |
+
border-radius: 5px;
|
97 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
98 |
+
}
|
99 |
+
|
100 |
+
.highlight-box {
|
101 |
+
background-color: #e6f7ff;
|
102 |
+
/* Light cyan/blue */
|
103 |
+
padding: 15px;
|
104 |
+
border-radius: 6px;
|
105 |
+
margin-bottom: 1.1em;
|
106 |
+
border: 1px solid #b3e0ff;
|
107 |
+
/* Cyan/blue border */
|
108 |
+
color: #004080;
|
109 |
+
/* Darker blue text for contrast */
|
110 |
+
}
|
111 |
+
|
112 |
+
.highlight-box strong {
|
113 |
+
color: #005A9C;
|
114 |
+
}
|
115 |
+
|
116 |
+
strong,
|
117 |
+
.bold-text {
|
118 |
+
font-weight: 600;
|
119 |
+
color: #005A9C;
|
120 |
+
/* Consistent bold color */
|
121 |
+
}
|
122 |
+
|
123 |
+
ul,
|
124 |
+
ol {
|
125 |
+
margin-bottom: 1.1em;
|
126 |
+
padding-left: 22px;
|
127 |
+
}
|
128 |
+
|
129 |
+
li {
|
130 |
+
margin-bottom: 0.5em;
|
131 |
+
}
|
132 |
+
|
133 |
+
.note-box {
|
134 |
+
background-color: #fffbe6;
|
135 |
+
/* Light yellow */
|
136 |
+
border-left: 4px solid #ffdd77;
|
137 |
+
/* Yellow border */
|
138 |
+
padding: 10px 15px;
|
139 |
+
margin: 15px 0;
|
140 |
+
border-radius: 5px;
|
141 |
+
color: #665200;
|
142 |
+
/* Dark yellow text */
|
143 |
+
}
|
144 |
+
|
145 |
+
.example-box {
|
146 |
+
background-color: #e6ffed;
|
147 |
+
/* Light green */
|
148 |
+
border-left: 4px solid #77dd77;
|
149 |
+
/* Green border */
|
150 |
+
padding: 10px 15px;
|
151 |
+
margin: 15px 0;
|
152 |
+
border-radius: 5px;
|
153 |
+
color: #004d1a;
|
154 |
+
/* Dark green text */
|
155 |
+
}
|
156 |
+
.example-box h4 {
|
157 |
+
margin-top: 0.5em;
|
158 |
+
color: #004d1a; /* Dark green to match box text */
|
159 |
+
}
|
160 |
+
|
161 |
+
table {
|
162 |
+
width: 100%;
|
163 |
+
border-collapse: collapse;
|
164 |
+
margin: 20px 0;
|
165 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
|
166 |
+
}
|
167 |
+
|
168 |
+
th,
|
169 |
+
td {
|
170 |
+
border: 1px solid #dce4f0;
|
171 |
+
/* Lighter border for table */
|
172 |
+
padding: 10px 12px;
|
173 |
+
text-align: left;
|
174 |
+
vertical-align: top;
|
175 |
+
}
|
176 |
+
|
177 |
+
th {
|
178 |
+
background-color: #f0f6ff;
|
179 |
+
/* Light blue for table header */
|
180 |
+
font-weight: 600;
|
181 |
+
color: #005A9C;
|
182 |
+
}
|
183 |
+
|
184 |
+
hr {
|
185 |
+
border: 0;
|
186 |
+
height: 1px;
|
187 |
+
background-color: #d0d0d0;
|
188 |
+
margin: 2em 0;
|
189 |
+
}
|
190 |
+
</style>
|
191 |
+
</head>
|
192 |
+
|
193 |
+
<body>
|
194 |
+
<div class="container">
|
195 |
+
<h1>PPO, GRPO, & DAPO: Core Concepts (Unified Example)</h1>
|
196 |
+
|
197 |
+
<section id="intro">
|
198 |
+
<h2>I. Introduction to Policy Optimization</h2>
|
199 |
+
<p>
|
200 |
+
In Reinforcement Learning (RL), an <strong class="bold-text">agent</strong> learns to make decisions by interacting with an <strong class="bold-text">environment</strong> to maximize cumulative <strong class="bold-text">rewards</strong>. The agent's strategy is its <strong class="bold-text">policy (π)</strong>.
|
201 |
+
</p>
|
202 |
+
<p>
|
203 |
+
<strong class="bold-text">Policy Optimization</strong> algorithms directly learn or improve this policy. Instead of just learning values for states/actions, they find policy parameters (θ) that yield the highest rewards. PPO, GRPO, and DAPO are advanced policy optimization algorithms, particularly relevant for complex tasks like training Large Language Models (LLMs).
|
204 |
+
</p>
|
205 |
+
</section>
|
206 |
+
<hr />
|
207 |
+
|
208 |
+
<section id="ppo">
|
209 |
+
<h2>II. Proximal Policy Optimization (PPO)</h2>
|
210 |
+
<div class="highlight-box">
|
211 |
+
<strong>Core Idea of PPO:</strong> Improve the policy with updates that are not too large (to avoid performance collapse) and not too small (to ensure progress). PPO aims for stable and reliable policy improvement.
|
212 |
+
</div>
|
213 |
+
|
214 |
+
<h3>A. Key Concepts in PPO</h3>
|
215 |
+
<ul>
|
216 |
+
<li>
|
217 |
+
<strong class="bold-text">Policy (π<sub>θ</sub>(a|s)):</strong> The agent's current strategy, mapping states <code class="code-inline">s</code> to action <code class="code-inline">a</code> probabilities, parameterized by <code class="code-inline">θ</code>. In LLMs, <code class="code-inline">s</code> is the current sequence of generated tokens (prompt + previous tokens), and <code class="code-inline">a</code> is the next token to generate.
|
218 |
+
</li>
|
219 |
+
<li>
|
220 |
+
<strong class="bold-text">Value Function (V(s)):</strong> Learned by a <strong class="bold-text">critic network</strong>, estimates the expected cumulative reward from state <code class="code-inline">s</code>. For an LLM, <code class="code-inline">V(s)</code> would estimate the quality (e.g., from a reward model) of the completion starting from the current token sequence <code class="code-inline">s</code>.
|
221 |
+
</li>
|
222 |
+
<li>
|
223 |
+
<strong class="bold-text">Advantage Function (A<sup>π</sup>(s,a) or Â<sub>t</sub>):</strong> Quantifies how much better action <code class="code-inline">a</code> is compared to the average action from state <code class="code-inline">s</code>. Often estimated using <strong class="bold-text">Generalized Advantage Estimation (GAE)</strong>:
|
224 |
+
<div class="formula">Â<sub>t</sub><sup>GAE</sup> = ∑<sub>l=0</sub><sup>T-t-1</sup> (γλ)<sup>l</sup>δ<sub>t+l</sub></div>
|
225 |
+
where <code class="code-inline">δ<sub>t+l</sub> = r<sub>t+l</sub> + γV(s<sub>t+l+1</sub>) - V(s<sub>t+l</sub>)</code> is the TD residual. <code class="code-inline">r<sub>t+l</sub></code> is the reward for generating the token <code class="code-inline">a<sub>t+l</sub></code>, and <code class="code-inline">V(s)</code> is the state-value function.
|
226 |
+
</li>
|
227 |
+
<li>
|
228 |
+
<strong class="bold-text">Probability Ratio (r<sub>t</sub>(θ)):</strong> Compares the probability of an action under the new policy (π<sub>θ</sub>) versus the old policy (π<sub>θ<sub>old</sub></sub>) that collected the data.
|
229 |
+
<div class="formula">r<sub>t</sub>(θ) = π<sub>θ</sub>(a<sub>t</sub>|s<sub>t</sub>) / π<sub>θ<sub>old</sub></sub>(a<sub>t</sub>|s<sub>t</sub>)</div>
|
230 |
+
</li>
|
231 |
+
<li>
|
232 |
+
<strong class="bold-text">Clipped Surrogate Objective Function (L<sup>CLIP</sup>(θ)):</strong> PPO's core.
|
233 |
+
<div class="formula">L<sup>CLIP</sup>(θ) = Ê<sub>t</sub> [ min( r<sub>t</sub>(θ)Â<sub>t</sub>, clip(r<sub>t</sub>(θ), 1-ε, 1+ε)Â<sub>t</sub> ) ]</div>
|
234 |
+
Here, <code class="code-inline">ε</code> (epsilon, e.g., 0.1 or 0.2) defines the clipping range.
|
235 |
+
</li>
|
236 |
+
</ul>
|
237 |
+
<div class="note-box">
|
238 |
+
<strong>Why clipping?</strong> It prevents the new policy from moving too far from the old policy in a single update, ensuring stability.
|
239 |
+
</div>
|
240 |
+
|
241 |
+
<h3>B. Example: LLM Answering "Capital of Australia?" with PPO</h3>
|
242 |
+
<div class="example-box">
|
243 |
+
<h4>Scenario: LLM generating an answer to "What is the capital of Australia?"</h4>
|
244 |
+
<ol>
|
245 |
+
<li><strong>Prompt (Initial State):</strong> "What is the capital of Australia?"</li>
|
246 |
+
<li><strong>Data Collection (Rollout):</strong> The LLM (policy π<sub>θ<sub>old</sub></sub>) generates a sequence of tokens. Let's say it generates "Sydney".
|
247 |
+
<ul>
|
248 |
+
<li>State <code class="code-inline">s<sub>0</sub></code>: "What is the capital of Australia?"</li>
|
249 |
+
<li>Action <code class="code-inline">a<sub>0</sub></code>: Token "Sydney"</li>
|
250 |
+
<li>Reward <code class="code-inline">r<sub>0</sub></code>: A reward model evaluates "Sydney" in this context. Let's say it gives a low reward (e.g., 2/10) because it's incorrect.</li>
|
251 |
+
<li>Next State <code class="code-inline">s<sub>1</sub></code>: "What is the capital of Australia? Sydney" (now considering this as a completed sequence for simplicity of this step).</li>
|
252 |
+
</ul>
|
253 |
+
</li>
|
254 |
+
<li><strong>Value Estimation (Critic):</strong>
|
255 |
+
<ul>
|
256 |
+
<li>The critic <code class="code-inline">V(s<sub>0</sub>)</code> estimates the expected future reward from the prompt. It might have a moderate value if the LLM sometimes gets it right.</li>
|
257 |
+
<li>The critic <code class="code-inline">V(s<sub>1</sub>)</code> (value of the state *after* generating "Sydney") would likely be low, as "Sydney" is a poor completion.</li>
|
258 |
+
</ul>
|
259 |
+
</li>
|
260 |
+
<li><strong>Advantage Estimation (Â<sub>0</sub> for token "Sydney"):</strong>
|
261 |
+
Using a simplified GAE (single step for clarity): <code class="code-inline">Â<sub>0</sub> ≈ r<sub>0</sub> + γV(s<sub>1</sub>) - V(s<sub>0</sub>)</code>.
|
262 |
+
If <code class="code-inline">r<sub>0</sub>=2</code>, <code class="code-inline">V(s<sub>1</sub>)</code> is low (e.g., 1), and <code class="code-inline">V(s<sub>0</sub>)</code> was higher (e.g., 5, hoping for a better outcome), then Â<sub>0</sub> might be <code class="code-inline">2 + 0.9*1 - 5 = -2.1</code> (negative advantage). This indicates "Sydney" was a worse-than-average choice.
|
263 |
+
</li>
|
264 |
+
<li><strong>Probability Ratio (r<sub>0</sub>(θ)):</strong>
|
265 |
+
The new policy π<sub>θ</sub> will try to decrease the probability of generating "Sydney" given the prompt: <code class="code-inline">π<sub>θ</sub>("Sydney"|s<sub>0</sub>) < π<sub>θ<sub>old</sub></sub>("Sydney"|s<sub>0</sub>)</code>. This makes <code class="code-inline">r<sub>0</sub>(θ) < 1</code>.
|
266 |
+
</li>
|
267 |
+
<li><strong>Clipped Objective in Action:</strong>
|
268 |
+
Let <code class="code-inline">ε = 0.2</code>. Suppose <code class="code-inline">r<sub>0</sub>(θ) = 0.7</code> (policy wants to reduce probability by 30%). Â<sub>0</sub> is negative (-2.1).
|
269 |
+
<ul>
|
270 |
+
<li>Term 1: <code class="code-inline">r<sub>0</sub>(θ)Â<sub>0</sub> = 0.7 * (-2.1) = -1.47</code>.</li>
|
271 |
+
<li>Term 2: <code class="code-inline">clip(r<sub>0</sub>(θ), 1-ε, 1+ε)Â<sub>0</sub> = clip(0.7, 0.8, 1.2)Â<sub>0</sub> = 0.8 * (-2.1) = -1.68</code>.</li>
|
272 |
+
<li>The objective takes <code class="code-inline">min(-1.47, -1.68)</code>. Since Â<sub>0</sub> is negative, the objective function aims to make the term <code class="code-inline">r<sub>t</sub>(θ)Â<sub>t</sub></code> less negative (i.e., closer to zero or positive). The `min` here actually selects the *larger* value when advantages are negative (less negative is larger). So, it would be <code class="code-inline">-1.47</code>. The goal is to reduce the likelihood of this action, but the clipping (to 0.8 * Â<sub>0</sub> in the second term) prevents the policy from drastically reducing the probability too quickly if the proposed change is too large.
|
273 |
+
<br/><em>Correction:</em> For negative advantages, the objective is <code class="code-inline">max( r<sub>t</sub>(θ)Â<sub>t</sub>, clip(r<sub>t</sub>(θ), 1-ε, 1+ε)Â<sub>t</sub> )</code> effectively, or the PPO paper presents it as <code class="code-inline">min</code> but the interpretation for negative advantage is that we want to increase <code class="code-inline">r_t(θ)</code> towards <code class="code-inline">1+ε</code> if <code class="code-inline">r_t(θ) > 1+ε</code > (which is not the case here) or decrease it towards <code class="code-inline">1-ε</code> if <code class="code-inline">r_t(θ) < 1-ε</code >.
|
274 |
+
The key is that the change is bounded. If <code class="code-inline">r_t(θ) = 0.7</code> and <code class="code-inline">Â_t < 0</code >, the objective encourages increasing <code class="code-inline">r_t(θ)</code > but not beyond <code class="code-inline">1-ε</code >. The update is based on <code class="code-inline">0.8 * Â_t</code > if <code class="code-inline">0.7 * Â_t < 0.8 * Â_t</code > (which is true since <code class="code-inline">Â_t < 0</code >).
|
275 |
+
So, the effective update is based on <code class="code-inline">clip(0.7, 0.8, 1.2) * Â_t = 0.8 * Â_t</code>.
|
276 |
+
The policy is gently discouraged from picking "Sydney".
|
277 |
+
Conversely, if the LLM had generated "Canberra" (high reward, positive advantage), PPO would encourage increasing its probability, clipped at <code class="code-inline">(1+ε)Â<sub>t</sub></code>.
|
278 |
+
</li>
|
279 |
+
</ul>
|
280 |
+
</li>
|
281 |
+
</ol>
|
282 |
+
</div>
|
283 |
+
|
284 |
+
<h3>C. PPO Strengths & Limitations</h3>
|
285 |
+
<ul>
|
286 |
+
<li><strong>Strengths:</strong> Simpler to implement than TRPO, good empirical performance, stable, relatively sample efficient.</li>
|
287 |
+
<li><strong>Limitations:</strong> Critic can be complex and resource-intensive for LLMs. Sensitive to initialization. Value estimation for long, sparse-reward sequences in LLMs is challenging (value initialization bias, reward signal decay).</li>
|
288 |
+
</ul>
|
289 |
+
</section>
|
290 |
+
<hr />
|
291 |
+
|
292 |
+
<section id="grpo">
|
293 |
+
<h2>III. Group Relative Policy Optimization (GRPO)</h2>
|
294 |
+
<div class="highlight-box">
|
295 |
+
<strong>Core Idea of GRPO:</strong> Simplify PPO for LLMs by <strong class="bold-text">removing the critic network</strong>. Advantage is estimated by comparing a response's reward to the average reward of a "group" of responses generated for the <strong class="bold-text">same input prompt</strong>.
|
296 |
+
</div>
|
297 |
+
|
298 |
+
<h3>A. Key Concepts in GRPO</h3>
|
299 |
+
<ul>
|
300 |
+
<li>
|
301 |
+
<strong class="bold-text">Critic-less:</strong> No learned value function <code class="code-inline">V(s)</code>. This reduces memory and computation.
|
302 |
+
</li>
|
303 |
+
<li>
|
304 |
+
<strong class="bold-text">Group Sampling:</strong> For an input prompt <code class="code-inline">q</code>, generate <code class="code-inline">G</code> responses <code class="code-inline">{o<sub>1</sub>, ..., o<sub>G</sub>}</code> using the current policy.
|
305 |
+
</li>
|
306 |
+
<li>
|
307 |
+
<strong class="bold-text">Group-Relative Advantage Estimation (Â(o<sub>i</sub>)):</strong> The advantage for response <code class="code-inline">o<sub>i</sub></code> is its reward <code class="code-inline">R(o<sub>i</sub>)</code> standardized relative to the group's rewards:
|
308 |
+
<div class="formula">Â(o<sub>i</sub>) = (R(o<sub>i</sub>) - μ<sub>G</sub>) / (σ<sub>G</sub> + ϵ<sub>norm</sub>)</div>
|
309 |
+
where <code class="code-inline">μ<sub>G</sub></code> is the mean reward of the group, <code class="code-inline">σ<sub>G</sub></code> is the standard deviation of rewards in the group, and <code class="code-inline">ϵ<sub>norm</sub></code> is for numerical stability. This advantage is typically applied to all tokens in the response <code class="code-inline">o<sub>i</sub></code>.
|
310 |
+
</li>
|
311 |
+
<li>
|
312 |
+
<strong class="bold-text">Objective Function (L<sub>GRPO</sub>(θ)):</strong> Uses the PPO-style clipped objective but with the group-relative advantage. Often includes a KL-divergence penalty term <code class="code-inline">β · KL(π<sub>θ</sub> || π<sub>ref</sub>)</code>.
|
313 |
+
<div class="formula">L<sub>GRPO</sub>(θ) = E [min( r<sub>θ</sub>(o)Â(o), clip(r<sub>θ</sub>(o), 1-ε, 1+ε)Â(o) )] - β KL(π<sub>θ</sub> || π<sub>ref</sub>)</div>
|
314 |
+
</li>
|
315 |
+
</ul>
|
316 |
+
|
317 |
+
<h3>B. Example: LLM Answering "Capital of Australia?" with GRPO</h3>
|
318 |
+
<div class="example-box">
|
319 |
+
<h4>Scenario: LLM generating an answer to "What is the capital of Australia?"</h4>
|
320 |
+
<ol>
|
321 |
+
<li> <strong>Prompt:</strong> "What is the capital of Australia?"</li>
|
322 |
+
<li> <strong>Group Sampling (G=3 responses generated by current policy π<sub>θ<sub>old</sub></sub>):</strong>
|
323 |
+
<ul>
|
324 |
+
<li>o<sub>1</sub>: "Sydney" (Reward R(o<sub>1</sub>)=2 from a reward model)</li>
|
325 |
+
<li>o<sub>2</sub>: "Canberra" (Reward R(o<sub>2</sub>)=10)</li>
|
326 |
+
<li>o<sub>3</sub>: "Melbourne" (Reward R(o<sub>3</sub>)=3)</li>
|
327 |
+
</ul>
|
328 |
+
</li>
|
329 |
+
<li> <strong>Group Stats:</strong> Mean reward μ<sub>G</sub> = (2+10+3)/3 = 5. Standard deviation σ<sub>G</sub> ≈ 3.5 (assuming ϵ<sub>norm</sub> is small).</li>
|
330 |
+
<li> <strong>Group-Relative Advantages:</strong>
|
331 |
+
<ul>
|
332 |
+
<li>Â(o<sub>1</sub>) for "Sydney" = (2-5)/3.5 ≈ -0.86 (negative advantage)</li>
|
333 |
+
<li>Â(o<sub>2</sub>) for "Canberra" = (10-5)/3.5 ≈ +1.43 (positive advantage)</li>
|
334 |
+
<li>Â(o<sub>3</sub>) for "Melbourne" = (3-5)/3.5 ≈ -0.57 (negative advantage)</li>
|
335 |
+
</ul>
|
336 |
+
These advantages apply to the entire sequences. For example, every token in "Sydney" gets an advantage of -0.86.
|
337 |
+
</li>
|
338 |
+
<li><strong>Probability Ratio (r<sub>θ</sub>(o<sub>i</sub>)):</strong> This is <code class="code-inline">π<sub>θ</sub>(o<sub>i</sub>|prompt) / π<sub>θ<sub>old</sub></sub>(o<sub>i</sub>|prompt)</code>.
|
339 |
+
<li> <strong>Policy Update:</strong>
|
340 |
+
<ul>
|
341 |
+
<li>For o<sub>1</sub> ("Sydney"): Â(o<sub>1</sub>) is negative. The policy π<sub>θ</sub> will be updated to decrease the probability of generating "Sydney". The update is clipped.</li>
|
342 |
+
<li>For o<sub>2</sub> ("Canberra"): Â(o<sub>2</sub>) is positive. The policy π<sub>θ</sub> will be updated to increase the probability of generating "Canberra". The update is clipped.</li>
|
343 |
+
<li>For o<sub>3</sub> ("Melbourne"): Â(o<sub>3</sub>) is negative. The policy π<sub>θ</sub> will be updated to decrease the probability of generating "Melbourne". The update is clipped.</li>
|
344 |
+
</ul>
|
345 |
+
The KL term helps ensure π<sub>θ</sub> doesn't stray too far from a reference policy (e.g., the SFT model).
|
346 |
+
</li>
|
347 |
+
</ol>
|
348 |
+
</div>
|
349 |
+
|
350 |
+
<h3>C. GRPO Strengths & Limitations</h3>
|
351 |
+
<ul>
|
352 |
+
<li><strong>Strengths:</strong> Computationally efficient for LLMs (no critic), stable due to clipping and KL regularization, flexible reward sources.</li>
|
353 |
+
<li><strong>Limitations:</strong>
|
354 |
+
<ul>
|
355 |
+
<li><strong class="bold-text">Zero-Advantage Problem:</strong> If all responses in a group have the same reward (e.g., all "Canberra" or all "Sydney"), <code class="code-inline">σ<sub>G</sub></code> is zero, leading to zero advantage for all samples in that group and thus no learning signal.</li>
|
356 |
+
<li>Potential optimization bias (e.g., favoring longer responses if length correlates with reward, as advantage is sequence-level).</li>
|
357 |
+
<li>Advantage is applied at sequence level, not token level, which can be less precise.</li>
|
358 |
+
</ul>
|
359 |
+
</li>
|
360 |
+
</ul>
|
361 |
+
</section>
|
362 |
+
<hr />
|
363 |
+
|
364 |
+
<section id="dapo">
|
365 |
+
<h2>IV. Decoupled Clip and Dynamic Sampling Policy Optimization (DAPO)</h2>
|
366 |
+
<div class="highlight-box">
|
367 |
+
<strong>Core Idea of DAPO:</strong> Refine GRPO for LLMs by addressing issues like <strong class="bold-text">entropy collapse</strong> and the <strong class="bold-text">zero-advantage problem</strong>, using techniques like decoupled clipping and dynamic sampling. It often uses token-level advantages.
|
368 |
+
</div>
|
369 |
+
|
370 |
+
<h3>A. Key Innovations in DAPO</h3>
|
371 |
+
<ul>
|
372 |
+
<li>
|
373 |
+
<strong class="bold-text">Decoupled Clipping ("Clip-Higher" Strategy):</strong>
|
374 |
+
Uses asymmetric clipping bounds for the probability ratio <code class="code-inline">r<sub>t</sub>(θ)</code>, e.g., <code class="code-inline">[1-ε<sub>low</sub>, 1+ε<sub>high</sub>]</code>, where <code class="code-inline">ε<sub>high</sub></code> (e.g., 0.28) > <code class="code-inline">ε<sub>low</sub></code> (e.g., 0.2).
|
375 |
+
<div class="note-box">
|
376 |
+
<strong>Rationale:</strong> When advantage is positive, allows larger probability increases for beneficial, initially low-probability tokens, promoting exploration.
|
377 |
+
</div>
|
378 |
+
</li>
|
379 |
+
<li>
|
380 |
+
<strong class="bold-text">Dynamic Sampling:</strong>
|
381 |
+
Filters out and replaces training prompts/groups where responses have homogenous rewards (low <code class="code-inline">σ<sub>G</sub></code>).
|
382 |
+
<div class="note-box">
|
383 |
+
<strong>Rationale:</strong> Mitigates GRPO's zero-advantage problem, ensuring batches have "informative" samples.
|
384 |
+
</div>
|
385 |
+
</li>
|
386 |
+
<li>
|
387 |
+
<strong class="bold-text">Token-Level Policy Gradient Loss:</strong>
|
388 |
+
Calculates loss at the token level and averages across all tokens in the batch. GRPO's group-relative advantage can be adapted for token-level application (e.g., by assigning the sequence advantage to each token, or using more fine-grained token-level reward signals if available).
|
389 |
+
</li>
|
390 |
+
</ul>
|
391 |
+
<p>DAPO typically builds on GRPO's critic-less group-relative advantage estimation but incorporates these enhancements.</p>
|
392 |
+
|
393 |
+
<h3>B. Example: LLM Answering "Capital of Australia?" with DAPO</h3>
|
394 |
+
<div class="example-box">
|
395 |
+
<h4>Scenario: LLM generating an answer to "What is the capital of Australia?"</h4>
|
396 |
+
<ol>
|
397 |
+
<li><strong>Prompt:</strong> "What is the capital of Australia?"</li>
|
398 |
+
<li><strong>Group Sampling (G=3, by π<sub>θ<sub>old</sub></sub>):</strong>
|
399 |
+
<ul>
|
400 |
+
<li>o<sub>1</sub>: "Sydney" (Reward R(o<sub>1</sub>)=2)</li>
|
401 |
+
<li>o<sub>2</sub>: "Canberra" (Reward R(o<sub>2</sub>)=10)</li>
|
402 |
+
<li>o<sub>3</sub>: "Melbourne" (Reward R(o<sub>3</sub>)=3)</li>
|
403 |
+
</ul>
|
404 |
+
</li>
|
405 |
+
<li> <strong>Group Stats & Advantages (as in GRPO):</strong> μ<sub>G</sub>=5, σ<sub>G</sub>≈3.5.
|
406 |
+
<ul>
|
407 |
+
<li>Â(o<sub>1</sub>) ≈ -0.86</li>
|
408 |
+
<li>Â(o<sub>2</sub>) ≈ +1.43</li>
|
409 |
+
<li>Â(o<sub>3</sub>) ≈ -0.57</li>
|
410 |
+
</ul>
|
411 |
+
These advantages are applied at the token level for DAPO's loss calculation. So, each token in "Canberra" gets an advantage of +1.43.
|
412 |
+
</li>
|
413 |
+
<li><strong>Dynamic Sampling in Action:</strong>
|
414 |
+
This group (rewards 2, 10, 3) is diverse (σ<sub>G</sub> is non-zero), so it's likely kept.
|
415 |
+
If another prompt, e.g., "What is 1+1?", produced three responses: o<sub>4</sub>:"2" (R=10), o<sub>5</sub>:"Two" (R=10), o<sub>6</sub>:"II" (R=10). Here, σ<sub>G</sub> would be 0. Dynamic Sampling might filter out this "1+1" prompt and its group, replacing it with a prompt that yields more diverse rewards to ensure effective gradients.
|
416 |
+
</li>
|
417 |
+
<li><strong>Decoupled Clipping ("Clip-Higher") in Action (Focus on o<sub>2</sub>: "Canberra"):</strong>
|
418 |
+
Assume the token "Canberra" (or its constituent tokens) had a relatively low probability under π<sub>θ<sub>old</sub></sub>, but it's the correct, high-reward answer. The advantage Â(o<sub>2</sub>) ≈ +1.43 is positive.
|
419 |
+
<ul>
|
420 |
+
<li>The new policy π<sub>θ</sub> aims to significantly increase the probability of "Canberra". Suppose this leads to a token probability ratio <code class="code-inline">r<sub>t</sub>(θ) = 1.35</code> for "Canberra".</li>
|
421 |
+
<li>DAPO uses <code class="code-inline">ε<sub>low</sub>=0.2</code>, <code class="code-inline">ε<sub>high</sub>=0.28</code>. Clipping range: <code class="code-inline">[1-0.2, 1+0.28] = [0.8, 1.28]</code>.</li>
|
422 |
+
<li>The clipped ratio is <code class="code-inline">clip(1.35, 0.8, 1.28) = 1.28</code>.</li>
|
423 |
+
<li>The update for "Canberra" tokens is based on <code class="code-inline">1.28 * Â(o<sub>2</sub>)</code>.
|
424 |
+
Standard PPO/GRPO (ε=0.2) would clip at <code class="code-inline">1.2 * Â(o<sub>2</sub>)</code>.
|
425 |
+
DAPO's "clip-higher" allows a larger update (<code class="code-inline">1.28 * Â(o<sub>2</sub>)</code > vs <code class="code-inline">1.2 * Â(o<sub>2</sub>)</code >), more strongly reinforcing this correct, high-advantage token, especially if it was initially unlikely.
|
426 |
+
</li>
|
427 |
+
</ul>
|
428 |
+
</li>
|
429 |
+
<li><strong>Token-Level Policy Gradient Loss:</strong> The loss is computed for each token in each response using its assigned advantage (e.g., all tokens in "Canberra" use Â(o<sub>2</sub>)). These token losses are then averaged across all tokens in the batch.</li>
|
430 |
+
</ol>
|
431 |
+
</div>
|
432 |
+
|
433 |
+
<h3>C. DAPO Strengths & Considerations</h3>
|
434 |
+
<ul>
|
435 |
+
<li><strong>Strengths:</strong> Addresses GRPO's zero-advantage problem and LLM entropy collapse. Improves training efficiency and stability for complex reasoning.</li>
|
436 |
+
<li><strong>Considerations:</strong> More hyperparameters (ε<sub>low</sub>, ε<sub>high</sub>). Effectiveness of dynamic sampling can be task-dependent. Relies on good reward function design.
|
437 |
+
</li>
|
438 |
+
</ul>
|
439 |
+
</section>
|
440 |
+
<hr />
|
441 |
+
|
442 |
+
<section id="comparison">
|
443 |
+
<h2>V. Comparative Overview & Evolution</h2>
|
444 |
+
<p>
|
445 |
+
The journey from PPO to GRPO to DAPO shows an evolution driven by the need to apply RL effectively to increasingly large and complex models, especially LLMs, using the same core problem as a lens.
|
446 |
+
</p>
|
447 |
+
|
448 |
+
<h3>Key Differences at a Glance (Unified Example: "Capital of Australia?"):</h3>
|
449 |
+
<table>
|
450 |
+
<thead>
|
451 |
+
<tr>
|
452 |
+
<th>Feature</th>
|
453 |
+
<th>PPO</th>
|
454 |
+
<th>GRPO</th>
|
455 |
+
<th>DAPO</th>
|
456 |
+
</tr>
|
457 |
+
</thead>
|
458 |
+
<tbody>
|
459 |
+
<tr>
|
460 |
+
<td><strong>Critic Usage</strong></td>
|
461 |
+
<td>Yes (Learned V(s) estimates value of "What is capital of Aus? ...token_sequence")</td>
|
462 |
+
<td>No (Critic-less)</td>
|
463 |
+
<td>No (Critic-less)</td>
|
464 |
+
</tr>
|
465 |
+
<tr>
|
466 |
+
<td><strong>Advantage Estimation for "Canberra"</strong></td>
|
467 |
+
<td>GAE: Uses reward for "Canberra" & V(s) from critic. Token-level.</td>
|
468 |
+
<td>Group-Relative: Compares R("Canberra") to R("Sydney"), R("Melbourne"). Sequence-level.</td>
|
469 |
+
<td>Group-Relative (like GRPO), but often applied for token-level loss.</td>
|
470 |
+
</tr>
|
471 |
+
<tr>
|
472 |
+
<td><strong>Clipping for "Canberra" (if <code class="code-inline">r<sub>t</sub>(θ)=1.35</code>, Â > 0)</strong></td>
|
473 |
+
<td>Symmetric (ε=0.2): <code class="code-inline">clip(1.35, 0.8, 1.2)Â = 1.2Â</code></td>
|
474 |
+
<td>Symmetric (ε=0.2): <code class="code-inline">clip(1.35, 0.8, 1.2)Â = 1.2Â</code></td>
|
475 |
+
<td>Decoupled (ε<sub>high</sub>=0.28): <code class="code-inline">clip(1.35, 0.8, 1.28)Â = 1.28Â</code> (allows larger increase)</td>
|
476 |
+
</tr>
|
477 |
+
<tr>
|
478 |
+
<td><strong>Handling Homogenous Rewards (e.g., all outputs "Canberra" R=10)</strong></td>
|
479 |
+
<td>Critic still provides value estimates; GAE can be non-zero if V(s) differs.</td>
|
480 |
+
<td>Zero-Advantage Problem: σ<sub>G</sub>=0, so Â=0 for all. No learning signal from this batch.</td>
|
481 |
+
<td>Dynamic Sampling: Filters out this batch to replace with more diverse one.</td>
|
482 |
+
</tr>
|
483 |
+
<tr>
|
484 |
+
<td><strong>Primary Stability/Exploration Mechanisms</strong></td>
|
485 |
+
<td>Clipping, Entropy Bonus (optional)</td>
|
486 |
+
<td>Clipping, KL Regularization, Group Normalization</td>
|
487 |
+
<td>Decoupled Clipping, Dynamic Sampling, Token-level Loss</td>
|
488 |
+
</tr>
|
489 |
+
<tr>
|
490 |
+
<td><strong>Primary Application Focus</strong></td>
|
491 |
+
<td>General RL</td>
|
492 |
+
<td>LLM fine-tuning (general)</td>
|
493 |
+
<td>Advanced LLM reasoning, mitigating specific LLM RL issues</td>
|
494 |
+
</tr>
|
495 |
+
</tbody>
|
496 |
+
</table>
|
497 |
+
</section>
|
498 |
+
<hr />
|
499 |
+
<section id="conclusion">
|
500 |
+
<h2>VI. Conclusion</h2>
|
501 |
+
<p>
|
502 |
+
PPO, GRPO, and DAPO represent a significant lineage of policy optimization algorithms. Using a consistent example like an LLM answering a factual question, we can see how PPO provides a robust foundation with its critic-based advantage. GRPO adapts these principles for resource-constrained LLM training by introducing a critic-less, group-based advantage, simplifying computation. DAPO further refines this with specialized techniques like decoupled clipping and dynamic sampling to tackle nuanced challenges in LLM training, such as maintaining exploration and improving data efficiency when rewards might be homogenous or certain correct tokens are initially rare. Understanding their core mechanisms and evolutionary path is key to applying them effectively.
|
503 |
+
</p>
|
504 |
+
</section>
|
505 |
+
|
506 |
+
</div>
|
507 |
+
</body>
|
508 |
+
|
509 |
+
</html>
|