LLM学习笔记-奖励模型reward model
奖励模型(Reward Model)训练数据是如何构造的
LLM Training: RLHF and Its Alternatives Another distinction not depicted in the above-mentioned annotated figure relates to how model responses are ranked to generate the reward model. In the standard InstructGPT approach for RLHF PPO discussed previously, the researchers collect responses that rank 4-9 outputs f...
LLM学习笔记-偏好对齐-PPO vs DPOl
前言
Fine-tune Mistral-7b with Direct Preference Optimization – Maxime Labonne Pre-trained Large Language Models (LLMs) can only perform next-token prediction, making them unable to answer questions. This is why these base models are then fine-tuned on pairs of instructions and answers to act as helpful assistants. However, this process can st...
LLM学习笔记-偏好对齐-DPO代码实现
前言
DPO 核心原理(一句话)
用有监督的对比学习,直接优化 πθ 对 chosen 和 rejected 的相对概率,同时用 πref 作为锚点防止跑偏。
DPO 核心公式
\[L_{DPO} = -\log \sigma \left( \beta \cdot \log \frac{\pi_\theta(y_w|x)}{\pi_{ref}(y_w|x)} - \beta \cdot \log \frac{\pi_\theta(y_l|x)}{\pi_{ref}(y_l|x)} \right)\]
公式拆解:
符号
含义
$\pi_\theta$
训练模型(可更新...
LLM学习笔记-llm微调vs偏好对齐
llm的微调 vs RLHF(基于人类反馈的强化学习)
这是一个非常经典且核心的问题。为了让你直观地理解,我们可以用一个“学霸备考”的比喻来贯穿全程:
预训练(Pre-training):学霸读完了一整座图书馆的书,成了“通才”,上知天文下知地理。
微调(Fine-tuning):学霸开始做历年真题(特定数据集),目标是把题做对(提高特定任务的得分)。
RLHF(基于人类反馈的强化学习):学霸不仅要做对题,还要把答案写得让阅卷老师(人类)赏心悦目,目标是获得最高评价。
下面我为你深度拆解两者的目标差异,这远不止“一个简单、一个复杂”那么简单。
1. 核心优化目标的差异(“学知识” vs “学做人”)
微调(以监督微调SFT为例)的目标: 概率拟合(Dis...
LLM学习笔记-RLHF偏好对齐
原文链接:Illustrating Reinforcement Learning from Human Feedback (RLHF)
LLM偏好对齐的目标:使其对齐人类偏好
LLM Training: RLHF and Its Alternatives RLHF is an integral part of the modern LLM training pipeline due to its ability to incorporate human preferences into the optimization landscape, which can improve the model’s helpfulness and safety.
通俗理解
1. 核心痛...
LLM学习笔记-文本生成解码策略
前言
GPT类模型本质上是自回归语言模型,通过预测下一个词来逐步生成文本。不同的解码策略会显著影响生成文本的质量、多样性和创造性。
一、GPT-2 的核心流程
1.1 基本工作流程
text
输入 → 预测下一个词 → 拼接到输入 → 重复直到完成
1.2 生成案例
生成5个词的过程:
text
输入:"I have a dream"
↓
第1次预测 → "about" → "I have a dream about"
第2次预测 → "my" → "I have a dream about my"
第3次预测 → "future" → "I have a dream about my future"
第4次预测 → "in" ...
LLM学习笔记-从全量微调到LoRA再到QLoRA
前言
来自: https://huggingface.co/blog/mlabonne/sft-llama3从全量微调到LoRA再到QLoRA,核心是为了解决在有限显存资源下微调大模型的问题。
方法
核心理念
一句话概括
全量微调
更新全部参数
搬整个图书馆,效果好但显存爆炸
LoRA
冻结原模型,只训练旁路小矩阵 A×B
不搬书,只做索引卡,显存省10倍+
QLoRA
LoRA + 4-bit量化
先把书压缩成口袋书,再做索引卡,显存再省60%
...
共计 61 篇文章,8 页。