背景
为什么要做 RLHF
Reward: 1.344 | Substring: I Reward: 1.152 | Substring: I love Reward: 2.174 | Substring: I love to Reward: -0.385 | Substring: I love to walk Reward: 0.176 | Substring: I love to walk the Reward: 2.305 | Substring: I love to walk the dog Reward: 1.619 | Substring: I love to walk the dog, Reward: -0.201 | Substring: I love to walk the dog, what Reward: 1.255 | Substring: I love to walk the dog, what do Reward: 2.377 | Substring: I love to walk the dog, what do you Reward: 1.179 | Substring: I love to walk the dog, what do you like Reward: 1.298 | Substring: I love to walk the dog, what do you like?
数据
训练
Policy Model 策略优化
先建模好奖励模型 Reward Model 再优化:PPO
- Actor model:传统的语言模型,最后一层网络是 nn.Linear(hidden_size, vocab_size)
- Reference model(不参与训练):Actor_model的一个复制
- Reward model(不参与训练):
- 将传统语言模型的最后一层网络,由 nn.Linear(hidden_size, vocab_size) 替换成 nn.Linear(hidden_size, 1),也就是说该模型输出的是当前token的得分,而不是对下一个token的预测
- 输入是prompt + answer, 输出是answer中每个token对应的值,answer中最后一个token对应的值即为这条语料的reward
- Critic model:Reward_model 的一个复制
DeepSpeedExamples/applications/DeepSpeed-Chat at master · microsoft/DeepSpeedExamples
Example models using DeepSpeed. Contribute to microsoft/DeepSpeedExamples development by creating an account on GitHub.
强化学习基础知识
RLHF 完整流程
- Reward_model 负责给 LLM 生成的句子打分
- Actor_model 就是我们要优化的 LLM
- Critic_model 负责计算Actor_model的状态动作值矩阵,也就是上面提到的Q函数(Reward模型只负责给最后一个token打分,给之前token打分的重任靠Critic_model 完成)
- Reference_model 是一个标杆,为的是让我们的Actor_model在训练时不要偏离原始模型太远,保证其不会失去原本的说话能力
策略梯度理论
节省资源
直接优化:Bradley-Terry Model
- bandit:DPO
- token:from r to Q*:与bandit不同,但 loss 殊途同归
DPO
DPO 改进
改进反馈粒度
交互形式多样化
多轮 DPO 的 loss 改进

Building Math Agents with Multi-Turn Iterative Preference Learning
Recent studies have shown that large language models' (LLMs) mathematical problem-solving capabilities can be enhanced by integrating external tools, such as code interpreters, and employing...
原有 DPO 优化时出现的“缺陷”
样本质量,与当前优化策略的关系
更新 ref 的策略
去掉 ref 部分:提升正样本,减少负样本
- 推理成本增加导致训练效率降低:在常见的模型规模配置下(如所有模型均为70B),使用vLLM或TensorRT - LLM进行PPO样本生成以及DeepSpeed或Megatron进行训练加速时,推理和训练的计算资源消耗近乎相等(约1:1比例)。GRPO去除了critic模型,这可能会因推理成本增加而无意中降低训练效率。
- 系统复杂性未显著降低:尽管去除了critic模型,但由于多个模型仍需在一个AI系统中与推理和训练模块协同工作,整体系统复杂性基本保持不变。
- 理论性能提升不明显:理论上,GRPO和RLOO并没有显著提升PPO的性能。虽然采样基线可能比critic学习的估计更准确,但可以通过在PPO训练中冻结actor的权重更新来预训练critic模型,而且PPO本身也可以通过多种策略实现类似的效果,如增加每个提示的响应数量来提高批处理大小稳定性和增强探索。
- 可能存在归一化问题:GRPO在某些情况下可能会出现问题,例如当两个采样奖励略有不同(如1.001与1.00)时,在归一化过程中可能会放大为显著偏差。
- Reward Hacking 攻击风险:在Bradley-Terry奖励模型下,GRPO更容易受到奖励黑客攻击。(会生成长的输出以获得奖励,而不是正确的输出)
转移思路
理论假设的不同
DPO 缺陷
scaling laws:奖励模型优化的尺度定律
如何选择
现状
Reward Model 奖励模型
RM 的优化
BT model外的选择
RM类别
数值
对比
规则
LLM as judge:可与生成任务统一建模
RM 的 bias
数据有偏
非内容偏好:输出长度、emoji、加粗、exclamation、list、link、affimtive
BT Model 潜在问题
从人类反馈中的纳什学习
推理阶段
搜索出 best
迭代优化
推理阶段尺度定律
参考文献
Reinforcement Learning From Human Feedback — My sample book
TRL is a full stack library that provides a set of tools to train transformer language models with Reinforcement Learning, from the Supervised Fine-tuning step (SFT), Reward Modeling step (RM) to the Proximal Policy Optimization (PPO) step. The library is integrated with 🤗 transformers. In this blog, we will introduce both system architecture, code and mathematics of PPO in TRL. Specifically, we split this blog into three parts: