从零开始的RLHF
RLHF from Scratch

原始链接: https://github.com/ashworks1706/rlhf-from-scratch

这个仓库提供了一个使用人类反馈强化学习 (RLHF) 的实践教程,使用简洁、易读的代码——优先考虑学习而非生产就绪。它专注于 RLHF 流程的核心步骤:收集偏好数据、训练奖励模型和优化语言模型策略。 代码包括一个简单的 PPO 训练循环 (`ppo_trainer.py`)、支持工具 (`core_utils.py`) 和参数解析 (`parse_args.py`)。主要的学习资源是 `tutorial.ipynb`,一个 Jupyter Notebook,解释了理论并演示了奖励建模和 PPO 微调,并提供可运行的示例。 鼓励用户交互式地探索 Notebook 并检查源代码,以了解各个组件如何协同工作。作者愿意根据需要添加更简单、单脚本的 DPO 或 PPO 演示。

黑客新闻 新的 | 过去的 | 评论 | 提问 | 展示 | 工作 | 提交 登录 从头开始的RLHF (github.com/ashworks1706) 12 分,by onurkanbkrc 2 小时前 | 隐藏 | 过去的 | 收藏 | 1 评论 alansaber 19 分钟前 [–] 看起来不错。我非常支持这种实践演示,认为这是初学者学习机器学习的最佳方式。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

Hands-on RLHF tutorial and minimal code examples. This repo is focused on teaching the main steps of RLHF with compact, readable code rather than providing a production system.

What the code implements (short)

  • src/ppo/ppo_trainer.py — a simple PPO training loop to update a language model policy.
  • src/ppo/core_utils.py — helper routines (rollout/processing, advantage/return computation, reward wrappers).
  • src/ppo/parse_args.py — CLI/experiment argument parsing for training runs.
  • tutorial.ipynb — the notebook that ties the pieces together (theory, small experiments, and examples that call the code above).

What's covered in the notebook (brief)

  • RLHF pipeline overview: preference data → reward model → policy optimization.
  • Short demonstrations of reward modeling, PPO-based fine-tuning, and comparisons.
  • Practical notes and small runnable code snippets to reproduce toy experiments.

How to try

  1. Open tutorial.ipynb in Jupyter and run cells interactively.
  2. Inspect src/ppo/ to see how the notebook maps to the trainer and utilities.

If you want a shorter or more hands-on example (e.g., a single script to run a tiny DPO or PPO demo), tell me and I can add it.

联系我们 contact @ memedata.com