🚀 RLHF奖励模型项目
本项目提供的奖励函数可用于基于人类反馈的强化学习(RLHF),包括近端策略优化(PPO)、迭代监督微调(iterative SFT)和迭代直接偏好优化(iterative DPO),为相关研究和应用提供了有力支持。
🚀 快速开始
本奖励函数可用于多种基于人类反馈的强化学习方法,如PPO、迭代SFT和迭代DPO。
📄 许可证
本项目的许可证派生自 PKU-Alignment/PKU-SafeRLHF-30K
,具体采用 CC BY-NC 4.0
许可协议。
✨ 主要特性
- 适用多种RLHF方法:奖励函数可用于PPO、迭代SFT和迭代DPO等多种基于人类反馈的强化学习方法。
- SOTA表现:该奖励模型在Reward-Bench上是截至2024年4月20日的最优开源奖励模型(SOTA)。
📦 安装指南
基础模型
本项目使用的基础模型是 meta-llama/Meta-Llama-3-8B-Instruct
。
训练脚本
我们使用位于 https://github.com/WeiXiongUST/RLHF-Reward-Modeling
的训练脚本进行训练。
💻 使用示例
基础用法
from transformers import AutoTokenizer, pipeline
rm_tokenizer = AutoTokenizer.from_pretrained("sfairXC/FsfairX-LLaMA3-RM-v0.1")
device = 0
rm_pipe = pipeline(
"sentiment-analysis",
model="sfairXC/FsfairX-LLaMA3-RM-v0.1",
device=device,
tokenizer=rm_tokenizer,
model_kwargs={"torch_dtype": torch.bfloat16}
)
pipe_kwargs = {
"return_all_scores": True,
"function_to_apply": "none",
"batch_size": 1
}
chat = [
{"role": "user", "content": "Hello, how are you?"},
{"role": "assistant", "content": "I'm doing great. How can I help you today?"},
{"role": "user", "content": "I'd like to show off how chat templating works!"},
]
test_texts = [rm_tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=False).replace(rm_tokenizer.bos_token, "")]
pipe_outputs = rm_pipe(test_texts, **pipe_kwargs)
rewards = [output[0]["score"] for output in pipe_outputs]
📚 详细文档
论文信息
- 论文标题:RLHF Workflow: From Reward Modeling to Online RLHF(发表于TMLR, 2024)
- 作者:Hanze Dong*, Wei Xiong*, Bo Pang*, Haoxiang Wang*, Han Zhao, Yingbo Zhou, Nan Jiang, Doyen Sahoo, Caiming Xiong, Tong Zhang
代码仓库
代码仓库地址:https://github.com/RLHFlow/RLHF-Reward-Modeling/
实验结果
该奖励模型在Reward-Bench上的表现如下:
指标 |
得分 |
对话(Chat) |
99.44 |
困难对话(Chat Hard) |
65.13 |
安全性(Safety) |
88.76 |
推理能力(Reasoning) |
88.3 |
📖 参考文献
如果您发现本仓库的内容对您的工作有帮助,请考虑引用以下文献:
@article{dong2023raft,
title={Raft: Reward ranked finetuning for generative foundation model alignment},
author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong},
journal={arXiv preprint arXiv:2304.06767},
year={2023}
}
@misc{xiong2024iterative,
title={Iterative Preference Learning from Human Feedback: Bridging Theory and Practice for RLHF under KL-Constraint},
author={Wei Xiong and Hanze Dong and Chenlu Ye and Ziqi Wang and Han Zhong and Heng Ji and Nan Jiang and Tong Zhang},
year={2024},
eprint={2312.11456},
archivePrefix={arXiv},
primaryClass={cs.LG}
}