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