🚀 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}
}