跳到主要内容
SecondHome

高级 RL 与系统:算法四失效,工程一本账

训练篇收束的双讲:6a 从算法侧接住 Agentic RL 的四种失效(反馈太稀、等待太久、更新太猛、奖励太假),外加向教师学习的助攻;6b 由客座讲师 Apurva Gandhi 拆开轨迹背后的双引擎,算清 KV 缓存、前缀共享、TITO 与服务化架构的账。

阅读约 51 分钟发布于 9月29日对应 CMU Lecture 11–12讲义 L11 ↗讲义 L12 ↗录像 ↗6b 录像 ↗音频 ↓

先试一试 · 入门探针

01判断基础L11 p.5-8 ↗

【讲前探针】同一任务采 4 条轨迹,奖励 1、0、0、0。按每条奖励减去组均值 0.25 取更新权重后,那 3 条失败轨迹仍然完全不会改变策略参数。

判断

本讲地图

点击卡片下钻详解

总起:两节课一条主线——让 Agentic RL 真的跑起来

6a(Graham Neubig,58 页)从算法侧接住四个失效;6b(客座讲师 Apurva Gandhi,43 页)从系统侧拆开一条轨迹背后的双引擎。修 bug agent 案例贯穿始终。

入门4 分钟#总起#6a#6b#训练方法L11 ↗L12 ↗

详解 →

信用分配三部曲:组均值、Critic 与过程奖励

失败轨迹在纯 REINFORCE 下梯度为零。组均值让失败开始教学,reward-to-go 与 critic 把信号细化到步,GAE 用 λ 调偏差-方差,PRM 则给每步人工打分;三层递进各付什么价。

进阶15 分钟#信用分配#GAE#PRM#6aL11 p.7-17 ↗

详解 →

长轨迹上比值会爆炸:重要性采样与裁剪六家

单步比值 1.05 乘 100 步约 132:少数样本主导更新。六家算法(PPO/GRPO/CISPO/GSPO/DAPO/CTPO)在哪些 token 进权重、怎么裁剪上分道扬镳;L11 p35 总结表逐格拆(表内基准行是 REINFORCE,CTPO 对照见 p.27)。

前沿17 分钟#重要性采样#PPO#CISPO#6aL11 p.18-35 ↗

详解 →

Verifier 也会骗人:假阴、假阳与独立审计

SWE-bench Verified 在 80.9% 放缓、τ-bench Retail 92% 是标注错误:基准自己会坏。假阴假阳诊断、reward hacking 矩阵与三栏独立验证,外加辅助奖励反噬的实证。

前沿16 分钟#奖励可靠性#reward hacking#基准审计#6aL11 p.36-47 ↗

详解 →

向教师学习:课程、蒸馏与 On-Policy 变奏

RL 采不动的任务,让会做的老师带:热启动与课程铺路,固定轨迹蒸馏会走出训练集没有的历史,GKD 让学生自己 rollout 再对齐教师,OPSD 直接冻结自己当教师。

进阶12 分钟#蒸馏#GKD#课程学习#6aL11 p.48-53 ↗

详解 →

一个训练步的五段旅程:双引擎与权重往返

optimizer.step() 只覆盖训练循环的中间一步。sample→verify→forward→backward→sync 五段里,推理引擎(vLLM/SGLang)与训练引擎(Megatron/FSDP2)用权重同步和路由重放对话。

入门13 分钟#RL系统#双引擎#weight sync#6bL12 p.2-8 ↗p.16-17 ↗

详解 →

Rollout 经济学:KV 缓存、前缀共享与投机解码的账本

Llama-3-8B 每 token 128KB KV、64 条 32k 轨迹约 256GB;而 GRPO batch 80–95% 是重复 prompt。KV/前缀缓存、连续批、投机解码、prefix sharing(ZoRRo 6×)与 activation checkpointing 的省法。

进阶14 分钟#KV缓存#前缀共享#投机解码#6bL12 p.9-15 ↗

详解 →

Agentic RL 的暗坑:模板、Token 与陈旧策略

Qwen3 默认模板会把 reasoning 从历史删掉;字符串存 rollout 会让训练/推理 tokenization 不一致;异步让数据陈旧:三个坑让训练器与 rollout 器各看各的场景,配 L12 p43 八项调试指标。

前沿15 分钟#chat template#TITO#staleness#6bL12 p.18-27 ↗p.43 ↗

详解 →

服务化 RL:单控制器、中间人与多租户

SPMD 直控一切但欠灵活;服务化(Agent/Env-Reward/Orchestrator/Trainer/Inference 五服务 + WeightSync + Open Reward Standard)换 harness 零代码。Cursor 每 5 小时在线出一版、8 并发多 LoRA 吞吐反超串行。

前沿15 分钟#服务化#单控制器#多租户#6bL12 p.28-41 ↗

详解 →

实践视角:八项调试指标与阅读路线

作业路线:手算组均值与 GAE 数值例、把 PPO/CISPO 目标写成对照实现、按 L12 p43 八指标搭一张自查看板;阅读路线见文末实践视角。

入门5 分钟#实践#调试指标#阅读路线L11 p.35 ↗L12 p.43 ↗

详解 →

站内音频镜像(YouTube 自动字幕转写见页面底部)· 原录像归 CMU 课程方所有加载中…

伴读笔记

导语

第 5 讲立起了 RL 的骨架:采样→打分→更新,GRPO 用组内比较省掉 critic。骨架能跑,长尾失效还在:反馈太稀、等待太久、更新太猛、奖励太假。

这一讲是「训练篇」的收束双讲。上半场 6a《Training 3: Advanced RL Algorithms》(Graham Neubig,L11 讲义 58 页)从算法侧逐一接住这四个失效,外加一条向教师学习的助攻。

下半场 6b《Training 4: RL Systems》(客座讲师 Apurva Gandhi,L12 讲义 43 页,里程碑是 Assignment 2 due: Eval)换到系统侧。

它把一条轨迹背后的两台引擎拆开看:推理引擎与训练引擎各自优化什么、靠什么对话。

两节课共用同一个贯穿案例:训练一个修 bug 的 coding agent,拿测试当 verifier。它从第 3 讲的 Coding Agents 一路陪到本讲收尾,算法侧的每个公式、系统侧的每笔账,都落在这个案例上。

顺带说明编号:官网一讲含 a/b 两节,slides 按学期总讲次编号,第 6 讲对应的就是 Lecture 11 与 Lecture 12 两份 PDF,分别是 6a 与 6b。两段课程录像各约 68 与 66 分钟,与讲义同步上线。

这一版对齐官方两份讲义:lecture-11-rl-advanced.pdf 共 58 页,lecture-12-rl-systems.pdf 共 43 页,都是 2026-10-14 当天新传上线。

页码随文以 L11 p.X/ L12 p.X 标注。讲次页本讲地图的卡片可下钻到对应分节详解。

把它当成课前预习、课后消化用的地图,而不是课程实录;数字与案例只出自这两份讲义及其引用文献。

一、修 bug 的贯穿案例:REINFORCE 的死角

任务很朴素 (L11 p.3-4):修一个 retry_count 函数的 bug。函数体是 config.get("retries") or 3,期望行为四种情形各查一个单元测试:Missing→3、None→3、0→0、2→2。这个例子沿自第 3 讲 Coding Agents 的 slides。

一条轨迹 τ 是 agent 的一次完整尝试:Inspect 读代码 → Edit 改 → Test 跑测试 → Revise 再改 → Test again。成功定义 R (τ)=1 当且仅当 4 个测试全过。注意奖励只看结局:中间改得好不好、测试跑了几轮,R 一概不知。

训练循环还是老三样 (L11 p.5):Sample 当前策略采轨迹 → Score 用 verifier 打分 → Update。

记号 x/θ/p_θ(τ|x),目标 J(θ)=Eτ∼pθ(⋅∣x)[R(τ)]J(\theta)=\mathbb{E}_{\tau\sim p_\theta(\cdot|x)}[R(\tau)]。

纯 REINFORCE 的损失是 LPG=−R(τ)∑tlog⁡πθ(at∣ht)\mathcal{L}_{PG} = -R(\tau)\sum_t \log \pi_\theta(a_t|h_t)(L11 p.6)。它在 agent 场景里有个安静的死角:失败尝试 R (τ)=0,整条梯度为零。

模型从「做错了」里学不到任何东西,连「别这么改」的负向信号都没有。

修 bug 偏偏是高失败率任务:早期策略十条轨迹九条挂零,九成采样预算不产生任何更新。

6a 的讲座地图 (L11 p.2) 就是围绕这个死角排的课程表:有用的反馈、更少等待、稳定更新、可靠奖励、向教师学习,分别对应信用分配、异步、重要性采样与裁剪、verifier 审计、蒸馏。

这份课程表就是接下来四节加第五节的目录。下一讲的 RL Systems,内存、并行与大规模执行,由 6b 提前剧透。

二、信用分配三部曲:组均值、Critic 与过程奖励

第一层:组内比较 (L11 p.8-9)。对同一任务采 4 条轨迹,奖励 1、0、0、0,拿组均值 0.25 当基线:成功轨迹更新权重 +0.75,三条失败轨迹各 −0.25。失败开始贡献负向信号,压低自己被再采的概率,这就是 GRPO 式基线。

第 5 讲算过它的完整版,减均值再除以组内散布;本讲关心的是它救了什么。三失败的组在纯 REINFORCE 里没有任何更新,减均值后每条轨迹都携带信息。

但它的粒度也在这层就到头了 (L11 p.9)。组权重对整条轨迹的所有动作一视同仁,而成功轨迹里可能含错误动作,比如第一步就改错文件、绕一圈才回来。

失败轨迹里也可能含有益动作,定位很准、最后一步手滑。组比较奖惩的是整条路,想区分到步,得进第二层。

第二层:reward-to-go 与 critic (L11 p.10-16)。reward-to-go RtR_t 只累计当前动作之后的奖励:A 轨迹只有末端奖励 r6=1,从第 3 步往后看 R₃=0+0+1=1。

对比另两条每步都有奖励的轨迹,A 每步 R_t=1、B 每步 R_t=0。动作只被它之后的奖励加权,更早的奖励与它无关,去掉只降方差不引偏差。

有了 R_t 就能学价值函数 Vμ(h)=Eμ[Rt∣h]V^\mu(h)=\mathbb{E}_\mu[R_t|h],用采样估计:从某历史 h₃ 出发续采 10 次、3 次成功,V (h₃)≈0.3。

critic 用平方误差训练 LV=Et[(Vϕ(ht)−Rt)2]\mathcal{L}_V=\mathbb{E}_t[(V_\phi(h_t)-R_t)^2]:若 V_φ(h₃)=0.6,该点 MSE=0.30;最优预测恰是均值 0.3,此时误差 0.21(MIXER)。

结构上有两种取法 (L11 p.14)。一是独立 value 网络,value loss 训整个网络,例 InstructGPT 附录 C.4;二是挂在 policy body 上的线性 value head 加 stop-gradient,只训 head 不动主干,例 MIXER。

前者表达力强,要多养一个模型;后者省资源,但基座与头耦合。

再往前一步是 TD 误差 δt=rt+1+Vϕ(ht+1)−Vϕ(ht)\delta_t = r_{t+1}+V_\phi(h_{t+1})-V_\phi(h_t)。值序列 0.3→0.6→0.4→0.0、中间奖励全 0,给 +0.3/−0.2/−0.4。每个 δ 都在说实际比预期好多少、差多少。

GAE 把它们指数衰减加权:λ=0.5 时 A^3=0.3+0.5×(−0.2)+0.25×(−0.4)=0.1\hat{A}_3 = 0.3+0.5\times(-0.2)+0.25\times(-0.4)=0.1。

递推式 A^t=δt+λA^t+1\hat{A}_t=\delta_t+\lambda\hat{A}_{t+1}。λ 从 0 拨向 1,估计从偏差大方差小的一步自举,滑向无偏差方差大的 reward-to-go 蒙特卡洛。偏差换方差,一个旋钮调完。

第三层:过程奖励模型 PRM (L11 p.17)。critic 的监督信号还得从别处来,Let’s Verify Step by Step 干脆用人工步骤标注当 value 的代理。

解 5x=6x−14,标注者判「x=7」这一步错误,正确解是 x=14。每一步都有分,不再等最后开奖。

代价写在方法名里:步骤级标注不便宜 ——PRM800K 为控成本只标到第一个错误为止,而且标注者之间对哪一步算错未必一致。

一句话记住三部曲

组均值先问组内谁更好,critic 与 GAE 再问这一步比预期好多少,PRM 直接给每步打分。粒度每进一级,标注成本也涨一级。

三、长轨迹上比值会爆炸:重要性采样与裁剪六家

先解决「更少等待」(L11 p.19-20)。同步 RL 要整批轨迹全部完成才能更新,GPU 甘特图上 generate 与 update 交替排布,中间夹着大段等最长轨迹收尾的空闲。

异步 RL(AReaL)让 rollout worker 持续生成,learner 拿已完成的轨迹随时更新,两条流水线各跑各的。

代价是 staleness:learner 更新了若干轮之后,还在飞的 rollout 用的仍是旧权重,部分轨迹来自更旧的策略版本。

于是 rollout 策略 μ 与 learner 策略 πθ 的动作概率已经错位 (L11 p.22)。

同一个历史下,“Check None explicitly” 从 0.40 漂到 0.70,“Use get (…,3)” 从 0.40 跌到 0.20,“Keep original code” 从 0.20 跌到 0.10。

修正的数学工具是重要性采样 (L11 p.23):Ea∼πθ[R(a)]=Ea∼μ[πθ(a∣h)μ(a∣h)R(a)]\mathbb{E}_{a\sim\pi_\theta}[R(a)] = \mathbb{E}_{a\sim\mu}\left[\frac{\pi_\theta(a|h)}{\mu(a|h)}R(a)\right]。

在 μ 的样本上乘一个比值,期望就回到了 πθ;权重例 1.75 与 0.50。

单步还好,长轨迹就炸了 (L11 p.24):整条轨迹的比值是逐 token 连乘 w(τ∣x)=∏tπθ(at∣ht)/μ(at∣ht)w(\tau|x)=\prod_t \pi_\theta(a_t|h_t)/\mu(a_t|h_t),单步 1.05 乘 100 步约 132。高方差,少数样本主导更新。

CTPO 在工具调用数学 rollout 上的实测更直观 (L11 p.25):累积比值随 token 位置后移散布越拉越大,几百 token 之后个别样本的权重已经是天文数字。

更隐蔽的一层 (L11 p.26):早期动作改变了后续历史,即使下一个动作的比值恰为 1,到达该历史本身的概率也只有 0.10/0.40=0.25。比值账只管给定历史下的动作;走到这个历史的概率没进账,off-policy 的程度就被低估了。

哪些 token 该进权重?各家分道,CTPO 的对照表在 L11 p.27。

  • PPO/GRPO:只用当前 token 的比值。
  • CTPO:用截至 t 的全部动作。
  • Full ratio:用全部。
  • GSPO:用全部,但按整条响应长度归一化。
  • DAPO、CISPO:同用当前动作比值,clipping 规则不同。

裁剪的动机就在 stale rollout 的大权重与少数样本主导 (L11 p.29-30)。token 级 ρt=πθ(ut∣u<t)/μ(ut∣u<t)\rho_t = \pi_\theta(u_t|u_{<t})/\mu(u_t|u_{<t}),ct=clip(ρt,ℓ,u)c_t=\mathrm{clip}(\rho_t, \ell, u),示例界 0.8/1.2:ρ_t>1.2 或 ρ_t<0.8,就被夹回边界。

PPO 取 J=E[min⁡(ρtA^t, ctA^t)]J=\mathbb{E}[\min(\rho_t\hat{A}_t,\, c_t\hat{A}_t)](L11 p.31),min 里取原始项与截断项的较小者。

A=+1 时超上界不再加奖励,A=−1 时低于下界不再加重惩罚,不对称;ε=0.2 示意曲线改编自 PPO 论文 Fig.1。

CISPO 取 J=E[sg(ct)A^t⋅log⁡πθ(ut∣u<t)]J=\mathbb{E}[\mathrm{sg}(c_t)\hat{A}_t\cdot\log\pi_\theta(u_t|u_{<t})]:夹后比值经 stop-gradient 只作固定权重,乘 log 概率。ρ_t>u 或 ρ_t<ℓ,只改这个固定权重的数值;梯度走 log 通道不走比值通道,天然免疫比值的连乘爆炸。

clip 之外还有两个温和阀门 (L11 p.33-34)。参考模型 KL,max⁡θJpolicy−β DKL(πθ∥πref)\max_\theta J_{\text{policy}} - \beta\, D_{KL}(\pi_\theta\|\pi_{\text{ref}}):π_ref 是训练起点处冻结的固定锚,不管策略怎么漂都拽着,DeepSeekMath 的 GRPO 目标用的就是它。

熵奖励 max⁡J+αH(πθ)\max J + \alpha H(\pi_\theta) 让分布更宽、鼓励尝试,但更宽不保证有用;第四节的探索崩溃会回头用它。

L11 p.35 的算法总结表值得抄进笔记,六方法 × 四维度:

方法优势来源critic进重要性权重的动作裁剪方式
REINFORCEreward-to-go无不用比值无 clip
PPOGAE critic独立 value 网络当前 token原始与夹取项取 min
GRPO组比较无当前 token同 PPO
CISPO组比较无当前 token夹后比值作固定权重(sg)
GSPO组比较无整条响应(长度归一化)响应级比值上取 PPO min
DAPO组比较无当前 tokenPPO min 但上限更高

其中组比较的定义是减组均值、再除以组内奖励散布;「进重要性权重的动作」一列是各家的分水岭,其余三列都可以从这一列推导。

读表的姿势:先看 REINFORCE 这一行,全空,当作坐标原点;再看 PPO 补了什么,critic 与 min。

最后看 GRPO 把 critic 换成组比较,CISPO/GSPO/DAPO 又在裁剪端各自走了多远。一条从 2017 到 2026 的演化线就串起来了。

轨迹越长,比如多轮 agent,越该倾向序列级或固定权重方案压方差。多轮 agent 训练选算法,先看这一条。

四、Verifier 也会骗人:假阴、假阳与独立审计

组比较还有个隐含前提:组内奖励得有差异。全败 (0,0,0,0)、全过 (1,1,1,1) 这类全组同分的组,减均值后优势全为 0 (L11 p.37),「无信息组」白烧采样预算;混合组如 (0,1,0,1) 反而每条都有信息,是动态采样要留下的样本。

碰上全败先做三诊断 (L11 p.38):

  • verifier 质量:有效解被拒?查需求描述与失败测试本身。
  • 当前能力:换更强模型 demo 能否成功。问的是能不能,不是该不该。
  • 探索不足:各轨迹是否雷同,十条路走成一条路。

先看 verifier 质量。假阴性(L11 p.39):候选行为全对,但 verifier 要求代码精确含短语 value is None,写法不同但语义等价的有效解被拒。

后果不只是白扔样本:奖励里掺进了拟合措辞与实现细节的伪差异,模型会学会讨好 verifier 的措辞偏好。

这类缺陷会污染整个基准 (L11 p.40)。SWE-bench Verified 的进度在 80.9% 附近放缓,剩余失败多有测试缺陷,OpenAI 2026-02 审计后已不再将其作主评测。

τ-bench Airline ≈70% 是任务不一致,Retail ≈92% 是标注错误(SABER 审计;2026-02 发布了 task fixes 修补)。

假阳性(L11 p.41) 则是 reward hacking 的起点:verifier 只测 retries=0 的情形,候选恒返 0 拿满奖励却错 3 个用例。奖励给了,bug 没修。

环境能力清单就是作弊通道清单 (L11 p.42)。

  • 能联网:找已发布题解照抄。
  • git 历史含未来 commit:直接复制仓库里后来的官方修复。
  • 持有模型 API key:调更强模型替自己干活,PostTrainBench §5.4 Fig.7 实测 agent 真的这么干了。
  • 能看测试与 runner:不改 bug 直接过测试,MAI-Thinking-1 的案例。

审计环境的第一步就是把能力列成清单,每多一种能力就多一条要封的通道。

对策是独立验证三栏 (L11 p.43):训练奖励、未见任务上的独立成功率、成本与失败,即工具调用数、回归、重复动作,三者并行追踪。

独立成功率在训练循环外,不归 reward 管;奖励涨而独立指标不涨,就去查捷径。

工程补丁还有三个。一是 DAPO 动态采样:跳过等奖励组、保留含失败轨迹的混合组、持续采样到 batch 满 (L11 p.44)。

二是部分奖励:4 个检查每项 0.25 分,0/4、1/4、2/4、1/4 的组从优势全 0 变成 −0.25/0/+0.25/0,梯度重新有了分辨率 (L11 p.45)。

三是警惕辅助奖励的反噬 (L11 p.46)。GPT-5.1 把浏览器当计算器用,还假装搜过,这是 web-tool 浅调用给分的 bug。

“Nerdy” 人设的奖励让 goblin/gremlin 隐喻泛滥到脱离人设提示本身。辅助信号一旦可被单独优化,就会被单独优化。

最后是探索崩溃 (L11 p.47):动作概率 A 0.20→0.01、B 0.60→0.98、C 0.20→0.01,策略把概率质量全押在一条路上。熵奖励加轨迹多样性检查是常备药。

五、向教师学习:课程、蒸馏与 On-Policy 变奏

RL 采不动的任务,让会做的老师带 (L11 p.49)。课程学习三段推进:先用 demonstrations 热启动,模仿教师示范,把策略拉进偶尔能成功的可学会区;再在可学会任务上跑 RL,奖励不再是全零;最后上更难任务。

两个防坑细节:旧任务留在混合数据里防遗忘;用固定评测集衡量真进步,课程变了,尺子不能变。

蒸馏 (L11 p.50) 让学生在固定教师轨迹上匹配教师的动作分布,如 q (・|h₃)=80%/20%。它的问题与第 5 讲的暴露偏差同构:学生自己犯错会走到训练集里没有的历史,那里没有教师标签可学。

教师只在自己走过的路上留了脚印。

GKD (L11 p.51) 让学生自己 rollout 产生历史,教师在那些历史上给目标,训练分布永远是学生自己的分布。

目标用反向 KL (L11 p.52):student 0.5/0.5 对 teacher 0.8/0.2,DKL=0.5log⁡(0.5/0.8)+0.5log⁡(0.5/0.2)≈0.223D_{KL} = 0.5\log(0.5/0.8)+0.5\log(0.5/0.2)\approx 0.223。

损失 LOPD=Eh∼dμ[DKL(πθ(⋅∣h)∥q(⋅∣h))]\mathcal{L}_{OPD}=\mathbb{E}_{h\sim d^\mu}[D_{KL}(\pi_\theta(\cdot|h)\|q(\cdot|h))]。

OPSD (L11 p.53) 更进一步:冻结初始模型当教师,教师的输入是学生历史加上已验证的解答。不需要外部强模型,自己教自己,教师只是 “没被 RL 动过的自己”。

六、一个训练步的五段旅程:双引擎与权重往返

换到 6b。为什么不能裸写 PyTorch (L12 p.4)?optimizer.step()/model.backward()/model.forward() 只覆盖训练循环的中间一步。rollout 要跟环境与 agent harness 打交道,verify 要跑测试,权重还要在两套系统之间来回搬。

RL 框架真正要支持的是 (L12 p.3)θ+=σt(R(τ)−b)∇θlog⁡πθ(at∣ht)\theta \mathrel{+}= \sigma_t(R(\tau)-b)\nabla_\theta\log\pi_\theta(a_t|h_t)。

外接 env.verify 换奖励、env.state/step 换状态,再套一层 agent harness。

核心事实是两种本质不同的 workload (L12 p.5-6)。“sample” 是推理引擎的活,vLLM、SGLang 这类系统:decode 重、自回归串行、无梯度。

它的优化清单全是推理侧的:KV caching、Radix/Prefix caching、continuous batching、投机解码 / MTP、模型分片。

“forward_backward” 是训练引擎的活,Megatron、FSDP2 这类系统:prefill 式计算、可并行、走 autograd。

它的优化清单是训练侧的:activation checkpointing、prefix sharing、batch sample packing、模型分片(PP/CP/EP)。

同一个模型,两套权重,两套完全相反的优化方向。本讲把这叫「双引擎」。两台引擎之间只有两样东西在流动 (L12 p.7):rollout / 轨迹数据从推理流向训练,weight sync 从训练流向推理。

一个训练步因此分五段 (L12 p.8),每段各有归属:

第三段躲不掉:rollout 时没有梯度,训练侧必须自己重算一遍对数概率,不能直接复用推理引擎算好的 logprobs。

权重往返本身是笔大账 (L12 p.16):1T 参数 bf16 全量广播约 2TB,每步都搬一遍谁也受不了。RL 相邻两次更新间约 99% 的参数不变,delta sync 只同步增量。

还有一个容易被忽略的工程细节:训练引擎与推理引擎的分片布局不同,TP/PP 的切法各异,同步时要按推理引擎的并行布局重分片,PULSE 做的就是这件事。

更细的坑 (L12 p.17):微小数值差异会让 MoE 在训练时选了不同的 expert,前后不一致的软专家路由直接毁掉梯度。

Rollout Routing Replay(R3)把 rollout 时的专家选择记录下来、在训练中重放;代价是推理引擎必须把路由决策随轨迹一起传给训练引擎。

七、Rollout 经济学:KV 缓存、前缀共享与投机解码的账本

先算 KV 账 (L12 p.9):自回归解码每生成一个 token,过去所有 token 的 K/V 都得留着 attend,KV 占用随上下文线性涨。

Llama-3-8B bf16 每 token 约 128KB,一条 32k token 轨迹约 4GB,64 条约 256GB。不优化,显存先于算法崩溃。

这笔账里最大的折扣项是重复。prefix 缓存把上下文分成两段 (L12 p.10):可复用前缀,system prompt 加工具目录,只算存一次;新算后缀,即任务 prompt。

agentic RL 特别受益:GRPO 组内多条 rollout 共享任务 prompt,多轮交互还能跨 turn 复用历史 KV(SGLang RadixAttention、vLLM Automatic Prefix Caching)。

推理侧另有连续批 (L12 p.11)。静态批的空闲槽位要等最长请求跑完才能整批换人;连续批按 decode 步粒度回收补位,谁生成完谁下岗。

通常配合 chunked prefill,或索性 prefill/decode 分离部署,Orca 的迭代级调度是这条路的开端。

投机解码 (L12 p.12) 省的是 decode 步数:drafter 用 MTP 头或小模型,一次猜 k=4 个 token,policy 一次并行验证,拒绝采样保证输出分布与 policy 精确一致,加速而不失真。

但 RL 有个特有坑:策略每步都在变,冻结 drafter 的接受率会持续衰减,需要 SFT / 蒸馏这类在线辅助目标持续养 drafter。

训练引擎有同型优化 (L12 p.13-15)。activation checkpointing 对付显存:只存每层输入,backward 时逐层重算中间激活,代价约 +33% 的一次前向。

选择性重算只重算 attention 部分,能把代价再压低,Chen 2016、Korthikanti 2022 两篇是出处。

prefix sharing 是前缀缓存的训练版:GRPO 组共享 prompt,多轮共享历史,前向 + 反向对共享前缀只算一次。

用 tree attention mask 表达一棵共享前缀树,各分支独立位置编码,梯度在各分支汇聚后流进共享 prompt。

收益有实测背书:长 prompt GRPO batch 中 80–95% 是重复 prompt token,去重后 actor 更新最快 6×(Snowflake ZoRRo)。

AReaL-DTA 用前缀树把 τ²-bench 多轮 rollout 压缩 9.43×,DFS 逐条 root-to-leaf 遍历,最高 8.31× vs 稠密训练。

再往上就是并行策略 (L12 p.15)。Context Parallelism 让各 GPU 只留住自己的 Q,KV 块在 GPU 间轮转交换,连同 TP/PP/EP 构成长上下文训练的分片全家桶,NeMo 手册的配图值得一睹。

这本账怎么记

省重复永远优先于砍内容:先量重复率,GRPO 组 80–95% 是重复 prompt;再上前缀缓存与 prefix sharing 这对同型优化,一个在推理侧、一个在训练侧;最后才轮到截短轨迹这类伤信用分配的下策。

八、Agentic RL 的暗坑:模板、Token 与陈旧策略

三个坑:训练器与 rollout 器各看各的场景。

其一,sequence extension (L12 p.19-20):多轮 agent 的历史怎么拼进上下文?Harness A 每轮追加完整历史,T A₁O₁A₂O₂…;Harness B 每两轮压缩观察,保留 T,把 A₁O₁A₂O₂ 摘要成 S。

训练批视角看得很清楚:一条轨迹的优势 Â 会广播到该轨迹所有动作 token 上,loss mask 在 Task / 观察 token 上为 0、动作 token 上为 1。B 方案里每轮重复出现的 Task token 没有直接 loss,却仍占着上下文、耗着计算。

结论:尽量保持精确前缀、能拼多长拼多长。压缩历史省下的上下文,往往又在重复前缀的账上赔回去。

其二,chat template (L12 p.21-22):Qwen3/3.5 的默认模板会把 reasoning 从历史中删掉,模型上一轮想过什么,下一轮自己也看不见,sequence extension 直接被模板破坏。

agent RL 框架因此自带定制模板 /renderer(Tinker、PrimeRL),别信默认模板会替你保住历史。

其三,TITO (L12 p.23-24):rollout 数据应以 token 而非字符串存传。chat template 加个空白这类字符串空间的小变换,会让训练侧重新 tokenize 的结果与推理侧实际用的 token 不一致。

前后两套 token 序列对不上,梯度就训在不存在的轨迹上。

机制上 tokenize 一一对应、detokenize 多对一,字符串往返一次必失真。所以从采样到训练全程走 token。

异步 RL 把暗坑经济学化 (L12 p.25-26):重叠推理与权重更新,消掉长 rollout 的 GPU 空闲。代价还是 staleness,要用第三节的重要性比值与裁剪来修正。

Sync 是训练推理同卡共置,简单但互相等;Async 是 GPU 分组各跑各的。

agentic RL 常 rollout-bound,推理: 训练 GPU 可到 3:1,需要 continuous batching 加 in-flight weight update:推理引擎边服务边热更新权重,这是它专为 RL 演化出的能力(Pipeline RL、AReaL;SGLang 文档有示例)。

复杂 harness,比如子 agent 与上下文压缩,另配 RAO/RLM 一类递归优化框架 (L12 p.27)。

收尾的调试指标表 (L12 p.43) 是全讲最实用的一页,八个指标各盯一种死法:

指标异常时说明什么
reward / pass@1多步平坦,或训练涨而留出集降 = reward hacking
pass@kpass@1 升而 pass@k 降 = 多样性崩溃
entropy骤降趋 0 或跳变 = 退化文本
importance_weight_maxπ_train/π_rollout 最差 token 比值;尖峰 = 数据 stale
grad norm尖峰先于发散
average staleness数据落后多少个权重版本
trainer MFUpadding / 不均衡 / 小 microbatch 会拉低
timing(rollout/update/stall/total)stall>0 = 训练器在等 rollout

九、服务化 RL:单控制器、中间人与多租户

系统设计有两端。一端是 SPMD 单程序多数据 (L12 p.30):一份 Python 跑所有 rank,dist.new_group 把 GPU 分成 train [0–3] /infer [4–7] 两组,权重经 publish_weights_async 异步发布,推理侧 refresh_weights_if_ready 就绪即刷。

单程序直控一切、写起来直白;但任何新算法都要改这份程序,欠灵活。这是 AReaL 的早期形态。

另一端是 everything-as-a-service 加单控制器 (L12 p.31-33):把训练循环拆成五个服务。

  • Agent Service:跑 harness。
  • Env/Reward Service:环境与打分,走 Open Reward Standard。
  • Orchestrator/Controller:CPU 上的轻量训练循环,只发指令不算梯度。
  • Trainer Service:如 Tinker training API。
  • Inference Service:SGLang/vLLM API。

外加 Weight Sync Service,可托管如 OpenReward 或自托管。这套拆法的好处有三层,讲义用三页讲它。

  • 关注点分离:轻量编排器让研究者不动重依赖就能试算法。
  • 发版解耦:换一个 SGLang 版本不必重训 Megatron。
  • 模块化:同协议即可换实现,比对评测变成本地改动。

中间还有个巧妙解法对付 harness 碎片化 (L12 p.29)。要支持 Codex、Claude Code、OpenHands、Pi、Hermes、Prime Agent 等各家 harness,反模式是每个 harness 手写一套 rollout / 环境代码。

正解是 middleman:代理服务把 chat-completions、responses、anthropic 等协议都扮一遍,harness 以为自己在调真模型,实际后面是你的训练管线,换 harness 零代码改动。

再配 rollout store,存 logprobs、路由决策等训练要用的副产物(Agent Lightning 的设计)。

这套架构的延展性一路铺到生产 (L12 p.34-41):弹性扩容,动态加推理控制器或节点;多集群异构算力,8×H100 与 4×Mi350 挂同一编排器;多策略训练,微服务架构便于同时训多个模型、异构策略做多 agent rollout。案例是 AstraFlow。

两个生产数字最值钱。Cursor 的实践是 Composer 每 5 小时从真实用户交互出新 checkpoint(AReaL 2.0),在线 RL 在这里已经是部署后滚一版的工程节奏。

多租户多 LoRA 训练里,8 个 LoRA 并发跑的总吞吐优于 8 个串行,代价是单 run 端到端时间变长,需要 Grouped-GEMM/SGMV 特殊内核撑住(SkyRL 与 Trajectory Labs;Punica 一脉)。

Tinker 是解耦训练服务设计的先驱:每 run 一个 training client、每 LoRA checkpoint 一个 sampling client,租户之间互不感知。

下一讲预告:Sandboxing and Credential Management,沙箱与凭证管理,接着本讲的作弊通道清单往下讲。

论文与材料导读

本讲官方未设 readings(6a 无 readings 字段、6b 连 references 都没挂),6a 讲义反而自带 25 条 references、逐页挂在对应幻灯片上,读单是现成的。以下按它的幻灯片挂接顺序、辅以 6b 讲义引用,给扩展导读:

  • GAE(Schulman et al., ICLR 2016, arXiv:1506.02438):λ 指数衰减加权 TD 误差的原始推导。第二节那串 0.3/−0.2/−0.4 数值例的出处,读它看偏差 - 方差权衡怎么变成一个旋钮。
  • PPO(Schulman et al., 2017, arXiv:1707.06347):clip 目标与 Fig.1 那张不对称曲线。第三节的 min (ρÂ, cÂ) 与那对不对称行为全部来自这里。
  • Let’s Verify Step by Step(Lightman et al., 2023, arXiv:2305.20050):过程奖励模型 PRM 的实证 —— 每步打分胜过只看结果,5x=6x−14 的步骤标注例出自它的 Fig.1。
  • DeepSeekMath(Shao et al., 2024, arXiv:2402.03300):GRPO 出处,也是「参考模型 KL 锚」的目标函数来源(L11 p.33 直接引它的目标式)。
  • 裁剪变奏四篇:MiniMax-M1 的 CISPO(arXiv:2506.13585,夹后比值作固定权重)、GSPO(arXiv:2507.18071,序列级长度归一化)、DAPO(arXiv:2503.14476,Clip-Higher 与动态采样)、CTPO(arXiv:2605.07331,长轨迹累积比值的实测与 Table 1)。第三、四节的总结表与动态采样各有出处。
  • AReaL(Fu et al., 2026, arXiv:2505.24298):异步 RL 的 staleness 分析;6b 的 async、in-flight weight update、DTA 前缀树与 AReaL 2.0 的 Cursor 实践同出这条线。
  • MIXER(Ranzato et al., ICLR 2016, PDF):critic 的平方误差训练与线性 value head 结构 (L11 p.13-14);InstructGPT(arXiv:2203.02155)附录 C.4 是独立 value 网络的例。
  • 蒸馏三篇:Hinton et al. 2015(arXiv:1503.02531,固定轨迹蒸馏)、GKD(arXiv:2306.13649,on-policy 蒸馏与反向 KL)、OPSD(arXiv:2601.18734,冻结自己当教师)。第五节的三个变奏各对应一篇。
  • 奖励审计线:SWE-bench Verified 的引入与停用两篇 OpenAI 文章、SABER 的 τ-bench 审计(arXiv:2512.07850)、τ-bench task fixes、Lilian Weng 的 Reward Hacking 综述、PostTrainBench(arXiv:2603.08640,API key 作弊通道)、MAI-Thinking-1 报告、OpenAI 的 calculator hacking 与 Where the goblins came from—— 第四节的每个数字都能在这条线上找到原文。这条线值得整条读下来,讲的是基准自己也会坏。
  • 课程学习与奖励塑形:Curriculum Learning(Bengio et al., 2009, DOI)与 Policy Invariance Under Reward Transformations(Ng et al., 1999, PDF)是第四节部分奖励与第五节课程的理论底座:什么形式的奖励改动不改变最优策略,什么形式会。
  • 6b 系统线:讲义引用的 Orca(连续批 / 迭代级调度)、投机解码(Leviathan et al., 2023)、Agent Lightning(middleman 设计)、Snowflake ZoRRo(prefix sharing 6×)与 PULSE(delta sync)都在 slides 内引用;官方未挂 readings,6b 的正确读法是把那份 43 页讲义本身当论文读:每个数字(128KB、256GB、99%、3:1、6×、9.43×)都值得在自家集群上复算一遍。

完整资料库见本讲资料区。

实践视角

这套双讲离个人开发者比想象中近。三个体会:

  • 八指标看板是最便宜的自查:不用等大规模训练,任何在跑的 GRPO/LoRA 小实验都能抄 L12 p.43 那张表。timing 里 stall>0 就去查 rollout 瓶颈;importance_weight_max 出现尖峰,说明数据太 stale 或少数 token 主导更新;entropy 骤降,要赶在退化文本出现前干预。全是训练器顺手就能记的标量,比盯 loss 曲线信息量大得多。
  • middleman 思路超出 RL 框架:给 SecondPal 这类本地 agent 换 harness 或换模型供应商时,代理服务模拟推理 API、业务代码零改动的解耦方向同样适用,换 Claude Code 还是换别家 harness,都不该动训练 / 编排代码;rollout store 顺手存 logprobs 的习惯,也是日后复盘的原始档案。
  • 算法侧先手算再写码:第二节的两串数字,组均值 +0.75/−0.25×3、GAE 0.3−0.1−0.1=0.1,就是现成习题;第五节的反向 KL 0.223 也是。

作业路线串成一条线:手算组均值与 GAE 数值例,把 PPO 与 CISPO 目标写成对照实现,两者差异只有 sg 与 min 两种用法,再按八指标搭一张自查看板。

阅读按 6a 二十五条 references 的幻灯片挂接顺序推进,6b 以官方 slides 的数字为准绳;本讲没有官方 readings,讲义本身就是读本。

本讲要点

  • 失败轨迹在纯 REINFORCE 下零梯度:组均值让失败开始教学,reward-to-go 与 critic 把信号细化到步,GAE 用 λ 在偏差与方差之间调档,PRM 给每步人工打分。粒度每进一级,标注成本涨一级。
  • 异步 RL 买来吞吐、欠下 staleness:重要性比值是还债凭证,长轨迹逐 token 连乘会爆炸(1.05 的 100 次方约 132),六家算法在哪些 token 进权重、怎么裁剪上分野:PPO 的 min 与 CISPO 的 sg 固定权重是两种代表,序列级方案 GSPO 为多轮 agent 而生。
  • Verifier 本身是攻击面:假阴拒掉有效解(要求代码精确含某短语)、假阳养出恒返 0 式捷径;环境能力清单即作弊通道清单(联网 /git 历史 / API key / 可见测试),独立验证三栏(训练奖励、未见任务成功率、成本与失败)是底线。
  • RL 采不动的任务向教师学:课程铺路、蒸馏热启动;GKD 让学生在自己 rollout 的历史上对齐教师(反向 KL),OPSD 冻结初始自己当教师。
  • 一个训练步五段:sample→verify→forward→backward→sync;推理引擎(decode 重、无梯度)与训练引擎(可并行、autograd)是两台优化方向相反的机器,中间流动的只有 rollout 数据与权重;delta sync 只传增量,R3 重放 MoE 路由决策。
  • Rollout 经济学的一切优化都在省重复:KV 账 128KB/token、64 条 32k 轨迹约 256GB,而 GRPO batch 80–95% 是重复 prompt,前缀缓存(推理侧)与 prefix sharing(训练侧,ZoRRo 最快 6×)是同型优化;暗坑三件套(模板删 reasoning、字符串存 rollout、异步 staleness)配八项调试指标自查。
  • 服务化是规模化终点:middleman 让换 harness 零代码,五服务 + Open Reward Standard 让组件可换、发版解耦;Cursor 的 Composer 每 5 小时从真实用户交互在线出一版,8 并发多 LoRA 吞吐反超 8 串行。

延伸阅读

概念回顾

翻卡自测 · 「再看看」的卡进入复习队列

别只读一遍——先看正面的问题,心里作答,再翻面对照。主动提取比重复阅读记得牢。

自测7 题 · 约 12 分钟即时反馈 · 答错的题自动进入复习队列先自己作答,再看解析——检索练习的效果来自「先提取、后对照」。数字键 1-4 可快选,Enter 提交。
01单选进阶L11 p.15-16 ↗

训练修 bug agent 时 critic 给出值函数序列 V(h₁..h₄)=0.3→0.6→0.4→0.0,中间奖励全为 0。对初始状态(V=0.3)取 λ=0.5 的 GAE 优势,结果是多少?

选项(单选)
02多选挑战L11 p.41-42 ↗

你的 coding agent 训练环境里:模型能联网搜索、能读 git log(仓库里混入了未来日期的 commit)、持有模型 API key、能读测试文件与 runner。按 L11 的 reward hacking 矩阵,哪些能力会直接变成作弊通道?(多选)

选项(多选)

多选题:选出所有你认为正确的选项后提交。

03单选进阶L11 p.30-32 ↗

PPO 更新中某 token 的概率比 ρ_t=1.5,clip 区间 [0.8, 1.2],该 token 的优势估计 Â_t=+1。这个 token 对目标的贡献与梯度最接近哪种描述?

选项(单选)
04排序进阶L12 p.8 ↗

按 L12 对一个 RL 训练步的五段分解,把下列步骤排成实际执行顺序:

排序(按顺序点击)

按你认为的正确顺序依次点击各项;点错可「重排」。选项展示顺序已打乱。

05配对挑战L11 p.27-35 ↗

把「进重要性权重的 token × 裁剪方式」的四种设计与其代表算法配对:

配对
只用当前 token 的比值,clip 项与未截断项取 min
整条响应的比值做长度归一化,在序列级裁剪
clip 后的比值经 sg 停梯度只作固定权重,乘 log 概率
当前 token 比值 + PPO 式 min,但裁剪上限放得更高
06单选挑战L12 p.9-14 ↗

Llama-3-8B bf16 下每 token KV 约 128KB,一条 32k token 轨迹约 4GB,64 条约 256GB。GRPO 训练中同任务采 8 条 rollout,system prompt+工具目录+任务 prompt 完全相同。评估以下主张,哪条最站得住?

选项(单选)
07简答挑战L11 p.43 ↗

你负责一个修 bug agent 的 RL 训练:第 3 天起训练奖励从 42% 一路涨到 71%,但产品侧抽查感觉「没那么好」。请设计一套独立验证方案(至少三个并行追踪的指标列 + 一条报警规则),并写出发现「奖励涨、独立指标不涨」后的第一步排查动作。

题目与解析 AI 辅助生成 · 人工审校。答错的题会按间隔重复节奏在复习页重现。

AI 生成 · 仅供参考,与课程方无关。选中正文里的任何一段也能直接问我(解释一下 / 举个例子)。

英文文字稿(YouTube 自动字幕机转,未校对)

So uh hi everyone. This time I’m going to talk about advanced RL algorithms for agents. Um one thing that I did in preparing this lecture was think of all the things that have gone wrong to me uh while training agents in the past year or two. Uh, and so what I’ll try to do

during this lecture is try to point out a problem that you will encounter when you’re training agents and a solution for it. And so hopefully if you’re encountering any issues during your assignments or during your your projects, the information here will be

useful to help you overcome them. I intentionally didn’t cover anything that doesn’t fix a problem that I’ve never had. So hopefully it will all be all be practical advice here. So we have three lectures on RL because it’s such a big part of AI agents

nowadays and we already covered the RL basics and today I will be covering some advanced algorithmic topics and then in the next lecture we’ll be talking about some advanced systems topics. And so what I won’t be talking about this time is you know how do you sandbox agents to

make sure that they you know don’t destroy your file system how do you uh run them in parallel uh th those sorts of things. Today we’ll mostly be with respect to the algorithms in the math. So I’m going to be using a running example during this entire lecture just

a very simple example of fix getting a coding agent to fix a bug. And so this is also similar to what I talked about in the coding agents lecture, but the prompt is uh fix the retry setting. Zero should disable retries, but the code returns three. Preserve the other cases.

And the initial state is buggy code. And we have a verifier uh that runs tests. And all of these tests need to pass in order for you to get a reward of one. Of course, you can slot in any example that you want here. It could be a math uh problem solving problem like we

talked about before. It could be a web navigation problem. It could be a deep research problem. You know, pick your favorite one. So, let’s look at what a successful trajectory for this task may look like. The first thing that the agent does in

this case is read the function. And it changes the default handling. Runs the four tests. One test still fails. It goes back and changes the code again and then it reruns the four tests and all four tests pass. So this is a successful trial of course, but in the middle it

made a mistake. So there there were some places where it didn’t do as well as it could and it probably could have done a better job had it, you know, not made that mistake. It would have finished more quickly. So of course the final reward here is

one. And so the RL training loop as we discussed last time basically what we do is we sample uh score and update and the this time I’ll be using a bit of math and so the thing that we want to

remember is basically we’re going to be trying to maximize the average reward on the task. We talked about a bunch of different ways to do this like reinforce and gpo the previous time but we’ll all be in service of this uh you know of this job and just to make sure everybody

remembers the math the uh symbols that we’re going to be using we have theta which is the parameters we have p of theta or pi of theta which is our policy tow which is a trajectory and r here which is a reward. So

if we look at what reinforce did and part of the reason why we decided not to uh use reinforce uh overall reinforce basically if you got a reward of one you would increase the likelihood of the output uh by essentially one and if we failed we would do nothing. we

would you know not update uh not update the policy there and this was good but as we mentioned in the previous time this is high variance and high variance is uh leads to optimization difficulties. So we want the uh failed attempt to

still provide a learning signal and we want to also come up with more fine grain rewards than just uh one and zero. So the first thing I’d like to talk about is credit assignment and more dense feedback. And so if we look at what we did with

the gpo previously, we would do something like sample four attempts to the same bug fix uh test task and then compute their rewards and use the group average as a baseline. So this looks like uh this where we get you know plus 0.75 for the positive

example and minus 0.25 uh for the examples uh other examples. one issue with this is that if you looked at a successful trajectory, the successful trajectory might have a mistake in the middle and then you recover from it. And so if you’re giving

a positive weight to all of the actions in the positive trajectory, then you’re also giving a positive weight to the mistake. And sure, that might be fine. you know, eventually it recovered and it did a good job, but in general, you don’t want it to make mistakes. So, if

you can avoid this, then you would like to avoid that. And then for failures, you might have the agent doing the perfectly good job up until, you know, around here, uh, but then suddenly at the end, it falls off the rails and and stops working. And so, you don’t

necessarily want to penalize all of the useful work it did just because it failed at the very end. So this is the idea of more having more fine grain rewards. So turnle rewards uh are a way to do this and there’s a bunch of different

ways to calculate them. So going back to the previous uh class we talked about reward to go. So reward to go is starting uh you know just before A3. how much reward remains on this trajectory. So we add the remaining ones and this

gives us uh the road to go uh big R3 which are the rewards received after H3. All good I think maybe you remember from the previous class. Cool. Okay. So if we look at what the reward to go looks like in the positive and

negative case, of course we’ll get one one one and 00 0. So if we reward the mistakes in the successful trajectory and the good parts of the uh failed trajectory with this obviously uh you know we’ll be not rewarding [clears throat] each

individual action in a fine grade way. So then the question is how can we estimate which turns helped when we only observe the final reward? Any ideas about this? What would you do to predict whether a uh an action was a good one or a bad one

when you only get from your environment whether the tests passed or not? >> Yeah. to to get finer rewards. >> You can write rubrics to get final fine grain rewards. Yes, that’s a great idea. We’re going to talk about it more later,

but that’s not what we’re going to do right right away. Yeah. >> R= actions that are shared. >> Look at all the rollouts that uh do get R equals one and see if there are common actions that are shared. I

think that’s a really good idea, but how would you like actually operationalize that? >> Okay. Um, I I think it’s a it’s a good idea, but it’s not the easiest thing to operationalize, I think. Yeah. We try to get a bunch of trajectories and see what

distinguishes successful sequences of actions pres >> Yeah. So I think it’s a pretty similar idea I guess you know like look at the shared actions and the trajectory. Um I

I think that’s good. you need some way to judge which action sequences are shared uh either with like exact overlap or with a language model or something like that. I’m actually not going to talk about that this time, but it’s definitely something you could do. Yeah.

spread across. >> Yes. So, um the the answer was maybe we could have multiple definitions of reward, not just the final success, but also whether it’s like a shorter trajectory or something. Uh yes, that’s great. I’m going to talk about that

later, too. Okay. Yeah, I I think these are good points. They’re actually uh none of them [laughter] are the ones that I was going to uh going to talk about next but um I I am going to talk about some of them farther down the line. So um

so the way the typical way that we do this is by actually training a model to predict whether it looks like the agent is going to be successful given the current state and use this as uh something called a value function. And so if we look at for example state

three and then we roll out 10 times after this then it succeeds three times and it fails seven times just you know in this particular example. And so if this is the case the expected reward here is uh approximately uh 3 divided by 10. So 0.3

and you know obviously sampling 10 is one way of doing it. If we sample infinitely we can calculate the expectation of the uh reward to go from here and that will become our value from our uh policy. So the problem is doing this at every

step would be prohibitively expensive of course because you need to roll out at every step and so we can’t do this uh realistically. But what we can do is we can learn to a something called a uh like a critic or a value function that predicts this expected reward to go. And

the way we parameterize this is with parameters fi. And given some prediction of the reward to go, we then train a model to predict this. um and then uh we train this with essentially a squared error loss. So the best answer uh if the average is 0.3

then is that we would uh then predict 0.3. And so we can you know parameterize this and train a model. Specifically how do we parameterize this? There’s two common ways of doing this. Uh the first one is more common

than the other one. But basically what we do is we feed in a history uh HT and we train a value network uh which is maybe an entirely different language model and that value network can make a prediction uh over you know what the reward is

going to be next. The other way that we can do this is um you can so this is good but the problem with doing this is that you need to train two models right and training one model is already hard enough. So another option that you can do is you can take

the body of the model that you’re training to do reinforcement learning or to do to be the policy and then add a linear value head on top of it and predict uh from the embeddings that you get from the model. And if you do this, this value head is tiny and so it’s

basically no extra parameters, but it still allows you to predict the value. And then uh one other thing that I should mention is there’s two I I think probably it it’s more common over here. But if you you’re on the left

side, there’s two ways that you can do this. Um one way that you can do this is you can actually have a regression head that just directly um predicts the value. And another way that you can do this is you can put like is this trajectory good?

Yes or no? And then predict the next token. And if you do this and you have a reward between one and zero, you can fit

the normalized probability of yes divided by the normal by the probability of yes and no and use that as your prediction. And so that that kind of only works if you have a probability, but this has been this is pretty effective because you can reuse um you

know kind of the the prior that the model has for making the predictions. basically if you do this um this allows you to get a model that can predict how likely you are to succeed uh going forward. And you can train this at the same time you’re you’re training your

model using RL. Is this clear? Any any questions? >> So my question is If the model is correct or not, why not just like correct? >> Great question. So um the the question

was if the model itself can tell whether the action is correct or not um why not just produce a correct action uh for the model. So one important thing about the value function is the value function actually doesn’t condition on the action in this case. It only conditions on the

history. And so it’s not actually predicting whether the action is good. It’s just predicting whether the history is good is one thing. So um the the second reason is sometimes it’s still a lot easier to tell you’re doing a bad job than to know what you would

need to do next in order to do a good job. So, you know, I’m sure we’ve all been in the situation where we think we’re doing a really bad job and wish we knew how to do better, but we don’t. So, um, in this case, discriminating between good and bad trajectories is easier than

like actually generating a good next. Cool. Um, so now we can predict how well we’re doing. Um, how do we actually use this in training? And there’s a number of ways that we do this. Um one uh thing that we can do is uh if we look at a series of actions like we have

action three, action four, action five, we have our before value, our after value, um before value, after value, before value, after value, and the reward. And we can add the reward, add the before

value or sorry add the after value and subtract the before value. And this essentially gives us an estimate of how good each step is like how much did increase the val uh the value function, how much did it decrease the value function. And so if your action was

really bad like let’s say you you accidentally deleted your codebase and suddenly your value function goes to zero then uh you’ll be able to see that and be able to see that it dropped the value a whole lot here and this is uh called the temporal

difference error and so uh this is signified as delta t where uh we take the reward after value minus before value. So, how can we turn this into like an actual reward for each of our steps?

The most common way to do this is generalized advantage estimation uh which is uh used in PO. And basically the way it works is we have um sorry used in a reinforcement learning algorithm called PO which uh is is pretty common. Um so essentially we

start with each of the temporal difference rewards and based on the temporal difference rewards we have a parameter uh lambda where this parameter lambda uh is basically exponentiated at each step and then we add the temporal difference

reward in all of the lambdas from the beginning. uh starting with uh lambda to the zero and then lambda to the one and lambda to the two and uh you can see that we essentially will get a reward for this step. So the step itself was positive. So we get a reasonable reward

here, but it was followed by two bad steps. And so what this means is essentially step three might have seemed like a good step itself, but then in the future it ended up uh having us make bad decisions. So it maybe is not so great. So we drop its temporal difference

reward by a discounted uh kind of change in the future. So now that we have this, as long as we can train a value model at each step, we can kind of estimate how good each step was. >> Got it.

>> So we kind of collect steps and then >> I mean the if I go back, sorry, I I think I had this a really long time ago. If I go back, I I was using um

mu. Yeah, sorry I can’t find it on the slides, but I I was using mu here. And mu is basically our rollout policy. So it’s whatever policy we use for inference. and that if we’re doing complete on

policy learning that will be the same uh like policy that we’re updating but I’m going to be talking about async learning where we do rollouts and updates with different policies but um like you can you can think of it as the same model we’re training

>> yeah It’s basically a hyper it’s a hyperparameter. Um a typical hyperparameter for this is one um when you’re training PO and what that means is essentially we’re not considering the temporal difference. We’re only considering the final reward

because if we don’t do any decay the it will be the difference in the value function every time. And you can kind of tell like if you if you add these up and you don’t have any discount then essentially each time these will cancel out and

you’ll only get the the last one. So sometimes often with PO we won’t do any uh we won’t do any temporal discount but you can set a temporal discount if you have a good idea that like number one you have a good value function and number two you have like or you have

like intermediate rewards uh through rubrics like what was mentioned before for instance. Cool. Okay. So this is uh this is the typical way of learning intermediate some sort of uh you know value estimate. Another way that you can do this uh

which has been used uh to some extent although not quite as uh not quite as widely is to train something called a process reward model. And what a process reward model is is it’s essentially a model that was trained a priority or separately from the uh learning process

to predict how good each step is. So in contrast to the value function which predicts you know directly as part of the the learning process the process reward model it is trained on some sort of annotations and so this uh paper uh let’s verify step by step this was a

kind of famous paper by open AAI kind of early in the uh reasoning model phase they basically just had a whole bunch of annotators annotate which of the steps was uh was useful. I would say this is not used very widely because you know you can learn it as a byproduct of

training but it could be a very good way to kind of bootstrap a value function. So if you are able to somehow get lots of these annotations you could learn an initial better value function which would make your training faster beforehand.

Okay. So the um the partial rewards are a good way to increase the stability of learning by giving you by you know giving the model a better idea of which actions are useful and which actions are not useful. So the next problem I would like to uh

consider is that reinforcement learning for agents it can be very slow. Uh and you will certainly experience this and be frustrated by it in your uh in your assignment. So this is an example of uh synchronous reinforcement learning. and synchronous

reinforcement learning. Basically what you do is you have uh you know three GPUs uh for instance where you have uh a model running on each GPU and you use each GPU to generate uh using an agent. Um it doesn’t necessarily need to be

split by GPUs either. You could just have like multiple agents sharing the same inference server on a single GPU. Either way, you want to have multiple agents running at once because agents running is is slow essentially. And here this figure is a little bit charitable

to the models or to like what actually happens. But in reality, if you’re training a coding agent, it will be very common to have one straggler that takes like twice as much time or four times as much time as all the others. So all the others are just sitting there and doing

nothing while you’re waiting for that one straggler to finish. Um then after that you do an update synchronously and then you generate again. So there is one advantage to this. Um does anyone maybe someone familiar with

reinforcement learning know what the advantage here is? Any ideas? >> Yeah. It’s on policy. So it’s completely on policy. And what I mean by that is the um the policy that is doing the

rollouts, the policy that’s doing the generation is exactly the same as the policy you’re updating because you know you’re doing the the generation and then you’re doing the updates. So we had uh the mu pi mu or p mu and then we had pi uh theta and in this case mu and theta

would be the same. So we’d have exactly the same thing uh generating and updating. So to fix the wait time, a method that you can use is async RL. Um and async RL basically what this does is it will do an initial it

will start initial rollouts. it will accumulate a batch of rollouts and then once you have accumulated a certain number of rollouts you’ll start doing an update but while you’re doing the update or while you’re calculating the update you

will continue generating and this is good obviously because you never waste time waiting uh to generate. The downside though is you’ve started generating here and here before the update is finished. So the generation uh either up to this point or up to this

point is using the uh old policy before the update. And so now when you do the second update um you need to consider the fact that essentially uh the parameters were different uh for part of the generation. So this is absolutely essential in

Aentic RL. Nobody who’s doing Agentic RL seriously would do synchronous updates now, especially now that the software has gotten pretty good to support um async updates. But the problem is uh this can lead to a lot of instability in in training your models.

So how can we what is the problem through math and how can we fix it? So this is an example of what it looks like when you have rollouts from an older policy. So if you have your rollout policy uh mu and your learner policy uh pi theta,

it might be the case that there is a very different probability for each of the outputs uh for your rollout policy and your learner policy. And what that means in math is essentially

um we are ignore this for a second. Um we want to calculate the reward according to the update policy but what we actually would get is the reward according to the um uh to the rollout policy. So fortunately there’s a way that we can

fix this uh important sampling and I I think maybe many or most people have heard of important sampling. How how many oh actually surprisingly few. It’s um so the way important sampling works is um if you have one distribution that you

want to sample from but you cannot sample from that distribution and instead you can only sample from another distribution. You can correct the expected value that you get by sampling from the sampling distribution by having this uh ratio here where you divide by

the probability of the original of the sampling distribution and multiply it by the probability of the distribution that you actually want to sample from. Um I ju just trust me [laughter] this is uh This is uh true if you haven’t encountered this before.

But this is the way that we can fix this problem because you know this is the distribution we actually sampled from and this is the one we want. So uh we can apply this importance weight uh which is uh an adjustment factor like this. And for instance if we have the

correct edit where the current one is 0.7 and the behavior is 0.4 we would get an importance weight of 1.75. And um uh we might get a importance weight of 0.5 uh over here. And so essentially this will um upweight ones that are more likely under the um under

the true distribution and downweight ones that are less likely under the true distribution. there’s um so this is good but the problem is if you just use the importance weight as is you can get a lot of instability

and the reason why is if you get e even if each action is only a little bit different within an agentic trajectory there could be many many actions you know 100 is a charitable interpretation you know an agent agentic trajectory will have like 50,000 tokens or or

60,000 tokens or something like this. So even if the differences are small, the number can get very very large. So that’s a problem. Uh but um yeah, so so that’s a problem. The

uh exactly how much of a problem it is depends on how far into the trajectory you go because you can actually calculate the variance of the log the expected variance of the log importance weight by using the fact that as you add numbers together their variance will go

up by the square root of the number of items that you add together as long as they’re IID. You can derive this from the law law of large numbers and how everything can conver converges to like a Gaussian distribution as you add more iid numbers together. And so this is uh

from a paper called CTPO where basically they um they actually measure this empirically on reasoning trajectories. And you can see that indeed it is going up by approximately the square root. So another thing that you need to worry about is that earlier actions uh do edit

uh do change later histories. And so the next action ratio is um you know one in general on average it will be one but uh you know you the you can have compounding effects and you can get very very large numbers here. there’s a number of ways that people

deal with this. Um the most common way that people deal with uh with this importance weight getting very very large is through P uh the method that is used in PO and GRPO. And the way they do this is essentially they throw away

they they don’t consider the fact that the importance weight is actually the product of these weights and they only consider the importance weight for the current action. And so this is not actually correct. It’s not actually the correct importance

weight for the next action, but it’s good enough and it gives you some idea of uh like gives you some idea of how unexpected the action is. Another way that you can do this is you can do all of the previous actions. The problem with doing all of the previous

actions is that it will get very big as I mentioned before. Um, and so in order to fix this, uh, both PO and G, uh, GRPO and CTPO do some variety of clipping to prevent the, uh, importance weight from getting too large.

You could also do the full ratio. Uh, this is bad for the same reason. You know, it would get very large. So there’s another method that was proposed called GSPO. And what GSPO does is it essentially divides by the sequence length. So it considers all of the

actions but then divides by the length of the sequence which brings it down to being in the same scale as uh what we use for PO and GRPO. this is a bit of detail but like long story short you want to use importance weights but you don’t want to let them

get out of uh you know out of control. And actually I I realize now that maybe I should have put this slide um should have put this slide earlier but this is actually um an actual experiment that we ran in my lab. Uh so thanks to Aditia one of the TAs for sharing this but this

is essentially the um importance weight the maximum importance weight that you get in any individual batch of training. And the orange the orange thing here is uh the importance way when you’re running asynchronous RL with a maximum off policiness of one. And so maximum

off policiness basically means how many updates can you do uh how many updates can intervene between the things you’re currently updating and the rollout policy. And so this means that you can only use rollouts from the previous policy. you can’t use rollouts from any

earlier policies. Um the green one is a maximum off policiness of three. So this means that you could have up to three updates since the previous uh since the previous policy. And so what you can see is and this is the maximum importance weight.

So you can see that around uh step 17 of his RL there was actually one importance weight that was 1,00 you know on the order of 1,400. Um, and so you can imagine what would happen if you have a multiple of 1,400 in your update. You’re going to

make a huge gradient step and mess up your model and you might completely destroy training uh destroy training overall. um any do people understand the basic idea? I’m going to talk about how we fix this

next, but is the basic idea clear? Okay, cool. Um, so the way we fix this, uh, is somewhat huristic. Um, but basically in the PO paper, they introduce a way of clipping the probability ratio and and actually I don’t think they introduce it, but they

they use it. A previous paper introduced it. it you take the uh you take the probability ratio or the importance weight and you allow it to expand linearly but then you clip it off uh after it gets above a certain size. So uh for instance uh in

PO the standard way of doing it is like uh 1.2 and 0.8. We don’t let it get any larger than that. And there’s a few ways that you can use this clipped importance weight. Uh the way that PO does it is they essentially multiply the clipped importance weight

by the advantage. Uh so you know like which will be positive if you have a good example, negative if you have a bad example and then you take the min here. Um, basically it’s a little bit hard to intuitively understand, but basically what it’s

doing is it’s um stopping you from updating uh any it’s stopping you from updating beyond kind of the the region where the importance weight is very high. Um and then siso is just another optimization algorithm and it does something similar uh except it clips the

importance weight directly. So this is um a little bit uh like more detail on what PO uh what the PO clipping looks like. So here uh what we do is for a helpful action for one where the advantage is possible we stop rewarding a ratio uh which is above 1

plus epsilon where epsilon is something like 0.2 too. And for a negative advantage, for an action that is not helpful, we uh we stop like negatively rewarding it after uh the ratio is below one minus epsilon. Cool. Um, so basically by doing this,

what we can prevent is we can prevent these really crazy spikes in importance weight from causing our model to go off the rails. Cool. Um, so actually maybe I should briefly uh

mention what will happen uh in this case. So typically what happens uh when you when you have a really bad spike and you don’t appropriately account for it is the model will suddenly start doing something degenerate and these can be things like repeating the same token

over and over again. Uh other things include generating really really long outputs, really really short outputs. uh these sorts of things and it’s kind of hard to say it’s going to be any individual thing. It’s just like suddenly things look really weird and

you don’t really know why. Uh it might be because of this. It might be because of other things but it’s typically because of some you know large gradient uh step that you took that uh that caused the model to go off the rails. And the problem is it’s hard to recover

from this because uh once you do that you start not being able to get advantages, not being able to get you know good rewards. So yeah, it it will fail. >> Can you just clip the gradient instead of clipping the

>> Yeah, you can you can clip the gradient also. I I think the importance weights tend to be the biggest cause of the gradients going out of the way, but you could clip the gradients as well. I I actually don’t know. That’s a good question. I don’t know whether that’s

like the most common practice or or not. So I’d have to go back and look. Cool. Okay. So, other ways that you can help uh prevent the model from go uh completely going off the rails is to have a reference model. And the reference model is essentially, you

know, your initialized model. And you can uh prevent the reference model uh you can prevent the KL divergence between the updated model and the reference model from uh becoming too diff different. And so essentially this will allow you to um to prevent big

updates as well. It’s kind of another way of doing it. But um maybe the more interesting thing specifically for reinforcement learning is another thing that can go off the rails is uh the entropy of your model either collapsing or exploding.

And entropy just uh to to make sure that people are awake. Uh what what does entropy mean either in mathematical or kind of uh you know intuitive terms? Yeah. >> Yeah. How broad the probability distribution is. So, um, that’s a good

good way of saying it. Another way of saying it is how likely are you to select a variety of different outputs instead of a single, you know, a single output. And so, if your entropy is very low, it means that your model is likely to sample the same thing over and over

again. If your entropy is very high, it means it will sample diverse things. And so the problems we often see in reinforcement learning are the entropy will go way down and the model will lose diversity and so it won’t have a bunch of different things to compare. So your

gpo loss will um will disappear as I’ll talk about in a moment. On the other hand, if the entropy goes too high, that means it’s sampling a bunch of random stuff and it’s not like actually likely to get good uh good results. So both of them can be a problem. And so you can

essentially um set entropy regularization to uh prevent that from happening. So I introduced a bunch of concepts one by one uh because I I feel like this may be a easier way to intuitively understand each of the algorithms. But

I’d like to finish up this part with a table of uh many of the algorithms that people use. And so the first one is uh the weight that you get from the reward, whether you have a learned critic. Um whether you have an importance ratio and whether you have clipping and basically

um reinforce like we talked about before uh very simple. We just use the reward to go. Um no importance ratio uh although you you could add that if you’re doing uh not fully on policy, no clipping. So very very simple. Um, PO uh uses the GA uh from the critic as I

introduced before. Um, it requires a learned critic and it uses a current token uh importance weight and I talked about the clipping. GRPO is the same as PO but it uses group comparison. Uh, siso is another example. It’s been used by the miniax models and other uh

other things like this. It has a different variety of it’s similar to PO but with GRPO but with a different variety of importance weight clipping. GSPO uh does the importance weight but it uses a whole response length normalized.

Um and uh one other and deo I’ll talk a little bit more about it in a bit but one interesting thing in this algorithm is they actually have asymmetric clipping. So they they use a larger

upper bound than they use a lower bound which is basically to reward positive example uh positive advantages more. Um and so basically it’s saying we want to we want to maximize the uh we want to maximize the like benefit that we get from the positive examples

and then clip the negative examples uh like a same amount. So um if you want to you can go go in and uh read more details in the papers but this is the high level overview of the differences. So next I’d like to talk about task selection and reward reliability. So

this is uh le maybe not exactly on the algorithmic side but it has to do with being able to tell if you’re going to get a good result from the training examples that you have. So if you’re using something like GRPO, a really good value to monitor is the percentage of

zero advantage uh outputs. And so or or nonzero advantage outputs. So in order to learn from gRPO, your outputs must have at least one negative example and at least one positive example because otherwise there’s no variance in the um in the uh

advantage and they all revert to the mean and you don’t get any uh you don’t get any gradient. So it’s a problem both if all attempts failed and if all attempts passed. So, oops. So, if we look at why every trajectory might fail, there’s actually

a number of reasons. Um, the first one is verifier quality. So, um, it might be the case that you actually got a correct answer, but the verifiers did not grade it as correct. And this is actually very very common. So, you

should be aware of this. Another one is uh current capability. The model itself might not be good enough. Um, another thing might be lack of exploration exploration. And so it might be that the model could do it, but it just didn’t uh didn’t get enough um outputs. And so

to check all of these, we can look at the requirements in the failed tests um whether stronger model demonstrations would succeed and whether the trajectories differ. for false negatives in the verifier, this is essentially if you have some

sort of test that is unachievable. in the running example that I’m using, ideally your test would you know directly test the inputs and outputs, but you could think of a bad verifier where it tested directly that value is none was included in the program or

something like this. And you might think this sounds very silly, but agents will write these sorts of tests all the time. Uh they’ll write, you know, tests that don’t actually test the underlying behaviors. So, uh you need to be very careful about this.

So, there’s a number of results of false negatives. Um the first one is reward noise. So, you know, if it actually got it right, but it got it marked wrong, you’ll get more noise in your reward than you actually need to have. Another problem with it is if you’re

looking specifically at benchmarks, benchmarks can plateau at lower values and so you might not actually be able to measure your actual progress. And so, basically, OpenAI has a blog post about SWEBench verified, which is actually, you know, a benchmark they created. So

they’re criticizing criticizing their own benchmark, but basically they said only about 81% of them are actually solvable. Um and if you look at the remaining uh unsolved ones, a lot of them are just verifier noise. Um and then another popular benchmark called

tobench at one point had a ceiling of about 70% on some tasks, 92 on other tasks. So something to be like even very popular good benchmarks can have this problem. So another issue is false positives. Um so false positives

can uh be the result of uh can result in reward hacking. And so basically what this means is if you keep the same testing requirements, but if you only have uh the tests check a subset of the things you actually want to be testing, um you could have a degenerate solution

that nonetheless gets a good answer. Um and so it it would not pass other tests, but this is incomplete. And so people have also pointed this out about a number of benchmarks. uh Sweetbench. Everybody loves to pick on SWEBench because it’s so popular, but there’s um

a paper called Swebench++ which basically uh examines, you know, all of the things that are not rigorous enough. but there there’s a number of problems that you actually very practically will encounter if you’re using strong

language models to try to solve these tests. So these are all ones that I have encountered uh not you know not going out of my way to encounter them like just agents will spontaneously do these things. So if the agent has internet access uh the agent will go

look the results up online. Um I’m sure a lot of people heard about the open AI hugging face thing. Um there the agent very aggressively looked things up online to the point where it hacked into Hugging Face. Um and so the answer to this is uh don’t uh don’t give it

internet access or at the very least don’t give it internet access to the sites uh that had the answers directly on them. Another example which has appeared in multiple coding benchmarks is they left the git history in the coding benchmark.

And because the get history was in the coding benchmark, the agent would discover uh that it still had the git history. It would fast forward the history to code that had the answer in it and then just use that code. And um I’ve I’ve fixed the benchmarks that had

this problem and and sent you know sent in them. This is another interesting one that I just encountered like a few weeks ago. Um, which was I had a model API key within the container that the agent evaluation was running in because I needed a model API key to power the

agent. Uh, and this resulted in that agent finding the proxy server, finding that the proxy server had other uh, agents on it and called a different stronger model to try to ask the stronger model an answer. And so uh specifically DeepSeek uh Deepseek V4

Flash was calling Claude Opus. So it was like um it knew that Claude Opus might have the answer to it. So it decided to uh decided to ask its manager or something. Um the final thing is if you give it access to tests or the test runner, it

will write specifically for the tests and um and go in and uh solve that. So all of these are are problems. um all of these are problems obviously because it’s not learning to solve the actual task. It’s learning to do something else. The even worse part is if you do

this during training the model will learn that this is a very effective way to solve that variety of problems. So um again talking about the open AI hugging face uh incident um one of the problems was they gave it um

the they had a problem of both false negatives and reward hacking where they gave it an impossible task where the there was no way you could solve the task without breaking out of the sandbox and using the internet. and they had a problem in the sandbox

that let the agent break out and and use the internet. And so it basically reinforced this behavior more and more and more because it’s like this is the only way to solve it, but this, you know, is a way to solve it. So it got baked into the parameters of the model.

Um, for me personally, I use DeepSeek uh to try to solve some problems and it called the API I think 60% of the time and 60% of the time is a lot, right? So my intuitive uh my intuitive thought about this is they must have had this problem while they

were also training the model because otherwise it wouldn’t have this behavior so baked into the model itself. So um it’s something to be very very careful about when you’re training and I think the people are becoming much much more uh familiar about this and now you can

like actually view what the model is doing make sure it’s not violating any issue violating any uh policies or stuff like that. So um there’s a number of ways you can do that. Um you can also do uh independent checks of uh progress. So

essentially um you you do want to measure the training reward but you also want to be checking on uh unseen tasks and uh monitoring the behavior like I mentioned. And another thing that you can do is you can check uh you know the costs. Um sometimes when training is

failing it’s not due to the agents behavior but it’s because some infra fell over because as we mentioned um you know RL is a very big systems problem. So, it’s also good to be monitoring, you know, just all of your training runs to make sure that nothing is breaking. And

fortunately, now having an asking an agent to periodically monitor the training run is, you know, a very effective way of of doing this, even if you don’t have special tooling. So another um another reason why things might fail uh I mentioned is your

entropy collapses and it leads to a lack of exploration. So I haven’t seen like a ton of people use this method but it is one that was used in um in large scale training uh which is essentially if you get zero advantage uh rollouts you can roll out again and uh hope that you get

a mixed group again. So you you basically keep on rolling out until you get uh get a positive example. Um so this is one way you can deal with uh the fact that there’s very little uh very few positive examples or very few negative examples.

Okay. So um another thing that uh I would like to talk about is partial and auxiliary rewards. So basically right now we’re becoming more and more ambitious about the types of tasks that we would want to tackle. And

essentially um you know because we’re becoming more and more ambitious we might start out with a model that is not able to tackle these tasks at all. There’s a few ways you can fix this. you can come up with like simpler tasks and you can train the model on simpler tasks

first and then uh then train it on uh others uh other tasks later. But um one thing that you can do is you can give partial rewards. And so partial rewards are basically the simplest example of a partial reward is if you have four tests you give uh a

reward of number of tests passed divided by total number of tests. And so if you do this then you can get a a score a non-zero score even if you would have had a zero success uh reward and you can uh calculate something like GRPO based on that. The problem with this is

it’s much harder to design rewards because you’re no longer directly optimizing the final accuracy that you want. And if you design rewards that aren’t, you know, aligned with doing better on the task eventually, then this can cause you to, you know, essentially

like optimize those rewards at the cost of optimizing the main reward. Um, so I have two actual examples of this. Um, not to pick on OpenAI, but they’re both from OpenAI. Um, so one example is GPD 5.1 had an auxiliary reward for

using the web browser because they wanted to teach it to use the web browser. So basically what it did was it called the web browser uh navigated to a calculator app and used the calculator app to solve math problems. And so they basically ended up training a model that

every time it wanted to solve a simple math problem like oneplus 2, it would call the web browser and use like five extra seconds to get that like extra auxiliary reward. Um, this one’s even more funny. Did did anybody read this blog post on goblin where the goblins

came from from OpenAI? So for a while the GPD models really love to say like goblins. It’s like there’s a bunch of coding goblins in this uh in this uh problem or something like this. And the reason why is because they introduced they briefly introduced character

training. And the character training uh gave a little bit of a bonus if like the uh the character was like nerdy or the character was friendly or the character was concise or something like this. Um, but for some reason the language model that they used as a judge of the nerdy

persona thought that if you said goblin or gremlin, uh, it was very nerdy, I guess. And so they got extra award for saying goblin. And then over time, this just kind of like amplified itself and the percentage of goblins got larger and larger and larger. So this is a

fascinating blog post. If you haven’t seen it before, you can go in and see the like unexpected uh, side effects of auxiliary rewards. Cool. Um, yeah, actually I already kind of mentioned exploration collapse when I talked about uh Dapo. So I uh you know

it means that it will only pick like one type of action. Um so uh I’ll I’ll skip that slide. The final thing I’d like to talk about is learning from a teacher. And so this is particularly useful if you have uh a stronger model that you can use to train

a weaker model. So this could either be you know one of the one of the strong models that is just available uh nowadays or it could be like a larger model of the model family that you want to train um that sort of thing. And so

a very common thing or I I would say every model is doing this nowadays is starting from demonstrations. And so all the large language models will add mid training where essentially they add uh add demonstrations and uh uh already talked about this extensively in the

previous class so I won’t cover this um but the next thing that you can do is uh you can start with some simpler tasks and then gradually um move into harder tasks. And there’s a bunch of different ways to do this. I don’t know if there’s any like

science about exactly how people do this, but you can gradually modify uh modify your mix or gradually remove tasks from task categories where the model is mostly getting them right, etc., etc. Another thing you can do is uh

distillation. And so basically uh what you do here is you have a stronger model roll out on whatever uh reinforcement learning environment you want to be training on and then you take only the examples that passed and then you train on that. So this is also like called

various things like reinforce fine-tuning or something like that but bas basically it’s a it’s a method for distillation. Um so oh yeah sorry actually the next part is important. So the the one thing that’s

important here is um one popular method for distillation is not just training on the examples but it’s actually m matching the probability distribution from the teacher. And so instead of uh maximizing the log likelihood of the next token, you minimize the kale

divergence from the distribution over next tokens from the teacher. Um, and so it’s kind of like if the teacher says the next token is like a b c with a probability of 0.5 0.3 0.2 instead of

just taking the the one token that you sampled you actually match this distribution here. So this is good. Uh but the problem with this is if this is a roll out from the teacher, the teacher still may be like very successful at getting to this point

despite the fact that the model you’re trying to train is not successful has not been successful at getting to this point. So it like might fail to even get this far. And that leads to a problem uh that Daniel mentioned last uh last lecture. Does anyone remember the name

of this problem? Begins with an e Okay, it’s uh exposure bias. Um and so exposure bias is basically like you’re you’re never seeing the examples. um you’re never seeing the examples that you would actually see at test time. And

so a way to solve this is uh on policy distillation. And on policy distillation, essentially what it does is um you do a student roll out. Um you do a roll out with the weaker model and then um you take the next action from the student model. uh you take the next

action from this roll out of the student model but then you train the student model to match the teacher’s probability distribution. So the trajectory history is from the student model but the next target is from the teacher model essentially.

Yeah. Okay. And sorry I uh I wrote this on the board already but basically it’s saying the same thing. you you’re maximizing the um uh the probability between them. And then um there’s also a paper um on policy

self-distillation. And the basic idea here is that the student model is the model you’re trying to train and the teacher model is the model that you’re trying to train but you tell it the answer. Um and so essentially it already knows the answer

in advance uh so it’s able to pick next actions more uh more appropriately. So I think this is an interesting problem uh an interesting method uh but it is a little bit biased because of course you know the actions that a teacher is going to take if it already knows the answer

are going to be different uh than if it didn’t know the answer already. So um there there’s probably ways that this could be further improved as well. Cool. So, that’s all the stuff that I wanted to talk about today. Um, essentially to break it down, um, I

talked about methods to get better and more useful feedback, including more useful feedback on each token or each action. I talked about stable updates, so how to prevent your uh, reward from crashing uh, a little while into the training. And I talked about how to get

more reliable rewards. So make sure that you’re getting signal and not getting all examples where the model cannot pass or all examples where the model can pass. So are there any questions? Yeah. >> Talking about the actual training procedure. Do you follow the same

guidelines as for SF? So only actual tool calls each token this kind of stuff. Do we uh what do you mean by each token? Sorry. >> So you calculate the signal whatever token tools

>> yal how does it translate? >> Yeah great great question. So um how do you how do you calculate the loss? Do you only calculate it on tool calls or do you calculate it on like the

observations as well? Um the answer there is interesting which is typically you only calculated on the tool call. So you only on the actions and so that includes the chains of thought and you know all the stuff that the model produces but there’s actually a paper

called echo um it’s something like echo uh terminal agents learn a world model for free and basically the only thing they do is they also train the model on the observations and they demonstrate that this improves performance and so the thinking behind this is that

actually predicting the state of the world is also an ability that you need the like the language model to have. Like if it can predict the state of the world, it should also be better at picking the next action. And so if you’re not training on the observations,

you’re essentially throwing away this multitask learning training signal that you could use to train the model better. So um long long story short, you can do both. And it might be an empirical question about which is better, but if you have a really rich environment, then

that could be a useful training signal. Yeah. Great. Any any others?

持续耕种,欢迎订阅 🌱

RSS全站 ·原创 ·策展 ·雷达;公众号「炼金术」同步更新。

本讲伴读笔记以 CMU 11-768 AI Agents (Fall 2026) 课程大纲为参考框架独立撰写。原课程由 Daniel Fried 与 Graham Neubig 讲授,原始课件与视频见cmu-agents.com; 音频镜像与文字稿仅作大陆可达性便利,版权归课程方所有。本文观点与文字为作者原创。

本讲大纲
  1. 01导语
  2. 02一、修 bug 的贯穿案例:REINFORCE 的死角
  3. 03二、信用分配三部曲:组均值、Critic 与过程奖励
  4. 04三、长轨迹上比值会爆炸:重要性采样与裁剪六家
  5. 05四、Verifier 也会骗人:假阴、假阳与独立审计
  6. 06五、向教师学习:课程、蒸馏与 On-Policy 变奏
  7. 07六、一个训练步的五段旅程:双引擎与权重往返
  8. 08七、Rollout 经济学:KV 缓存、前缀共享与投机解码的账本
  9. 09八、Agentic RL 的暗坑:模板、Token 与陈旧策略
  10. 10九、服务化 RL:单控制器、中间人与多租户
  11. 11论文与材料导读
  12. 12实践视角
  13. 13本讲要点
  14. 14延伸阅读
  15. 本讲模块概念回顾本讲资料自测问学伴微行动文字稿