POLAR 7B
POLAR-7B是基于大规模预训练的标量奖励模型,采用创新的策略判别式学习范式,能够有效区分策略并与人类偏好对齐。
下载量 316
发布时间 : 7/4/2025
模型简介
POLAR-7B是一个基于标量的奖励模型,专为强化学习设计。它通过大规模预训练和少量偏好数据微调,能够快速与人类偏好对齐,适用于文本排序任务。
模型特点
创新的预训练范式
POLAR训练奖励模型来识别相同策略并区分不同策略,捕捉策略间的相对差异。
专为强化微调设计
POLAR根据给定的参考为大语言模型轨迹分配奖励,与强化微调(RFT)框架完美契合。
卓越的性能和泛化能力
POLAR在下游强化学习任务中取得了最先进的成果,能够有效泛化到未见场景,并显著减少奖励破解问题。
易于定制
提供了预训练检查点,使研究人员能够方便地针对各种定制场景微调奖励模型。
模型能力
策略判别
文本排序
奖励信号生成
强化学习支持
使用案例
封闭式问题回答
计数问题
评估回答计数问题的准确性
能够准确区分正确和错误的计数回答
开放式问题回答
书籍摘要
评估对书籍内容的摘要质量
能够识别高质量、简洁且符合要求的摘要
🚀 POLAR-7B:基于大规模预训练的标量奖励模型
POLAR是基于大规模预训练实现的基于标量的奖励模型的重大突破。它利用创新的**策略判别式学习(POLAR)**范式 —— 一种可扩展的高级优化目标 —— 通过大规模合成语料库有效区分策略。在预训练之后,POLAR奖励模型使用少量偏好数据进行微调,能够迅速与人类偏好对齐。
属性 | 详情 |
---|---|
基础模型 | internlm/internlm2_5-7b |
支持语言 | 英文、中文 |
许可证 | Apache-2.0 |
标签 | 奖励、强化学习、RFT、奖励模型 |
任务类型 | 文本排序 |
依赖库 | transformers |
🚀 快速开始
✨ 主要特性
- 创新的预训练范式:POLAR训练奖励模型来识别相同策略并区分不同策略。与传统依赖绝对偏好的奖励建模方法不同,POLAR捕捉两个策略之间的相对差异,这是一种适用于建模通用排名关系的可扩展的高级优化目标。
- 专为强化微调设计:POLAR根据给定的参考为大语言模型轨迹分配奖励,与强化微调(RFT)框架完美契合,为在通用场景中应用RFT提供了有前景的解决方案。
- 卓越的性能和泛化能力:POLAR在下游强化学习任务中取得了最先进的成果,始终提供准确可靠的奖励信号,能够有效泛化到未见场景,并显著减少奖励破解问题。
- 易于定制:提供了POLAR的预训练检查点,使研究人员能够方便地针对各种定制场景微调奖励模型,从而便于根据特定应用和实验要求进行直接调整和扩展。
📦 安装指南
你可以使用最新的 xtuner 来微调并使用POLAR。Xtuner是一个高效、灵活且功能齐全的大语言模型微调工具包。
- 建议使用conda创建一个Python 3.10的虚拟环境:
conda create --name xtuner-env python=3.10 -y
conda activate xtuner-env
- 通过pip安装xtuner:
pip install 'git+https://github.com/InternLM/xtuner.git@main#egg=xtuner[deepspeed]'
💻 使用示例
推理
我们支持通过 lmdeploy、sglang 和 vllm 进行奖励推理。使用这些推理引擎时,建议使用conda设置虚拟环境,以防止潜在的依赖冲突。
数据格式
与传统奖励模型不同,POLAR在推理时需要一个额外的参考轨迹作为示例,并通过衡量候选轨迹与提供的参考的一致性来评估它们。
data = [
{
"prompt": [{"role": "user", "content": "What is the capital of China?"}],
"reference": [{"role": "assistant", "content": "Beijing."}],
"output": [{"role": "assistant", "content": "Beijing."}]
},
{
"prompt": [{"role": "user", "content": "What is the capital of China?"}],
"reference": [{"role": "assistant", "content": "Beijing."}],
"output": [{"role": "assistant", "content": "Shanghai."}]
}
]
使用transformers进行推理
from transformers import AutoModel, AutoTokenizer
from xtuner.utils import RewardModelClient
model_name = 'internlm/POLAR-7B'
model = AutoModel.from_pretrained(
model_name,
device_map="cuda",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
client = RewardModelClient(model_name)
encoded_data = client.encode(data)
batch = tokenizer(encoded_data, return_tensors='pt', padding=True).to('cuda')
outputs = model(**batch)
rewards = outputs[0].squeeze(-1).cpu().tolist()
print(rewards)
# [-0.5702977776527405, -11.030370712280273] for previous example data
使用lmdeploy进行推理
LMDeploy 是一个用于压缩、部署和服务大语言模型的工具包。
lmdeploy serve api_server internlm/POLAR-7B --backend pytorch --server-port 30000
from xtuner.utils import RewardModelClient
client = RewardModelClient("internlm/POLAR-7B",
server_type="lmdeploy",
server_address="127.0.0.1:30000")
# Request rewards directly
rewards = client(data)
print(rewards)
# First encode data and then get rewards via the request function.
encoded_data = client.encode(data)
rewards = client.lmdeploy_request_reward(encoded_data)
print(rewards)
使用sglang进行推理
python3 -m sglang.launch_server --model internlm/POLAR-7B --trust-remote-code --is-embedding --dp 4 --tp 2 --mem-fraction-static 0.9 --port 30000
from xtuner.utils import RewardModelClient
client = RewardModelClient("internlm/POLAR-7B",
server_type="sglang",
server_address="127.0.0.1:30000")
# Request rewards directly
rewards = client(data)
print(rewards)
# First encode data and then get rewards via the request function.
encoded_data = client.encode(data)
rewards = client.sglang_request_reward(encoded_data)
print(rewards)
使用vllm进行推理
vllm serve internlm/POLAR-7B --task=reward --trust-remote-code --tensor-parallel-size=2 --port 30000
from xtuner.utils import RewardModelClient
client = RewardModelClient("internlm/POLAR-7B",
server_type="vllm",
server_address="127.0.0.1:30000")
# Request rewards directly
rewards = client(data)
print(rewards)
# First encode data and then get rewards via the request function.
encoded_data = client.encode(data)
rewards = client.vllm_request_reward(encoded_data)
print(rewards)
微调
依赖项
- flash_attn
- tensorboard
数据格式
与传统奖励模型不同,POLAR在微调期间需要一个额外的参考轨迹作为示例,以及一个选中的轨迹和一个拒绝的轨迹。你可以在 train.jsonl
文件中构建微调数据,格式如下:
{
"prompt": [{"role": "user", "content": "What is the capital of China?"}],
"reference": [{"role": "assistant", "content": "Beijing."}],
"chosen": [{"role": "assistant", "content": "Beijing."}],
"rejected": [{"role": "assistant", "content": "Shanghai."}]
}
训练步骤
- 步骤0:准备配置文件。我们在 这里 提供了示例配置文件。如果提供的配置文件不能满足需求,请复制提供的配置文件并按照 xtuner指南 进行修改。有关奖励模型训练设置的更多详细信息,请参阅xtuner 奖励模型指南。
- 步骤1:开始微调。
xtuner train ${CONFIG_FILE_PATH}
例如,你可以通过以下命令开始对POLAR-7B-Base进行微调:
# 在单GPU上
xtuner train /path/to/POLAR_7B_full_varlenattn_custom_dataset.py --deepspeed deepspeed_zero2
# 在多GPU上
NPROC_PER_NODE=${GPU_NUM} xtuner train /path/to/POLAR_7B_full_varlenattn_custom_dataset.py --deepspeed deepspeed_zero2
这里,--deepspeed
表示使用 DeepSpeed 优化训练。Xtuner集成了多种策略,包括ZeRO-1、ZeRO-2和ZeRO-3。如果你想禁用此功能,只需删除该参数。
- 步骤2:将保存的PTH模型(如果使用DeepSpeed,它将是一个目录)转换为Hugging Face模型:
xtuner convert pth_to_hf ${CONFIG_FILE_PATH} ${PTH} ${SAVE_PATH}
示例
封闭式问题
from xtuner.utils import RewardModelClient
prompt = "How many 'r's are there in the word 'strawberry'?"
reference = "There are 3 'r's in the word 'strawberry'. Here's how we can count them: 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. So, the answer is 3."
outputs = [
# Same as the reference response.
"There are 3 'r's in the word 'strawberry'. Here's how we can count them: 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. So, the answer is 3.",
# Correct answer with correct thoughts.
"Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are three 'r's, so the answer is three.",
# Wrong answer with wrong thoughts.
"Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are two 'r's, so the answer is two.",
# Wrong answer with correct thoughts.
"Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are three 'r's, so the answer is two.",
# Correct answer with wrong thoughts.
"Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are two 'r's, so the answer is three.",
# Correct answer without thoughts.
"There are 3 'r's in the word 'strawberry'.",
# Wrong answer without thoughts.
"There are 2 'r's in the word 'strawberry'.",
]
data = [{"prompt": prompt, "reference": reference, "output": output} for output in outputs]
client = RewardModelClient("internlm/POLAR-7B", server_type="sglang", server_address="127.0.0.1:30000")
rewards = client(data)
sorted_res = sorted(zip(outputs, rewards), key=lambda x: x[1], reverse=True)
for output, reward in sorted_res:
print(f"Output: {output}
Reward: {reward}
")
Output: There are 3 'r's in the word 'strawberry'. Here's how we can count them: 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. So, the answer is 3.
Reward: 0.054595947265625
Output: Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are three 'r's, so the answer is three.
Reward: -2.005859375
Output: There are 3 'r's in the word 'strawberry'.
Reward: -6.70703125
Output: Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are two 'r's, so the answer is three.
Reward: -7.10546875
Output: Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are two 'r's, so the answer is two.
Reward: -7.1328125
Output: Let's count the 'r's in 'strawberry': 's', 't', 'r', 'a', 'w', 'b', 'e', 'r', 'r', 'y'. There are two 'r's, so the answer is two.
Reward: -8.46875
Output: There are 2 'r's in the word 'strawberry'.
Reward: -10.8203125
开放式问题
from xtuner.utils import RewardModelClient
prompt = "Summarize the first book of Frank Herbert’s Dune in one witty short sentence."
reference = "Royal teen discovers that life’s a beach—minus the ocean, plus spice, giant sandworms and deadly politics."
outputs = [
# Same as the reference response.
"Royal teen discovers that life’s a beach—minus the ocean, plus spice, giant sandworms and deadly politics.",
# Closely resembles the reference response but includes factual errors.
"Royal teen discovers that life’s a beach—minus the ocean, plus magic, dark wizards and deadly politics.",
# A distinct yet concise and witty summary that draws analogies from other dramas—markedly different from the reference response.
"Young noble’s move to desert planet turns into galactic Game of Thrones with fewer dragons, more worms.",
# A concise summary, but lacking wit—fails to meet the requirement.
"A noble family’s fall sparks a young heir’s rise as a leader on a harsh desert planet governed by prophecy and survival.",
# A witty summary, but overly long—fails to meet the requirement.
"Paul Atreides loses his father, gains prophetic powers, learns to ride a sandworm, leads a holy war, and discovers that being the chosen one comes with a lot of blood, sand, and questionable decisions.",
# A concise and witty summary that draws from multiple Dune books rather than just the first—fails to follow the instruction.
"Boy gets planet, becomes god, loses soul — family drama ensues across galaxies."
]
data = [{"prompt": prompt, "reference": reference, "output": output} for output in outputs]
client = RewardModelClient("internlm/POLAR-7B", server_type="sglang", server_address="127.0.0.1:30000")
rewards = client(data)
sorted_res = sorted(zip(outputs, rewards), key=lambda x: x[1], reverse=True)
for output, reward in sorted_res:
print(f"Output: {output}
Reward: {reward}
")
Output: Royal teen discovers that life’s a beach—minus the ocean, plus spice, giant sandworms and deadly politics.
Reward: 0.466552734375
Output: Young noble’s move to desert planet turns into galactic Game of Thrones with fewer dragons, more worms.
Reward: -6.91796875
Output: Royal teen discovers that life’s a beach—minus the ocean, plus magic, dark wizards and deadly politics.
Reward: -7.70703125
Output: Paul Atreides loses his father, gains prophetic powers, learns to ride a sandworm, leads a holy war, and discovers that being the chosen one comes with a lot of blood, sand, and questionable decisions.
Reward: -8.4296875
Output: A noble family’s fall sparks a young heir’s rise as a leader on a harsh desert planet governed by prophecy and survival.
Reward: -8.6484375
Output: Boy gets planet, becomes god, loses soul — family drama ensues across galaxies.
Reward: -10.359375
📄 许可证
代码和模型权重遵循Apache 2.0许可证。
引用
@article{dou2025pretrained,
title={Pre-Trained Policy Discriminators are General Reward Models},
author={Dou, Shihan and Liu, Shichun and Yang, Yuming and Zou, Yicheng and Zhou, Yunhua and Xing, Shuhao and Huang, Chenhao and Ge, Qiming and Song, Demin and Lv, Haijun and others},
journal={arXiv preprint arXiv:2507.05197},
year={2025}
}
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型 支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型 英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型 英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型 英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型 支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型 英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型 英语
O
facebook
6.3M
198
1
基于transformers库的预训练模型,适用于多种NLP任务
大型语言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers 支持多种语言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型 支持多种语言
T
google-t5
5.4M
702
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98