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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# EasyR1: An Efficient, Scalable, Multi-Modality RL Training Framework
|
| 2 |
+
|
| 3 |
+
[](https://github.com/hiyouga/EasyR1/stargazers)
|
| 4 |
+
[](https://twitter.com/llamafactory_ai)
|
| 5 |
+
|
| 6 |
+
### Used by [Amazon Web Services](https://aws.amazon.com/cn/blogs/china/building-llm-model-hub-based-on-llamafactory-and-easyr1/)
|
| 7 |
+
|
| 8 |
+
This project is a clean fork of the original [veRL](https://github.com/volcengine/verl) project to support vision language models, we thank all the authors for providing such a high-performance RL training framework.
|
| 9 |
+
|
| 10 |
+
EasyR1 is efficient and scalable due to the design of **[HybirdEngine](https://arxiv.org/abs/2409.19256)** and the latest release of **[vLLM](https://github.com/vllm-project/vllm)**'s SPMD mode.
|
| 11 |
+
|
| 12 |
+
## Features
|
| 13 |
+
|
| 14 |
+
- Supported models
|
| 15 |
+
- Llama3/Qwen2/Qwen2.5/Qwen3 language models
|
| 16 |
+
- Qwen2/Qwen2.5-VL vision language models
|
| 17 |
+
- DeepSeek-R1 distill models
|
| 18 |
+
|
| 19 |
+
- Supported algorithms
|
| 20 |
+
- GRPO
|
| 21 |
+
- DAPO
|
| 22 |
+
- Reinforce++
|
| 23 |
+
- ReMax
|
| 24 |
+
- RLOO
|
| 25 |
+
|
| 26 |
+
- Supported datasets
|
| 27 |
+
- Any text, vision-text dataset in a [specific format](#custom-dataset)
|
| 28 |
+
|
| 29 |
+
- Supported tricks
|
| 30 |
+
- Padding-free training
|
| 31 |
+
- Resuming from checkpoint
|
| 32 |
+
- Wandb & SwanLab & Mlflow & Tensorboard tracking
|
| 33 |
+
|
| 34 |
+
## Requirements
|
| 35 |
+
|
| 36 |
+
### Software Requirements
|
| 37 |
+
|
| 38 |
+
- Python 3.9+
|
| 39 |
+
- transformers>=4.51.0
|
| 40 |
+
- flash-attn>=2.4.3
|
| 41 |
+
- vllm>=0.8.3
|
| 42 |
+
|
| 43 |
+
We provide a [Dockerfile](./Dockerfile) to easily build environments.
|
| 44 |
+
|
| 45 |
+
We recommend using the [pre-built docker image](https://hub.docker.com/r/hiyouga/verl) in EasyR1.
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
docker pull hiyouga/verl:ngc-th2.7.0-cu12.6-vllm0.9.1
|
| 49 |
+
docker run -it --ipc=host --gpus=all hiyouga/verl:ngc-th2.7.0-cu12.6-vllm0.9.1
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
If your environment does not support Docker, you can consider using **Apptainer**:
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
apptainer pull easyr1.sif docker://hiyouga/verl:ngc-th2.7.0-cu12.6-vllm0.9.1
|
| 56 |
+
apptainer shell --nv --cleanenv --bind /mnt/your_dir:/mnt/your_dir easyr1.sif
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
### Hardware Requirements
|
| 60 |
+
|
| 61 |
+
\* *estimated*
|
| 62 |
+
|
| 63 |
+
| Method | Bits | 1.5B | 3B | 7B | 32B | 72B |
|
| 64 |
+
| ------------------------ | ---- | ------ | ------ | ------ | ------- | ------- |
|
| 65 |
+
| GRPO Full Fine-Tuning | AMP | 2*24GB | 4*40GB | 8*40GB | 16*80GB | 32*80GB |
|
| 66 |
+
| GRPO Full Fine-Tuning | BF16 | 1*24GB | 1*40GB | 4*40GB | 8*80GB | 16*80GB |
|
| 67 |
+
|
| 68 |
+
> [!NOTE]
|
| 69 |
+
> Use `worker.actor.fsdp.torch_dtype=bf16` and `worker.actor.optim.strategy=adamw_bf16` to enable bf16 training.
|
| 70 |
+
>
|
| 71 |
+
> We are working hard to reduce the VRAM in RL training, LoRA support will be integrated in next updates.
|
| 72 |
+
|
| 73 |
+
## Tutorial: Run Qwen2.5-VL GRPO on [Geometry3K](https://huggingface.co/datasets/hiyouga/geometry3k) Dataset in Just 3 Steps
|
| 74 |
+
|
| 75 |
+

|
| 76 |
+
|
| 77 |
+
### Installation
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
git clone https://github.com/hiyouga/EasyR1.git
|
| 81 |
+
cd EasyR1
|
| 82 |
+
pip install -e .
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### GRPO Training
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
bash examples/qwen2_5_vl_7b_geo3k_grpo.sh
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
### Merge Checkpoint in Hugging Face Format
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
python3 scripts/model_merger.py --local_dir checkpoints/easy_r1/exp_name/global_step_1/actor
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
> [!TIP]
|
| 98 |
+
> If you encounter issues with connecting to Hugging Face, consider using `export HF_ENDPOINT=https://hf-mirror.com`.
|
| 99 |
+
>
|
| 100 |
+
> If you want to use SwanLab logger, consider using `bash examples/qwen2_5_vl_7b_geo3k_swanlab.sh`.
|
| 101 |
+
|
| 102 |
+
## Custom Dataset
|
| 103 |
+
|
| 104 |
+
Please refer to the example datasets to prepare your own dataset.
|
| 105 |
+
|
| 106 |
+
- Text dataset: https://huggingface.co/datasets/hiyouga/math12k
|
| 107 |
+
- Image-text dataset: https://huggingface.co/datasets/hiyouga/geometry3k
|
| 108 |
+
- Multi-image-text dataset: https://huggingface.co/datasets/hiyouga/journeybench-multi-image-vqa
|
| 109 |
+
- Text-image mixed dataset: https://huggingface.co/datasets/hiyouga/rl-mixed-dataset
|
| 110 |
+
|
| 111 |
+
## How to Understand GRPO in EasyR1
|
| 112 |
+
|
| 113 |
+

|
| 114 |
+
|
| 115 |
+
- To learn about the GRPO algorithm, you can refer to [Hugging Face's blog](https://huggingface.co/docs/trl/v0.16.1/en/grpo_trainer).
|
| 116 |
+
|
| 117 |
+
## How to Run 70B+ Model in Multi-node Environment
|
| 118 |
+
|
| 119 |
+
1. Start the Ray head node.
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
ray start --head --port=6379 --dashboard-host=0.0.0.0
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
2. Start the Ray worker node and connect to the head node.
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
ray start --address=<head_node_ip>:6379
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
3. Check the Ray resource pool.
|
| 132 |
+
|
| 133 |
+
```bash
|
| 134 |
+
ray status
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
4. Run training script on the Ray head node only.
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
bash examples/qwen2_5_vl_7b_geo3k_grpo.sh
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
See the **[veRL's official doc](https://verl.readthedocs.io/en/latest/start/multinode.html)** for more details about multi-node training and Ray debugger.
|
| 144 |
+
|
| 145 |
+
## Other Baselines
|
| 146 |
+
|
| 147 |
+
We also reproduced the following two baselines of the [R1-V](https://github.com/deep-agent/R1-V) project.
|
| 148 |
+
- [CLEVR-70k-Counting](examples/baselines/qwen2_5_vl_3b_clevr.sh): Train the Qwen2.5-VL-3B-Instruct model on counting problem.
|
| 149 |
+
- [GeoQA-8k](examples/baselines/qwen2_5_vl_3b_geoqa8k.sh): Train the Qwen2.5-VL-3B-Instruct model on GeoQA problem.
|
| 150 |
+
|
| 151 |
+
## Performance Baselines
|
| 152 |
+
|
| 153 |
+
See [baselines.md](assets/baselines.md).
|
| 154 |
+
|
| 155 |
+
## Awesome Work using EasyR1
|
| 156 |
+
|
| 157 |
+
- **MMR1**: Advancing the Frontiers of Multimodal Reasoning. [![[code]](https://img.shields.io/github/stars/LengSicong/MMR1)](https://github.com/LengSicong/MMR1)
|
| 158 |
+
- **Vision-R1**: Incentivizing Reasoning Capability in Multimodal Large Language Models. [![[code]](https://img.shields.io/github/stars/Osilly/Vision-R1)](https://github.com/Osilly/Vision-R1) [![[arxiv]](https://img.shields.io/badge/arxiv-2503.06749-blue)](https://arxiv.org/abs/2503.06749)
|
| 159 |
+
- **Seg-Zero**: Reasoning-Chain Guided Segmentation via Cognitive Reinforcement. [![[code]](https://img.shields.io/github/stars/dvlab-research/Seg-Zero)](https://github.com/dvlab-research/Seg-Zero) [![[arxiv]](https://img.shields.io/badge/arxiv-2503.06520-blue)](https://arxiv.org/abs/2503.06520)
|
| 160 |
+
- **MetaSpatial**: Reinforcing 3D Spatial Reasoning in VLMs for the Metaverse. [![[code]](https://img.shields.io/github/stars/PzySeere/MetaSpatial)](https://github.com/PzySeere/MetaSpatial) [![[arxiv]](https://img.shields.io/badge/arxiv-2503.18470-blue)](https://arxiv.org/abs/2503.18470)
|
| 161 |
+
- **Temporal-R1**: Envolving Temporal Reasoning Capability into LMMs via Temporal Consistent Reward. [![[code]](https://img.shields.io/github/stars/appletea233/Temporal-R1)](https://github.com/appletea233/Temporal-R1)
|
| 162 |
+
- **NoisyRollout**: Reinforcing Visual Reasoning with Data Augmentation. [![[code]](https://img.shields.io/github/stars/John-AI-Lab/NoisyRollout)](https://github.com/John-AI-Lab/NoisyRollout) [![[arxiv]](https://img.shields.io/badge/arxiv-2504.13055-blue)](https://arxiv.org/pdf/2504.13055)
|
| 163 |
+
- **GUI-R1**: A Generalist R1-Style Vision-Language Action Model For GUI Agents. [![[code]](https://img.shields.io/github/stars/ritzz-ai/GUI-R1)](https://github.com/ritzz-ai/GUI-R1) [![[arxiv]](https://img.shields.io/badge/arxiv-2504.10458-blue)](https://arxiv.org/abs/2504.10458)
|
| 164 |
+
- **R1-Track**: Direct Application of MLLMs to Visual Object Tracking via Reinforcement Learning. [![[code]](https://img.shields.io/github/stars/Wangbiao2/R1-Track)](https://github.com/Wangbiao2/R1-Track)
|
| 165 |
+
- **VisionReasoner**: Unified Visual Perception and Reasoning via Reinforcement Learning. [![[code]](https://img.shields.io/github/stars/dvlab-research/VisionReasoner)](https://github.com/dvlab-research/VisionReasoner) [![[arxiv]](https://img.shields.io/badge/arxiv-2505.12081-blue)](https://arxiv.org/abs/2505.12081)
|
| 166 |
+
- **MM-UPT**: Unsupervised Post-Training for Multi-Modal LLM Reasoning via GRPO. [![[code]](https://img.shields.io/github/stars/waltonfuture/MM-UPT)](https://github.com/waltonfuture/MM-UPT) [![[arxiv]](https://img.shields.io/badge/arxiv-2505.22453-blue)](https://arxiv.org/pdf/2505.22453)
|
| 167 |
+
- **RL-with-Cold-Start**: Advancing Multimodal Reasoning via Reinforcement Learning with Cold Start. [![[code]](https://img.shields.io/github/stars/waltonfuture/RL-with-Cold-Start)](https://github.com/waltonfuture/RL-with-Cold-Start) [![[arxiv]](https://img.shields.io/badge/arxiv-2505.22334-blue)](https://arxiv.org/pdf/2505.22334)
|
| 168 |
+
- **ViGoRL**: Grounded Reinforcement Learning for Visual Reasoning. [![[code]](https://img.shields.io/github/stars/Gabesarch/grounded-rl)](https://github.com/Gabesarch/grounded-rl) [![[arxiv]](https://img.shields.io/badge/arxiv-2505.22334-blue)](https://arxiv.org/abs/2505.23678)
|
| 169 |
+
- **Revisual-R1**: Advancing Multimodal Reasoning: From Optimized Cold Start to Staged Reinforcement Learning. [![[code]](https://img.shields.io/github/stars/CSfufu/Revisual-R1)](https://github.com/CSfufu/Revisual-R1) [![[arxiv]](https://img.shields.io/badge/arxiv-2506.04207-blue)](https://arxiv.org/abs/2506.04207)
|
| 170 |
+
- **SophiaVL-R1**: Reinforcing MLLMs Reasoning with Thinking Reward. [![[code]](https://img.shields.io/github/stars/kxfan2002/SophiaVL-R1)](https://github.com/kxfan2002/SophiaVL-R1) [![[arxiv]](https://img.shields.io/badge/arxiv-2505.17018-blue)](https://arxiv.org/abs/2505.17018)
|
| 171 |
+
- **Vision-Matters**: Simple Visual Perturbations Can Boost Multimodal Math Reasoning. [![[code]](https://img.shields.io/github/stars/YutingLi0606/Vision-Matters)](https://github.com/YutingLi0606/Vision-Matters) [![[arxiv]](https://img.shields.io/badge/arxiv-2506.09736-blue)](https://arxiv.org/abs/2506.09736)
|
| 172 |
+
- **VTool-R1**: VLMs Learn to Think with Images via Reinforcement Learning on Multimodal Tool Use. [![[code]](https://img.shields.io/github/stars/VTOOL-R1/vtool-r1)](https://github.com/VTOOL-R1/vtool-r1) [![[arxiv]](https://img.shields.io/badge/arxiv-2505.19255-blue)](https://arxiv.org/abs/2505.19255)
|
| 173 |
+
- **Long-RL**: Scaling RL to Long Sequences. [![[code]](https://img.shields.io/github/stars/NVlabs/Long-RL)](https://github.com/NVlabs/Long-RL) [![[arxiv]](https://img.shields.io/badge/arxiv-2507.07966-blue)](https://arxiv.org/abs/2507.07966)
|
| 174 |
+
|
| 175 |
+
## TODO
|
| 176 |
+
|
| 177 |
+
- Support LoRA (high priority).
|
| 178 |
+
- Support ulysses parallelism for VLMs (middle priority).
|
| 179 |
+
- Support more VLM architectures.
|
| 180 |
+
|
| 181 |
+
> [!NOTE]
|
| 182 |
+
> We will not provide scripts for supervised fine-tuning and inference in this project. If you have such requirements, we recommend using [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory).
|
| 183 |
+
|
| 184 |
+
### Known bugs
|
| 185 |
+
|
| 186 |
+
These features are temporarily disabled for now, we plan to fix them one-by-one in the future updates.
|
| 187 |
+
|
| 188 |
+
- Vision language models are not compatible with ulysses parallelism yet.
|
| 189 |
+
|
| 190 |
+
## Discussion Group
|
| 191 |
+
|
| 192 |
+
👋 Join our [WeChat group](assets/wechat.jpg).
|
| 193 |
+
|
| 194 |
+
## FAQs
|
| 195 |
+
|
| 196 |
+
> ValueError: Image features and image tokens do not match: tokens: 8192, features 9800
|
| 197 |
+
|
| 198 |
+
Increase the `data.max_prompt_length` or reduce the `data.max_pixels`.
|
| 199 |
+
|
| 200 |
+
> RuntimeError: CUDA Error: out of memory at /workspace/csrc/cumem_allocator.cpp:62
|
| 201 |
+
|
| 202 |
+
Reduce the `worker.rollout.gpu_memory_utilization` and enable `worker.actor.offload.offload_params`.
|
| 203 |
+
|
| 204 |
+
> RuntimeError: 0 active drivers ([]). There should only be one.
|
| 205 |
+
|
| 206 |
+
Uninstall `deepspeed` from the current python environment.
|
| 207 |
+
|
| 208 |
+
## Citation
|
| 209 |
+
|
| 210 |
+
Core contributors: [Yaowei Zheng](https://github.com/hiyouga), [Junting Lu](https://github.com/AL-377), [Shenzhi Wang](https://github.com/Shenzhi-Wang), [Zhangchi Feng](https://github.com/BUAADreamer), [Dongdong Kuang](https://github.com/Kuangdd01) and Yuwen Xiong
|
| 211 |
+
|
| 212 |
+
We also thank Guangming Sheng and Chi Zhang for helpful discussions.
|
| 213 |
+
|
| 214 |
+
```bibtex
|
| 215 |
+
@misc{zheng2025easyr1,
|
| 216 |
+
title = {EasyR1: An Efficient, Scalable, Multi-Modality RL Training Framework},
|
| 217 |
+
author = {Yaowei Zheng, Junting Lu, Shenzhi Wang, Zhangchi Feng, Dongdong Kuang, Yuwen Xiong},
|
| 218 |
+
howpublished = {\url{https://github.com/hiyouga/EasyR1}},
|
| 219 |
+
year = {2025}
|
| 220 |
+
}
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
We recommend to also cite the original work.
|
| 224 |
+
|
| 225 |
+
```bibtex
|
| 226 |
+
@article{sheng2024hybridflow,
|
| 227 |
+
title = {HybridFlow: A Flexible and Efficient RLHF Framework},
|
| 228 |
+
author = {Guangming Sheng and Chi Zhang and Zilingfeng Ye and Xibin Wu and Wang Zhang and Ru Zhang and Yanghua Peng and Haibin Lin and Chuan Wu},
|
| 229 |
+
year = {2024},
|
| 230 |
+
journal = {arXiv preprint arXiv: 2409.19256}
|
| 231 |
+
}
|
| 232 |
+
```
|