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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
base_model:
|
| 7 |
+
- Qwen/Qwen2.5-VL-7B-Instruct
|
| 8 |
+
pipeline_tag: visual-question-answering
|
| 9 |
+
tags:
|
| 10 |
+
- multi-modal
|
| 11 |
+
- large-language-model
|
| 12 |
+
- video-language-model
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
<p align="center">
|
| 16 |
+
<img src="https://github.com/LengSicong/MMR1/blob/main/assets/logo.png?raw=true" width="150" style="margin-bottom: 0.2;"/>
|
| 17 |
+
<p>
|
| 18 |
+
|
| 19 |
+
<h3 align="center">
|
| 20 |
+
MMR1: Advancing the Frontiers of Multimodal Reasoning</a></h3>
|
| 21 |
+
<h5 align="center"> If you like our project, please give us a star ⭐ on <a href="https://github.com/LengSicong/MMR1">Github</a> to support us. 🙏🙏 </h2>
|
| 22 |
+
|
| 23 |
+
## 📰 News
|
| 24 |
+
* **[2025.03.11]** 🔥🔥 Release MMR1-Math-v0, achieving SOTA with only 6k data!
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
## Model Description
|
| 28 |
+
MMR1-Math-v0-7B is a Large Multimodal Model specialized in mathematical tasks. Remarkably, MMR1-Math-v0-7B achieves state-of-the-art performance among open-source 7B multimodal models, competing effectively even against proprietary models with significantly larger parameter sizes—all trained using only 6k carefully curated data instances.
|
| 29 |
+
|
| 30 |
+
### Key Highlights:
|
| 31 |
+
|
| 32 |
+
- **SOTA Performance**: Sets a new **state-of-the-art** benchmark on math-related multimodal tasks among open-source 7B models.
|
| 33 |
+
|
| 34 |
+
- **Minimal Training Data**: Remarkably achieves top-tier performance with just **6k** high-quality samples from **public training datasets**.
|
| 35 |
+
|
| 36 |
+
- **Efficient Training with GRPO**: 6 hours of RL training with 64 H100s for 15 epochs.
|
| 37 |
+
|
| 38 |
+
- **Public and High-Quality Data**: Publicly sourced datasets, rigorously filtered and balanced across both difficulty and mathematical problem types.
|
| 39 |
+
|
| 40 |
+
- **Balanced Data Strategy**: Uniform sampling of data based on both task difficulty (filtering out overly simple problems) and mathematical reasoning diversity.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
## Evaluation Results
|
| 44 |
+
|
| 45 |
+
We evaluated our model using [VLMEvalKit](https://github.com/open-compass/VLMEvalKit/tree/main) on four mathematical reasoning benchmarks: MathVista_MINI, MathVision, LogicVista, and MathVerse_MINI.
|
| 46 |
+
|
| 47 |
+
We also include results on the MathVerse_MINI_Vision_Only_cot (MathVerse_V) subset to maintain consistency with the VLMEvalKit leaderboard. The table below compares our model's performance against various open-source and proprietary models.
|
| 48 |
+
|
| 49 |
+
| Model | size | MathVista | MathVision | LogicVista | MathVerse | MathVerse_V |
|
| 50 |
+
|-------|:----:|:--------------:|:----------:|:----------:|:--------------:|:-------------------:|
|
| 51 |
+
| **Close-sourced** | | | | | | |
|
| 52 |
+
| [GPT-4o 1120](https://openai.com/index/gpt-4o-system-card/) | - | 60.0 | 31.2 | 52.8 | 40.6 | - |
|
| 53 |
+
| [Gemini-2.0-flash](https://deepmind.google/technologies/gemini/flash/) | - | 70.4 | 43.6 | 52.3 | 47.8 | - |
|
| 54 |
+
| [Claude3.7-Sonnet](https://www.anthropic.com/news/claude-3-7-sonnet) | - | 66.8 | 41.9 | 58.2 | 46.7 | - |
|
| 55 |
+
| **R1-related** | | | | | | |
|
| 56 |
+
| [LLaVA-CoT](https://github.com/PKU-YuanGroup/LLaVA-CoT) | 11B | 52.5 | 19.9 | 39.6 | 22.6 | - |
|
| 57 |
+
| [Open-R1-Multimodal](https://github.com/EvolvingLMMs-Lab/open-r1-multimodal) | 7B | 60.6 | - | - | - | - |
|
| 58 |
+
| [Mulberry](https://github.com/HJYao00/Mulberry) | 7B | 63.1 | - | - | - | - |
|
| 59 |
+
| [LMM-R1](https://arxiv.org/abs/2503.07536) | 3B | 63.2 | 26.4 | - | - | 41.6 |
|
| 60 |
+
| [R1-Onevision](https://github.com/Fancy-MLLM/R1-Onevision?tab=readme-ov-file) | 7B | - | 26.2 | - | - | 44.1 |
|
| 61 |
+
| [MM-Eureka](https://github.com/ModalMinds/MM-EUREKA) | 8B | 67.1 | 22.2 | - | - | 40.4 |
|
| 62 |
+
| [MM-Eureka](https://github.com/ModalMinds/MM-EUREKA) | 38B | 64.2 | 26.6 | - | - | 48.9 |
|
| 63 |
+
| **Open-sourced** | | | | | | |
|
| 64 |
+
| [Ovis2-8b](https://github.com/AIDC-AI/Ovis) | 8B | 71.8 | 25.9 | 39.4 | 42.3 | - |
|
| 65 |
+
| [MiniCPM-o-2.6](https://github.com/OpenBMB/MiniCPM-o) | 8B | **71.9** | 21.7 | 36.0 | 35.0 | - |
|
| 66 |
+
| [Qwen2.5-VL](https://github.com/QwenLM/Qwen2.5-VL) (official) | 7B | 68.2 | 25.4 | 47.9 | 41.1 | - |
|
| 67 |
+
| [Qwen2.5-VL](https://github.com/QwenLM/Qwen2.5-VL) (reproduced) | 7B | 67.5 | 25.6 | 46.8 | 42.5 | 46.9 |
|
| 68 |
+
| **Ours** | | | | | | |
|
| 69 |
+
| **MMR1-math-v0** | 7B | 71.0 | **30.2** | **50.8** | **45.1** | **49.8** |
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
### Quick Start
|
| 74 |
+
```python
|
| 75 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
|
| 76 |
+
from qwen_vl_utils import process_vision_info
|
| 77 |
+
# default: Load the model on the available device(s)
|
| 78 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 79 |
+
"MMR1/MMR1-Math-v0-7B",
|
| 80 |
+
torch_dtype=torch.bfloat16,
|
| 81 |
+
attn_implementation="flash_attention_2",
|
| 82 |
+
device_map="auto",
|
| 83 |
+
)
|
| 84 |
+
# default processer
|
| 85 |
+
processor = AutoProcessor.from_pretrained("MMR1/MMR1-Math-v0-7B")
|
| 86 |
+
# Example input
|
| 87 |
+
messages = [
|
| 88 |
+
{
|
| 89 |
+
"role": "user",
|
| 90 |
+
"content": [
|
| 91 |
+
{
|
| 92 |
+
"type": "image",
|
| 93 |
+
"image": "path/to/image.jpeg",
|
| 94 |
+
},
|
| 95 |
+
{"type": "text", "text": "Describe this image."},
|
| 96 |
+
],
|
| 97 |
+
}
|
| 98 |
+
]
|
| 99 |
+
# Preparation for inference
|
| 100 |
+
text = processor.apply_chat_template(
|
| 101 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 102 |
+
)
|
| 103 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 104 |
+
inputs = processor(
|
| 105 |
+
text=[text],
|
| 106 |
+
images=image_inputs,
|
| 107 |
+
videos=video_inputs,
|
| 108 |
+
padding=True,
|
| 109 |
+
return_tensors="pt",
|
| 110 |
+
)
|
| 111 |
+
inputs = inputs.to("cuda")
|
| 112 |
+
# Inference: Generation of the output
|
| 113 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 114 |
+
generated_ids_trimmed = [
|
| 115 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 116 |
+
]
|
| 117 |
+
output_text = processor.batch_decode(
|
| 118 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 119 |
+
)
|
| 120 |
+
print(output_text)
|
| 121 |
+
```
|
| 122 |
+
<details>
|
| 123 |
+
<summary>Batch inference</summary>
|
| 124 |
+
|
| 125 |
+
```python
|
| 126 |
+
# Sample messages for batch inference
|
| 127 |
+
messages1 = [
|
| 128 |
+
{
|
| 129 |
+
"role": "user",
|
| 130 |
+
"content": [
|
| 131 |
+
{"type": "image", "image": "file:///path/to/image1.jpg"},
|
| 132 |
+
{"type": "image", "image": "file:///path/to/image2.jpg"},
|
| 133 |
+
{"type": "text", "text": "What are the common elements in these pictures?"},
|
| 134 |
+
],
|
| 135 |
+
}
|
| 136 |
+
]
|
| 137 |
+
messages2 = [
|
| 138 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 139 |
+
{"role": "user", "content": "Who are you?"},
|
| 140 |
+
]
|
| 141 |
+
# Combine messages for batch processing
|
| 142 |
+
messages = [messages1, messages2]
|
| 143 |
+
# Preparation for batch inference
|
| 144 |
+
texts = [
|
| 145 |
+
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
|
| 146 |
+
for msg in messages
|
| 147 |
+
]
|
| 148 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 149 |
+
inputs = processor(
|
| 150 |
+
text=texts,
|
| 151 |
+
images=image_inputs,
|
| 152 |
+
videos=video_inputs,
|
| 153 |
+
padding=True,
|
| 154 |
+
return_tensors="pt",
|
| 155 |
+
)
|
| 156 |
+
inputs = inputs.to("cuda")
|
| 157 |
+
# Batch Inference
|
| 158 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 159 |
+
generated_ids_trimmed = [
|
| 160 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 161 |
+
]
|
| 162 |
+
output_texts = processor.batch_decode(
|
| 163 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 164 |
+
)
|
| 165 |
+
print(output_texts)
|
| 166 |
+
```
|
| 167 |
+
</details>
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
## Citation
|
| 171 |
+
|
| 172 |
+
If you find MMR1 useful for your research and applications, please cite using this BibTeX:
|
| 173 |
+
|
| 174 |
+
```bibtex
|
| 175 |
+
@misc{MMR1-Math2025,
|
| 176 |
+
title={MMR1: Advancing the Frontiers of Multimodal Reasoning},
|
| 177 |
+
author={Sicong Leng*, Jing Wang*, Jiaxi Li*, Hao Zhang*, Zhiqiang Hu, Boqiang Zhang, Hang Zhang, Yuming Jiang, Xin Li, Fan Wang, Yu Rong, Aixin Sun†, Shijian Lu†},
|
| 178 |
+
year={2025},
|
| 179 |
+
howpublished={\url{https://github.com/LengSicong/MMR1}},
|
| 180 |
+
}
|
| 181 |
+
```
|