Upload 2 files
Browse files- README.md +171 -3
- figs/implicit.png +0 -0
README.md
CHANGED
@@ -1,3 +1,171 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# EurusPRM-Stage2
|
5 |
+
|
6 |
+
## Links
|
7 |
+
|
8 |
+
- 📜 [Blog]()
|
9 |
+
- 🤗 [PRIME Collection](https://huggingface.co/PRIME-RL)
|
10 |
+
- 🤗 [Training Data](https://huggingface.co/datasets/PRIME-RL/EurusPRM-Stage2-Data)
|
11 |
+
|
12 |
+
## Introduction
|
13 |
+
|
14 |
+
EurusPRM-Stage2 is trained using **[Implicit PRM](https://arxiv.org/abs/2412.01981)**, which obtains free process rewards at no additional cost but just needs to simply train an ORM on the cheaper response-level labels. During inference, implicit process rewards are obtained by forward passing and calculating the log-likelihood ratio on each step.
|
15 |
+
|
16 |
+
<img src="./figures/implicit.png" alt="prm" style="zoom: 33%;" />
|
17 |
+
|
18 |
+
The key ingredient of Implicit PRM is the reward representation, as demonstrated below:
|
19 |
+
|
20 |
+
<aside>
|
21 |
+
✨
|
22 |
+
|
23 |
+
***Proposition**: Consider an ORM where the reward is parameterized by the log-likelihood ratio of two causal LMs, i.e. $r_\phi(\mathbf{y}):= \beta \log \frac{\pi_\phi(\mathbf{y})}{\pi_\text{ref}(\mathbf{y})}$. Define $q_\phi^t(\mathbf{y}_{<t}, y_t):= \sum_{i=1}^{t} \beta \log \frac{\pi_\phi(y_{i}|\mathbf{y}_{<i})}{\pi_\text{ref}(y_{i}|\mathbf{y}_{<i})}$. $q_\theta^t$ is the exponential average of $r_\theta$ at step $t$.*
|
24 |
+
|
25 |
+
$$
|
26 |
+
q_\phi^t(\mathbf{y}_{<t}, y_t) = \beta \log \mathbb{E}_{\pi_\text{ref}(\mathbf{y}|\mathbf{y}_{\leq t})} e^{\frac{1}{\beta}r_\phi(\mathbf{y})}
|
27 |
+
$$
|
28 |
+
|
29 |
+
*Hence, **$q_\theta^t$ represents an exact expectation of outcome reward $r_\theta$ at step $t$, i.e., the Q value.***
|
30 |
+
|
31 |
+
</aside>
|
32 |
+
|
33 |
+
The proposition indicates that when modeling $r_\phi(\mathbf{y}):= \beta \log \frac{\pi_\phi(\mathbf{y})}{\pi_\text{ref}(\mathbf{y})}$ to train an ORM with the standard pipeline, where $\beta$ is a hyperparameter, $\phi$ can implicitly learn a Q function. Hence, process reward $r_\phi^t$ can be obtained by:
|
34 |
+
|
35 |
+
$$
|
36 |
+
r_\phi^t := q_\phi^t - q_\phi^{t-1} = \beta \log \frac{\pi_\phi(y_{t}|\mathbf{y}_{<t})}{\pi_\text{ref}(y_{t}|\mathbf{y}_{<t})}
|
37 |
+
$$
|
38 |
+
|
39 |
+
Therefore, **we can indeed obtain PRMs simply by collecting response-level data and training an ORM, without any burden of annotating step labels.**
|
40 |
+
|
41 |
+
The proposition is **agnostic to specific choices of the training objective of ORMs**. It can be instantiated with different objectives as vanilla ORM training, with the only difference being substituting the $r_\phi \left( \mathbf{y} \right)$ with $\beta \log \frac{\pi_\phi(\mathbf{y})}{\pi_\text{ref}(\mathbf{y})}$. For example, [DPO](https://arxiv.org/abs/2305.18290) already meets our assumption and serves as a strong variant, while in this work, we instantiate our implicit PRM with cross entropy (CE) loss due to memory efficiency:
|
42 |
+
|
43 |
+
$$
|
44 |
+
\mathcal{L}_{CE} = l \cdot \log \sigma \left( \beta \log \frac{\pi_\phi(\mathbf{y})}{\pi_\text{ref}(\mathbf{y})} \right) + (1-l) \cdot \log\left[ 1 - \sigma \left( \beta \log \frac{\pi_\phi(\mathbf{y})}{\pi_\text{ref}(\mathbf{y})} \right) \right]
|
45 |
+
$$
|
46 |
+
|
47 |
+
We started the second-stage training on top of [EurusPRM-Stage1](https://huggingface.co/PRIME-RL/EurusPRM-Stage1) with fine-grained step-level labels. To obtain step-level labels, we employed Llama-3.1-70B-Inst and Qwen2.5-72B-Inst to insert nuance errors into correct solutions. We also mixed response-level data in this stage. The model was continually trained with $L_{CE}$ with a learning rate of 5e-7 and a batch-size of 64.
|
48 |
+
|
49 |
+
## Usage
|
50 |
+
|
51 |
+
We show an example leveraging **EurusPRM-Stage2** below:
|
52 |
+
|
53 |
+
```python
|
54 |
+
coef=0.001
|
55 |
+
d = {'query':'111','answer':['111','222']
|
56 |
+
}
|
57 |
+
model = AutoModelForCausalLM.from_pretrained('PRIME-RL/EurusPRM-Stage2')
|
58 |
+
tokenizer = AutoTokenizer.from_pretrained('PRIME-RL/EurusPRM-Stage2')
|
59 |
+
ref_model = AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-Math-7B-Instruct')
|
60 |
+
input_ids = tokenizer.apply_chat_template([
|
61 |
+
{"role": "user", "content": d["query"]},
|
62 |
+
{"role": "assistant", "content": "\n\n".join(d["answer"])},
|
63 |
+
], tokenize=True, add_generation_prompt=False)
|
64 |
+
attention_mask = input_ids!=tokenizer.pad_token_id
|
65 |
+
step_last_tokens = []
|
66 |
+
for step_num in range(0, len(d["answer"])+1):
|
67 |
+
conv = tokenizer.apply_chat_template([
|
68 |
+
{"role":"user", "content":d["query"]},
|
69 |
+
{"role":"assistant", "content":"\n\n".join(d["answer"][:step_num])},
|
70 |
+
], tokenize=False, add_generation_prompt=False)
|
71 |
+
conv = conv.strip()
|
72 |
+
if step_num!=0 and step_num!=len(d['answer']):
|
73 |
+
conv+='\n\n'
|
74 |
+
currect_ids = tokenizer.encode(conv,add_special_tokens=False)
|
75 |
+
step_last_tokens.append(len(currect_ids) - 2)
|
76 |
+
|
77 |
+
inputs = {'input_ids':input_ids,'attention_mask':attention_mask,'labels':input_ids}
|
78 |
+
step_last_tokens = torch.tensor(step_last_tokens)
|
79 |
+
|
80 |
+
def get_logps(model,inputs):
|
81 |
+
logits = model(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask']).logits
|
82 |
+
labels = inputs['labels'][:, 1:].clone().long()
|
83 |
+
logits = logits[:, :-1, :]
|
84 |
+
labels[labels == -100] = 0
|
85 |
+
per_token_logps = torch.gather(logits.log_softmax(-1), dim=2, index=labels.unsqueeze(2)).squeeze(2)
|
86 |
+
return per_token_logps
|
87 |
+
|
88 |
+
with torch.no_grad():
|
89 |
+
per_token_logps = get_logps(model, inputs)
|
90 |
+
per_token_logps = get_logps(ref_model,inputs)
|
91 |
+
|
92 |
+
raw_reward = per_token_logps - ref_per_token_logps
|
93 |
+
beta_reward = coef * raw_reward
|
94 |
+
beta_reward = beta_reward.cumsum(-1)
|
95 |
+
beta_reward = beta_reward.gather(dim=-1, index=step_last_tokens[1:])
|
96 |
+
print(beta_reward)
|
97 |
+
```
|
98 |
+
|
99 |
+
## Evaluation
|
100 |
+
|
101 |
+
### Evaluation Base Model
|
102 |
+
|
103 |
+
We adopt **Eurus-2-7B-SFT**, **Qwen2.5-7B-Instruct** and **Llama-3.1-70B-Instruct** as generation models to evaluate the performance of our implicit PRM. For all models, we set the sampling temperature as 0.5, *p* of the top-*p* sampling as 1.
|
104 |
+
|
105 |
+
### Best-of-N Sampling
|
106 |
+
|
107 |
+
We use Best-of-64 as our evaluation metric. The weighting methods are different for several PRMs below.
|
108 |
+
|
109 |
+
- For [Skywork-o1-Open-PRM-Qwen-2.5-7B](https://huggingface.co/Skywork/Skywork-o1-Open-PRM-Qwen-2.5-7B), we use simple average reward across all steps.
|
110 |
+
- For EurusPRM-Stage 1, we use the minimum reward across all steps.
|
111 |
+
- For EurusPRM-Stage 2, we use the accumulative rewards.
|
112 |
+
|
113 |
+
**Eurus-2-7B-SFT**
|
114 |
+
|
115 |
+
| Method | Reward Model | MATH | AMC | AIME_2024 | OlympiadBench | Minerva Math | Avg |
|
116 |
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
117 |
+
| Greedy Pass @ 1 | N/A | 65.1 | 30.1 | 3.3 | 29.8 | 32.7 | 32.2 |
|
118 |
+
| Majority Voting @ 64 | N/A | 65.6 | 53.0 | 13.3 | 39.1 | 22.4 | 38.7 |
|
119 |
+
| Best-of-64 | Skywork-o1-Open-PRM-Qwen-2.5-7B | 47.2 | 45.8 | 10.0 | 32.3 | 16.2 | 30.3 |
|
120 |
+
| | EurusPRM-Stage 1 | 44.6 | 41.0 | 6.7 | 32.9 | 17.3 | 28.5 |
|
121 |
+
| | EurusPRM-Stage 2 | 47.2 | 43.4 | 13.3 | 33.8 | 19.2 | 31.4 |
|
122 |
+
| Weighted Best-of-64 | Skywork-o1-Open-PRM-Qwen-2.5-7B | 64.6 | **55.4** | 13.3 | 41.3 | 23.2 | 39.6 |
|
123 |
+
| | EurusPRM-Stage 1 | **66.0** | 54.2 | 13.3 | 39.6 | **29.0** | **40.4** |
|
124 |
+
| | EurusPRM-Stage 2 | **66.0** | 54.2 | 13.3 | **39.7** | **29.0** | **40.4** |
|
125 |
+
|
126 |
+
**Llama-3.1-70B-Instruct**
|
127 |
+
|
128 |
+
| Method | Reward Model | MATH | AMC | AIME 2024 | OlympiadBench | Minerva Math | Avg |
|
129 |
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
130 |
+
| Greedy Pass @ 1 | N/A | 62.1 | 37.3 | 16.7 | 27.7 | 34.2 | 35.6 |
|
131 |
+
| Majority Voting @ 64 | N/A | 80.2 | 53.0 | 26.7 | 40.4 | 38.6 | 47.8 |
|
132 |
+
| Best-of-N @ 64 | Skywork-o1-Open-PRM-Qwen-2.5-7B | 77.8 | 56.6 | 23.3 | 39.0 | 31.6 | 45.7 |
|
133 |
+
| | EurusPRM-Stage 1 | 77.8 | 44.6 | **26.7** | 35.3 | 41.5 | 45.2 |
|
134 |
+
| | EurusPRM-Stage 2 | 80.6 | **59.0** | 20.0 | 37.6 | 44.9 | 48.4 |
|
135 |
+
| Weighted Best-of-64 | Skywork-o1-Open-PRM-Qwen-2.5-7B | **81.2** | 56.6 | 23.3 | **42.4** | 38.2 | 48.3 |
|
136 |
+
| | EurusPRM-Stage 1 | 80.4 | 53.0 | **26.7** | 40.9 | **46.7** | **49.5** |
|
137 |
+
| | EurusPRM-Stage 2 | 80.4 | 53.0 | **26.7** | 41.0 | 46.3 | **49.5** |
|
138 |
+
|
139 |
+
**Qwen2.5-7B-Instruct**
|
140 |
+
|
141 |
+
| Method | Reward Model | MATH | AMC | AIME 2024 | OlympiadBench | Minerva Math | Avg |
|
142 |
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
143 |
+
| Greedy Pass @ 1 | N/A | 73.3 | 47.0 | 13.3 | 39.4 | 35.3 | 41.7 |
|
144 |
+
| Majority Voting @ 64 | N/A | 82.0 | 53.0 | 16.7 | 43.0 | 36.4 | 46.2 |
|
145 |
+
| Best-of-N @ 64 | Skywork-o1-Open-PRM-Qwen-2.5-7B | 85.2 | **60.2** | **20.0** | **44.7** | 32.7 | 48.6 |
|
146 |
+
| | EurusPRM-Stage 1 | 81.8 | 47.0 | 16.7 | 40.1 | 41.5 | 45.4 |
|
147 |
+
| | EurusPRM-Stage 2 | **86.0** | 59.0 | 16.7 | 41.4 | 41.5 | **48.9** |
|
148 |
+
| Weighted Best-of-64 | Skywork-o1-Open-PRM-Qwen-2.5-7B | 83.6 | 55.4 | 13.3 | 43.7 | 36.8 | 46.6 |
|
149 |
+
| | EurusPRM-Stage 1 | 82.6 | 53.0 | 16.7 | 42.7 | 45.2 | 48.0 |
|
150 |
+
| | EurusPRM-Stage 2 | 84.8 | 53.0 | 16.7 | 43.2 | **45.6** | 48.7 |
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
## Citation
|
155 |
+
|
156 |
+
```latex
|
157 |
+
@misc{cui2024process,
|
158 |
+
title={Process Reinforcement through Implicit Rewards},
|
159 |
+
author={Ganqu Cui and Lifan Yuan and Zefan Wang and Hanbin Wang and Wendi Li and Bingxiang He and Yuchen Fan and Tianyu Yu and Qixin Xu and Weize Chen and Jiarui Yuan and Huayu Chen and Kaiyan Zhang and Xingtai Lv and Shuo Wang and Yuan Yao and Hao Peng and Yu Cheng and Zhiyuan Liu and Maosong Sun and Bowen Zhou and Ning Ding},
|
160 |
+
year={2025}
|
161 |
+
}
|
162 |
+
```
|
163 |
+
|
164 |
+
```latex
|
165 |
+
@article{yuan2024implicitprm,
|
166 |
+
title={Free Process Rewards without Process Labels},
|
167 |
+
author={Lifan Yuan and Wendi Li and Huayu Chen and Ganqu Cui and Ning Ding and Kaiyan Zhang and Bowen Zhou and Zhiyuan Liu and Hao Peng},
|
168 |
+
journal={arXiv preprint arXiv:2412.01981},
|
169 |
+
year={2024}
|
170 |
+
}
|
171 |
+
```
|
figs/implicit.png
ADDED