PURE PRM 7B
這是一個基於Qwen2.5-Math-7B訓練的過程獎勵模型,用於提升數學推理能力
下載量 18
發布時間 : 2/9/2025
模型概述
該模型通過對PRM800K數據集微調Qwen2.5-Math-7B獲得,主要用於評估數學推理過程和中間步驟的質量
模型特點
過程評估能力
專注於評估推理過程和中間步驟的質量,而非最終結果
數學推理優化
專門針對數學推理任務進行優化,提升推理步驟的準確性
步驟分隔評估
支持通過雙換行符分隔解決方案步驟,對每個步驟進行獨立評估
模型能力
數學推理評估
過程獎勵計算
步驟質量分析
使用案例
數學教育
數學解題步驟評估
評估學生解題過程中每個步驟的正確性
提供每個步驟的獎勵分數,幫助識別錯誤步驟
AI訓練
強化學習獎勵模型
作為強化學習中的獎勵模型,指導AI改進數學推理能力
提升AI模型的數學推理準確性
🚀 基於Qwen2.5-Math-7B的PURE的過程獎勵模型(PRM)
我們的過程獎勵模型(PRM)用於微調大語言模型(LLM),以增強其數學推理能力。更多細節請查看我們的 PURE GitHub倉庫。該模型是通過在開源數據集 PRM800K 的訓練集上對 Qwen2.5-Math-7B 進行微調得到的。我們選擇Qwen2.5-Math-7B而非Qwen2.5-Math-7B-Instruct,是為了使基礎模型與我們的基線保持一致。我們將PRM800K中的原始標籤1和0視為正標籤,-1視為負標籤。為避免測試數據汙染,我們還移除了PRM800K訓練樣本中與MATH測試集數學問題相同的樣本。
⚠️ 重要提示
本倉庫與 Qwen的PRM 不同。我們基於 Qwen2.5-Math-7B 訓練PRM,而Qwen的PRM基於 Qwen2.5-Math-7B-Instruct。
屬性 | 詳情 |
---|---|
基礎模型 | Qwen/Qwen2.5-Math-7B |
任務類型 | 標記分類 |
訓練數據 | HuggingFaceH4/prm800k-trl-dedup |
許可證 | Apache-2.0 |
🚀 快速開始
⚠️ 重要提示
PURE的PRM 是一種過程獎勵模型,通常用於對推理和中間步驟的質量提供反饋,而非用於生成任務。
前提條件
- 步驟分隔:建議使用雙換行符("\n\n")分隔解決方案中的各個步驟。
- 獎勵計算:在每個步驟後插入一個標記 "
\n
"。為計算獎勵,我們提取該標記的概率得分,並從正概率中減去負概率,得到一個介於 -1 和 1 之間的獎勵值。我們將獎勵 > 0 的步驟視為正確步驟,否則視為錯誤步驟。
🤗 Hugging Face Transformers
以下是使用 transformers
庫調用我們的PRM的代碼示例:
import torch
from transformers import AutoModelForTokenClassification, AutoTokenizer
def make_step_rewards(logits, token_masks):
all_scores_res = []
for sample, token_mask in zip(logits, token_masks):
# sample: (seq_len, num_labels)
probs = sample[token_mask].softmax(dim=-1) # (num_steps, 2)
process_reward = probs[:, 1] - probs[:, 0] # (num_steps,)
# weighted sum to approx. min, highly recommend when BoN eval and Fine-tuning LLM
# weight = torch.softmax(
# -process_reward / 0.1,
# dim=-1,
# )
# process_reward = weight * process_reward
all_scores_res.append(process_reward.cpu().tolist())
return all_scores_res
model_name = "jinachris/PURE-PRM-7B"
device = "auto"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True,
)
model = AutoModelForTokenClassification.from_pretrained(
model_name,
device_map=device,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
).eval()
question = "Sue lives in a fun neighborhood. One weekend, the neighbors decided to play a prank on Sue. On Friday morning, the neighbors placed 18 pink plastic flamingos out on Sue's front yard. On Saturday morning, the neighbors took back one third of the flamingos, painted them white, and put these newly painted white flamingos back out on Sue's front yard. Then, on Sunday morning, they added another 18 pink plastic flamingos to the collection. At noon on Sunday, how many more pink plastic flamingos were out than white plastic flamingos?"
steps = [
"To find out how many more pink plastic flamingos were out than white plastic flamingos at noon on Sunday, we can break down the problem into steps. First, on Friday, the neighbors start with 18 pink plastic flamingos.",
"On Saturday, they take back one third of the flamingos. Since there were 18 flamingos, (1/3 \\times 18 = 6) flamingos are taken back. So, they have (18 - 6 = 12) flamingos left in their possession. Then, they paint these 6 flamingos white and put them back out on Sue's front yard. Now, Sue has the original 12 pink flamingos plus the 6 new white ones. Thus, by the end of Saturday, Sue has (12 + 6 = 18) pink flamingos and 6 white flamingos.",
"On Sunday, the neighbors add another 18 pink plastic flamingos to Sue's front yard. By the end of Sunday morning, Sue has (18 + 18 = 36) pink flamingos and still 6 white flamingos.",
"To find the difference, subtract the number of white flamingos from the number of pink flamingos: (36 - 6 = 30). Therefore, at noon on Sunday, there were 30 more pink plastic flamingos out than white plastic flamingos. The answer is (\\boxed{30})."
]
step_separator = "\n"
step_separator_token = tokenizer(
step_separator,
add_special_tokens=False,
return_tensors='pt',
)['input_ids']
input_ids = tokenizer(
question,
add_special_tokens=False,
return_tensors='pt',
)['input_ids']
score_ids = []
for step in steps:
step_ids = tokenizer(
step,
add_special_tokens=False,
return_tensors='pt',
)['input_ids']
input_ids = torch.cat(
[input_ids, step_ids, step_separator_token],
dim=-1,
)
score_ids.append(input_ids.size(-1) - 1)
input_ids = input_ids.to(model.device)
token_masks = torch.zeros_like(input_ids, dtype=torch.bool)
token_masks[0, score_ids] = True
assert torch.all(input_ids[token_masks].to("cpu") == step_separator_token)
logits = model(input_ids).logits
step_reward = make_step_rewards(logits, token_masks)
print(step_reward) # [[0.796875, 0.185546875, -0.0625, 0.078125]]
# For BoN eval,
# uncomment the weighted sum part in `make_step_rewards` func,
# then sum the rewards to get the final score (outcome reward):
# torch.tensor(step_reward).sum(dim=-1)
此外,我們還提供了在RLHFlow數據上進行BoN評估的代碼:
import numpy as np
import torch
from datasets import load_dataset
from tqdm import tqdm
from transformers import AutoModelForTokenClassification, AutoTokenizer
ds_names = ["GSM8K", "MATH500"]
ds = [
load_dataset(
f"RLHFlow/Deepseek-{ds_name}-Test"
)['test'] for ds_name in ds_names
]
def make_step_rewards(logits, token_masks):
all_scores_res = []
for sample, token_mask in zip(logits, token_masks):
# sample: (seq_len, num_labels)
probs = sample[token_mask].softmax(dim=-1) # (num_steps, 2)
process_reward = probs[:, 1] - probs[:, 0] # (num_steps,)
# weighted sum to approx. min, highly recommend when BoN eval and Fine-tuning LLM
weight = torch.softmax(
-process_reward / 0.1,
dim=-1,
)
process_reward = weight * process_reward
all_scores_res.append(process_reward.cpu().tolist())
return all_scores_res
model_name = "jinachris/PURE-PRM-7B"
device = "auto"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True,
)
model = AutoModelForTokenClassification.from_pretrained(
model_name,
device_map=device,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
).eval()
step_separator = "\n"
step_separator_token = tokenizer(
step_separator,
add_special_tokens=False,
return_tensors='pt',
)['input_ids']
for ds_item, ds_name in zip(ds, ds_names):
# sampled_ids = np.random.choice(range(len(ds_item)), size=100, replace=False)
correct = 0
total = 0
for idx in tqdm(range(len(ds_item)), desc=f"Processing questions in {ds_name}"):
question = ds_item['prompt'][idx]
answers = ds_item['answers'][idx]
labels = ds_item['label'][idx]
outcome_scores = []
question_ids = tokenizer(
question,
add_special_tokens=False,
return_tensors='pt',
)['input_ids']
for answer in tqdm(answers, desc="Processing answers"):
steps = [i.rstrip() for i in answer.split("\n\n")]
input_ids = question_ids.clone()
score_ids = []
for step in steps:
step_ids = tokenizer(
step,
add_special_tokens=False,
return_tensors='pt',
)['input_ids']
input_ids = torch.cat(
[input_ids, step_ids, step_separator_token],
dim=-1,
)
score_ids.append(input_ids.size(-1) - 1)
input_ids = input_ids.to(model.device, dtype=torch.long)
token_masks = torch.zeros_like(input_ids, dtype=torch.bool)
token_masks[0, score_ids] = True
assert torch.all(input_ids[token_masks].to("cpu") == step_separator_token)
with torch.no_grad():
logits = model(input_ids).logits
step_reward = make_step_rewards(logits, token_masks)
outcome_reward = torch.tensor(step_reward).sum(dim=-1)
# TODO: batch input & output
outcome_scores.append(outcome_reward.item())
best_idx = np.argmax(outcome_scores)
if labels[best_idx] == 1:
correct += 1
total += 1
print(f"Accuracy on {ds_name}: {correct / total}")
📦 安裝指南
- 對於Qwen2.5-Math模型,需要
transformers>=4.40.0
,建議使用最新版本。
📄 許可證
本項目採用Apache-2.0許可證。
📚 引用
如果您覺得我們的工作有幫助,請引用以下文獻:
@article{cheng2025stop,
title={Stop Summation: Min-Form Credit Assignment Is All Process Reward Model Needs for Reasoning},
author={Cheng, Jie and Qiao, Ruixi and Li, Lijun and Guo, Chao and Wang, Junle and Xiong, Gang and Lv, Yisheng and Wang, Fei-Yue},
journal={arXiv preprint arXiv:2504.15275},
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