RLHF (Reinforcement Learning from Human Feedback) là pipeline nhiều giai đoạn để biến base LLM (chỉ biết predict token) thành assistant biết tuân chỉ dẫn và an toàn. Dùng cho ChatGPT, Claude, LLaMA Instruct, Gemini.
Pipeline 3 bước kinh điển:
1. SFT (Supervised Fine-Tuning) — thu thập dataset (prompt → ideal response) do human viết. Fine-tune base model trên đây để học format hội thoại và follow instruction. Output: SFT model.
2. Reward Model training — với mỗi prompt, sample nhiều response từ SFT model. Human ranker đánh giá (response A tốt hơn B). Train một reward model (thường init từ SFT model, thay head bằng scalar) dự đoán điểm r(prompt, response) khớp preference người dùng.
3. RL optimization (PPO) — dùng PPO (Proximal Policy Optimization): SFT model (policy) sinh response, reward model chấm điểm, PPO update policy để maximize reward. Thêm KL penalty với SFT model làm regularizer, tránh policy bị reward hacking (sinh output điểm cao nhưng vô nghĩa).
Các cải tiến / thay thế:
- DPO (Direct Preference Optimization) — bỏ reward model và RL, optimize trực tiếp từ preference data bằng loss closed-form. Đơn giản hơn PPO, chất lượng tương đương hoặc hơn. Hiện là default cho fine-tune open-source.
- RLAIF — thay human feedback bằng AI feedback (model mạnh đánh giá) → scale rẻ hơn. Anthropic's Constitutional AI, SPIN...
- KTO, ORPO, IPO — các biến thể DPO khác nhau.
Thách thức:
- Alignment tax — model mất khả năng sau RLHF.
- Reward hacking — policy exploit lỗ hổng reward model.
- Annotator disagreement — human rank không đồng nhất.
- Chi phí human label lớn.
RLHF (Reinforcement Learning from Human Feedback) is a multi-stage pipeline that turns a base LLM (which only predicts tokens) into an assistant that follows instructions safely. Used by ChatGPT, Claude, LLaMA Instruct, Gemini.
Classic 3-step pipeline:
1. SFT (Supervised Fine-Tuning) — collect a (prompt → ideal response) dataset written by humans. Fine-tune the base model on this to learn conversational format and instruction following. Output: SFT model.
2. Reward Model training — for each prompt, sample multiple responses from the SFT model. Human rankers judge them (response A better than B). Train a reward model (typically initialized from SFT, swap the head for a scalar) to predict r(prompt, response) matching human preferences.
3. RL optimization (PPO) — use PPO (Proximal Policy Optimization): SFT model (policy) generates responses, reward model scores, PPO updates the policy to maximize reward. A KL penalty against the SFT model regularizes, preventing reward hacking (high-score but meaningless output).
Improvements / alternatives:
- DPO (Direct Preference Optimization) — skip the reward model and RL, optimize directly from preference data with a closed-form loss. Simpler than PPO, matches or beats quality. Current default for open-source fine-tuning.
- RLAIF — replace human feedback with AI feedback (strong model ranker) → cheaper to scale. Anthropic's Constitutional AI, SPIN...
- KTO, ORPO, IPO — various DPO variants.
Challenges:
- Alignment tax — model loses some capability post-RLHF.
- Reward hacking — policy exploits reward-model loopholes.
- Annotator disagreement — inconsistent human rankings.
- Large human labeling cost.