Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,129 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
##
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
<
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
<
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
###
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
##
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
---
|
| 5 |
|
| 6 |
+
# Llama-3.2-3B-Oat-Zero
|
| 7 |
+
|
| 8 |
+
## Links
|
| 9 |
+
|
| 10 |
+
- 📜 [Paper](https://github.com/sail-sg/understand-r1-zero/blob/main/understand-r1-zero.pdf)
|
| 11 |
+
- 💻 [GitHub](https://github.com/sail-sg/understand-r1-zero)
|
| 12 |
+
- 🤗 [Oat-Zero Collection](https://huggingface.co/collections/sail/oat-zero-understanding-r1-zero-like-training-67dcdb07b9f3eb05f1501c4a)
|
| 13 |
+
|
| 14 |
+
## Introduction
|
| 15 |
+
|
| 16 |
+
To understand R1-Zero-like training, we critically examine two core components: **base models**
|
| 17 |
+
and **reinforcement learning**. We highlight our findings below.
|
| 18 |
+
|
| 19 |
+
### On base models:
|
| 20 |
+
1. **DeepSeek-V3-Base already exhibit "Aha moment"**.
|
| 21 |
+
<p align="center">
|
| 22 |
+
<img src="https://raw.githubusercontent.com/sail-sg/understand-r1-zero/refs/heads/main/assets/deepseek-base-aha.png" width=65%/>
|
| 23 |
+
</p>
|
| 24 |
+
|
| 25 |
+
2. As the popular choice for R1-Zero-like training, Qwen2.5 base models demonstrate strong reasoning capabilities
|
| 26 |
+
even **without** prompt templates: the average benchmark scores improve by **~60%** (compared to the traditional 4-shot prompting)!
|
| 27 |
+
<p align="center">
|
| 28 |
+
<img src="https://raw.githubusercontent.com/sail-sg/understand-r1-zero/refs/heads/main/assets/qwen-math-base-scores.png" width=65%/>
|
| 29 |
+
</p>
|
| 30 |
+
|
| 31 |
+
### On reinforcement learning:
|
| 32 |
+
|
| 33 |
+
3. GRPO leads to **biased** optimization! We propose a simple fix that improves token efficiency
|
| 34 |
+
while maintaining reasoning performance, termed as Dr. GRPO (GRPO **D**one **R**ight).
|
| 35 |
+
<p align="center">
|
| 36 |
+
<img src="https://raw.githubusercontent.com/sail-sg/understand-r1-zero/refs/heads/main/assets/drgrpo.png" width=65%/>
|
| 37 |
+
</p>
|
| 38 |
+
|
| 39 |
+
4. In R1-Zero-like training, the template and the question set perform a duet to affect the RL dynamics
|
| 40 |
+
* (Left Plot) For Qwen2.5-Math-1.5B, a mismatched template (e.g., R1 template) in fact **destructs the reasoning capabilities before RL reconstructing it**. This makes the improvement impressive on the surface.
|
| 41 |
+
* (Middle Plot) However, if a template does not deviate from the pretraining distribution too far, even a small and completely o.o.d. question set (e.g., GSM8K) could induce the reasoning ability equally well, by reinforcing correct reasoning behaviors instead of infusing new knowledge.
|
| 42 |
+
<p align="center">
|
| 43 |
+
<img src="https://raw.githubusercontent.com/sail-sg/understand-r1-zero/refs/heads/main/assets/template-data-duet.png" width=65%/>
|
| 44 |
+
</p>
|
| 45 |
+
|
| 46 |
+
5. Beyond Qwen, Llama can also be RL-tuned from base models. In this case, domain-specific pretraining will improves RL ceiling.
|
| 47 |
+
* (Right Plot) GRPO can even make Llama with math knowledge "Aha" by increasing the output length; however, it is likely due to its length bias, which can be removed by Dr. GRPO.
|
| 48 |
+
<p align="center">
|
| 49 |
+
<img src="https://raw.githubusercontent.com/sail-sg/understand-r1-zero/refs/heads/main/assets/llama-r1-zero.png" width=65%/>
|
| 50 |
+
</p>
|
| 51 |
+
|
| 52 |
+
### Our minimalist R1-Zero recipe:
|
| 53 |
+
Our analysis suggests a minimalist recipe for R1-Zero-like training:
|
| 54 |
+
|
| 55 |
+
We RL-tune Qwen2.5-
|
| 56 |
+
Math-7B using the (unbiased) Dr. GRPO algorithm on MATH level 3-5 questions with the Qwen-Math template, and achieve state-of-the-art performance with only 27 hours compute on 8× A100 GPUs
|
| 57 |
+
<p align="center">
|
| 58 |
+
<img src="https://raw.githubusercontent.com/sail-sg/understand-r1-zero/refs/heads/main/assets/benchmark.png" width=90%/>
|
| 59 |
+
</p>
|
| 60 |
+
|
| 61 |
+
If you are interested in more details, please check out our [paper](https://github.com/sail-sg/understand-r1-zero/blob/main/understand-r1-zero.pdf)!
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
## Usage
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
import time
|
| 68 |
+
import vllm
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def apply_qwen_math_template(question: str):
|
| 72 |
+
return (
|
| 73 |
+
"<|im_start|>system\nPlease reason step by step, and put your final answer within \\boxed{}.<|im_end|>\n<|im_start|>user\n"
|
| 74 |
+
+ question
|
| 75 |
+
+ "<|im_end|>\n<|im_start|>assistant\n"
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
def apply_r1_template(question: str):
|
| 79 |
+
return (
|
| 80 |
+
"A conversation between User and Assistant. The User asks a question, and the Assistant solves it. The Assistant first thinks about the reasoning process in the mind and then provides the User with the answer. "
|
| 81 |
+
"The reasoning process is enclosed within <think> </think> and answer is enclosed within <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>.\nUser: "
|
| 82 |
+
+ question
|
| 83 |
+
+ "\nAssistant: <think>"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
model_name = "sail/Llama-3.2-3B-Oat-Zero"
|
| 87 |
+
|
| 88 |
+
sampling_params = vllm.SamplingParams(
|
| 89 |
+
n=1,
|
| 90 |
+
temperature=0,
|
| 91 |
+
top_p=1,
|
| 92 |
+
max_tokens=3000,
|
| 93 |
+
logprobs=2,
|
| 94 |
+
seed=int(time.time_ns()),
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
model = vllm.LLM(
|
| 98 |
+
model_name,
|
| 99 |
+
swap_space=32,
|
| 100 |
+
max_model_len=4096,
|
| 101 |
+
dtype="bfloat16",
|
| 102 |
+
enable_prefix_caching=True,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
if "Llama-3.2-3B-Oat-Zero" in model_name:
|
| 106 |
+
apply_template = apply_r1_template
|
| 107 |
+
else:
|
| 108 |
+
apply_template = apply_qwen_math_template
|
| 109 |
+
|
| 110 |
+
prompts = [
|
| 111 |
+
"How many positive whole-number divisors does 196 have?"
|
| 112 |
+
]
|
| 113 |
+
prompts = list(map(apply_template, prompts))
|
| 114 |
+
outputs = model.generate(prompts, sampling_params)
|
| 115 |
+
|
| 116 |
+
print(outputs)
|
| 117 |
+
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
## Citation
|
| 121 |
+
|
| 122 |
+
```latex
|
| 123 |
+
@misc{liu2025understanding,
|
| 124 |
+
title={Understanding R1-Zero-Like Training: A Critical Perspective},
|
| 125 |
+
author={Zichen Liu and Changyu Chen and Wenjun Li and Penghui Qi and Tianyu Pang and Chao Du and Wee Sun Lee and Min Lin},
|
| 126 |
+
year={2025},
|
| 127 |
+
howpublished={\url{https://github.com/sail-sg/understand-r1-zero}},
|
| 128 |
+
}
|
| 129 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|