Views
No views yet
[!Warning]🚨 This repo differs from Qwen's PRM. We trained our PRM based on Qwen2.5-Math-7B, while Qwen's PRM is based on Qwen2.5-Math-7B-Instruct.
transformers>=4.40.0 for Qwen2.5-Math models. The latest version is recommended.[!Important]PURE's PRM is a process reward model typically used for offering feedback on the quality of reasoning and intermediate steps rather than generation.
\n". For reward calculation, we extract the probability score of this token and subtract negative probabilities from positive probabilities, resulting in a reward value between -1 and 1. We regard steps with reward > 0 as correct, otherwise as incorrect.transformers:1import torch
2from transformers import AutoModelForTokenClassification, AutoTokenizer
3
4
5def make_step_rewards(logits, token_masks):
6 all_scores_res = []
7 for sample, token_mask in zip(logits, token_masks):
8 # sample: (seq_len, num_labels)
9 probs = sample[token_mask].softmax(dim=-1) # (num_steps, 2)
10 process_reward = probs[:, 1] - probs[:, 0] # (num_steps,)
11 # weighted sum to approx. min, highly recommend when BoN eval and Fine-tuning LLM
12 # weight = torch.softmax(
13 # -process_reward / 0.1,
14 # dim=-1,
15 # )
16 # process_reward = weight * process_reward
17 all_scores_res.append(process_reward.cpu().tolist())
18 return all_scores_res
19
20model_name = "jinachris/PURE-PRM-7B"
21device = "auto"
22
23tokenizer = AutoTokenizer.from_pretrained(
24 model_name,
25 trust_remote_code=True,
26)
27model = AutoModelForTokenClassification.from_pretrained(
28 model_name,
29 device_map=device,
30 torch_dtype=torch.bfloat16,
31 trust_remote_code=True,
32).eval()
33
34question = "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?"
35steps = [
36 "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.",
37 "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.",
38 "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.",
39 "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})."
40]
41
42step_separator = "\n"
43step_separator_token = tokenizer(
44 step_separator,
45 add_special_tokens=False,
46 return_tensors='pt',
47)['input_ids']
48input_ids = tokenizer(
49 question,
50 add_special_tokens=False,
51 return_tensors='pt',
52)['input_ids']
53
54score_ids = []
55for step in steps:
56 step_ids = tokenizer(
57 step,
58 add_special_tokens=False,
59 return_tensors='pt',
60 )['input_ids']
61 input_ids = torch.cat(
62 [input_ids, step_ids, step_separator_token],
63 dim=-1,
64 )
65 score_ids.append(input_ids.size(-1) - 1)
66
67input_ids = input_ids.to(model.device)
68token_masks = torch.zeros_like(input_ids, dtype=torch.bool)
69token_masks[0, score_ids] = True
70assert torch.all(input_ids[token_masks].to("cpu") == step_separator_token)
71
72logits = model(input_ids).logits
73step_reward = make_step_rewards(logits, token_masks)
74print(step_reward) # [[0.796875, 0.185546875, -0.0625, 0.078125]]
75
76# For BoN eval,
77# uncomment the weighted sum part in `make_step_rewards` func,
78# then sum the rewards to get the final score (outcome reward):
79# torch.tensor(step_reward).sum(dim=-1)@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}
}