PKU-ML commited on
Commit
ba1e64c
·
verified ·
1 Parent(s): b5a6e3d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +306 -3
README.md CHANGED
@@ -1,3 +1,306 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - Qwen/Qwen2.5-VL-3B-Instruct
7
+ library_name: transformers
8
+ ---
9
+
10
+
11
+
12
+ # PKU-ML/SSL4RL-MMBench-Rotation-3B
13
+
14
+
15
+ ## 📊 Overview
16
+
17
+ We propose ***SSL4RL***, a novel framework that leverages self-supervised learning (SSL) tasks as a source of verifiable rewards for RL-based fine-tuning.
18
+ Our approach reformulates SSL objectives—such as predicting image rotation or reconstructing masked patches—into dense, automatic reward signals, eliminating the need for human preference data or unreliable AI evaluators.
19
+ Experiments show that SSL4RL substantially improves performance on both **vision-centric** and **vision-language reasoning benchmarks**, with encouraging potentials on **open-ended image-captioning tasks**.
20
+ Through systematic ablations, we identify key factors—such as **data volume, model scale, model choice, task difficulty, and semantic alignment with the target domain** — that influence the effectiveness of SSL4RL tasks, offering new design principles for future work.
21
+ We also demonstrate the framework’s generality by applying it to graph learning, where it yields significant gains.
22
+
23
+ <p align="center">
24
+ <img src="https://raw.githubusercontent.com/PKU-ML/SSL4RL/main/SSL4RL-Overview.png" width="80%"/>
25
+ <p>
26
+
27
+ This model `SSL4RL-MMBench-Rotation-3B` is trained on the Rotation Task, which is built on the benchmark [HuggingFaceM4/MMBench](https://huggingface.co/datasets/HuggingFaceM4/MMBench).
28
+ For training details, we recommend readers to our Paper [SSL4RL: Revisiting Self-supervised Learning as Intrinsic Reward for Visual-Language Reasoning](https://arxiv.org/pdf/2510.16416).
29
+
30
+ <p align="center">
31
+ <img src="https://raw.githubusercontent.com/PKU-ML/SSL4RL/main/SSL4RL-Example.png" width="60%"/>
32
+ <p>
33
+
34
+
35
+ ## 📌 Key Takeaways
36
+
37
+ 1️⃣ **SSL as Intrinsic Reward Sharpens VLM Reasoning**. The SSL4RL paradigm demonstrably enhances vision-language reasoning by repurposing SSL tasks as intrinsic rewards. It deepens the perception and understanding of the image itself, leading towards more precise visual attention and less language bias.
38
+
39
+ 2️⃣ **Task Choice is Critical**. SSL tasks show effectiveness when their inherent semantic aligns with core reasoning skills, while an inappropriate task may induce negative transfer and hinder downstream performance.
40
+
41
+ 3️⃣ **Goldilocks Principle of Task Difficulty**. The effectiveness of an SSL task is contingent on its difficulty being appropriately matched to the model's capacity. Insufficient challenge provides a weak learning signal, while excessive difficulty leads to negative transfer.
42
+
43
+ 4️⃣ **Non-additivity of Rewards**. A naive combination of multiple SSL rewards does not yield cumulative improvements, indicating potential optimization conflicts and underscoring the need for sophisticated integration strategies rather than simple averaging.
44
+
45
+
46
+
47
+
48
+
49
+ ## 🌊 Evaluation on MMBench
50
+
51
+
52
+ | Category | Model | Logical | Relation | Attribute | Coarse | Cross-Inst. | Single-Inst. | *Average* |
53
+ |----------------------|------------------|--------------|--------------|--------------|--------------|---------------|---------------|---------------|
54
+ | Base | Qwen2.5-VL-3B | 61.77 | 41.54 | 76.62 | 73.55 | 64.32 | 82.06 | 72.99 |
55
+ | SSL4RL | Rotation | *65.84* | **80.54** | **83.89** | *80.21* | **71.53** | *84.76* | **80.38** |
56
+ | ~ | Jigsaw | 62.86 | 74.51 | 80.35 | 77.92 |*67.82* | 84.31 | 77.82 |
57
+ | ~ | Contrastive | 61.12 | 73.42 | 71.81 | 65.38 | 58.39 | 78.50 | 69.27 |
58
+ | ~ | Position | **67.65** | *77.19* | *82.22* | **82.15** | 66.51 | **85.39** | *80.08* |
59
+ | Maximal Improvement | | ↑ 5.88 | ↑ 39.00 | ↑ 6.77 | ↑ 8.60 | ↑ 7.21 | ↑ 3.33 | ↑ 7.39 |
60
+
61
+
62
+
63
+
64
+ ## Requirements
65
+ The code of `SSL4RL-MMBench-Rotation-3B` has been in the latest Hugging face transformers and we advise you to build from source with command:
66
+ ```
67
+ pip install git+https://github.com/huggingface/transformers accelerate
68
+ ```
69
+ or you might encounter the following error:
70
+ ```
71
+ KeyError: 'qwen2_5_vl'
72
+ ```
73
+
74
+
75
+ ## Quickstart
76
+
77
+ Below, we provide simple examples to show how to use `SSL4RL-MMBench-Rotation-3B` with 🤗 Transformers.
78
+
79
+ The code of `SSL4RL-MMBench-Rotation-3B` has been in the latest Hugging face transformers and we advise you to build from source with command:
80
+ ```
81
+ pip install git+https://github.com/huggingface/transformers accelerate
82
+ ```
83
+ or you might encounter the following error:
84
+ ```
85
+ KeyError: 'qwen2_5_vl'
86
+ ```
87
+
88
+ We offer a toolkit to help you handle various types of visual input more conveniently, as if you were using an API. This includes base64, URLs, and interleaved images and videos. You can install it using the following command:
89
+
90
+ ```bash
91
+ # It's highly recommanded to use `[decord]` feature for faster video loading.
92
+ pip install qwen-vl-utils[decord]==0.0.8
93
+ ```
94
+
95
+ If you are not using Linux, you might not be able to install `decord` from PyPI. In that case, you can use `pip install qwen-vl-utils` which will fall back to using torchvision for video processing. However, you can still [install decord from source](https://github.com/dmlc/decord?tab=readme-ov-file#install-from-source) to get decord used when loading video.
96
+
97
+ ### Using 🤗 Transformers to Chat
98
+
99
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
100
+
101
+ ```python
102
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
103
+ from qwen_vl_utils import process_vision_info
104
+
105
+ # default: Load the model on the available device(s)
106
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
107
+ "PKU-ML/SSL4RL-MMBench-Rotation-3B", torch_dtype="auto", device_map="auto"
108
+ )
109
+
110
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
111
+ # model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
112
+ # "PKU-ML/SSL4RL-MMBench-Rotation-3B",
113
+ # torch_dtype=torch.bfloat16,
114
+ # attn_implementation="flash_attention_2",
115
+ # device_map="auto",
116
+ # )
117
+
118
+ # default processer
119
+ processor = AutoProcessor.from_pretrained("PKU-ML/SSL4RL-MMBench-Rotation-3B")
120
+
121
+ # The default range for the number of visual tokens per image in the model is 4-16384.
122
+ # You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.
123
+ # min_pixels = 256*28*28
124
+ # max_pixels = 1280*28*28
125
+ # processor = AutoProcessor.from_pretrained("PKU-ML/SSL4RL-MMBench-Rotation-3B", min_pixels=min_pixels, max_pixels=max_pixels)
126
+
127
+ messages = [
128
+ {
129
+ "role": "user",
130
+ "content": [
131
+ {
132
+ "type": "image",
133
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
134
+ },
135
+ {"type": "text", "text": "Describe this image."},
136
+ ],
137
+ }
138
+ ]
139
+
140
+ # Preparation for inference
141
+ text = processor.apply_chat_template(
142
+ messages, tokenize=False, add_generation_prompt=True
143
+ )
144
+ image_inputs, video_inputs = process_vision_info(messages)
145
+ inputs = processor(
146
+ text=[text],
147
+ images=image_inputs,
148
+ videos=video_inputs,
149
+ padding=True,
150
+ return_tensors="pt",
151
+ )
152
+ inputs = inputs.to("cuda")
153
+
154
+ # Inference: Generation of the output
155
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
156
+ generated_ids_trimmed = [
157
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
158
+ ]
159
+ output_text = processor.batch_decode(
160
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
161
+ )
162
+ print(output_text)
163
+ ```
164
+ <details>
165
+ <summary>Multi image inference</summary>
166
+
167
+ ```python
168
+ # Messages containing multiple images and a text query
169
+ messages = [
170
+ {
171
+ "role": "user",
172
+ "content": [
173
+ {"type": "image", "image": "file:///path/to/image1.jpg"},
174
+ {"type": "image", "image": "file:///path/to/image2.jpg"},
175
+ {"type": "text", "text": "Identify the similarities between these images."},
176
+ ],
177
+ }
178
+ ]
179
+
180
+ # Preparation for inference
181
+ text = processor.apply_chat_template(
182
+ messages, tokenize=False, add_generation_prompt=True
183
+ )
184
+ image_inputs, video_inputs = process_vision_info(messages)
185
+ inputs = processor(
186
+ text=[text],
187
+ images=image_inputs,
188
+ videos=video_inputs,
189
+ padding=True,
190
+ return_tensors="pt",
191
+ )
192
+ inputs = inputs.to("cuda")
193
+
194
+ # Inference
195
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
196
+ generated_ids_trimmed = [
197
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
198
+ ]
199
+ output_text = processor.batch_decode(
200
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
201
+ )
202
+ print(output_text)
203
+ ```
204
+ </details>
205
+
206
+ <details>
207
+ <summary>Batch inference</summary>
208
+
209
+ ```python
210
+ # Sample messages for batch inference
211
+ messages1 = [
212
+ {
213
+ "role": "user",
214
+ "content": [
215
+ {"type": "image", "image": "file:///path/to/image1.jpg"},
216
+ {"type": "image", "image": "file:///path/to/image2.jpg"},
217
+ {"type": "text", "text": "What are the common elements in these pictures?"},
218
+ ],
219
+ }
220
+ ]
221
+ messages2 = [
222
+ {"role": "system", "content": "You are a helpful assistant."},
223
+ {"role": "user", "content": "Who are you?"},
224
+ ]
225
+ # Combine messages for batch processing
226
+ messages = [messages1, messages2]
227
+
228
+ # Preparation for batch inference
229
+ texts = [
230
+ processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
231
+ for msg in messages
232
+ ]
233
+ image_inputs, video_inputs = process_vision_info(messages)
234
+ inputs = processor(
235
+ text=texts,
236
+ images=image_inputs,
237
+ videos=video_inputs,
238
+ padding=True,
239
+ return_tensors="pt",
240
+ )
241
+ inputs = inputs.to("cuda")
242
+
243
+ # Batch Inference
244
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
245
+ generated_ids_trimmed = [
246
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
247
+ ]
248
+ output_texts = processor.batch_decode(
249
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
250
+ )
251
+ print(output_texts)
252
+ ```
253
+ </details>
254
+
255
+
256
+ ### More Usage Tips
257
+
258
+ For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
259
+
260
+ ```python
261
+ # You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
262
+ ## Local file path
263
+ messages = [
264
+ {
265
+ "role": "user",
266
+ "content": [
267
+ {"type": "image", "image": "file:///path/to/your/image.jpg"},
268
+ {"type": "text", "text": "Describe this image."},
269
+ ],
270
+ }
271
+ ]
272
+ ## Image URL
273
+ messages = [
274
+ {
275
+ "role": "user",
276
+ "content": [
277
+ {"type": "image", "image": "http://path/to/your/image.jpg"},
278
+ {"type": "text", "text": "Describe this image."},
279
+ ],
280
+ }
281
+ ]
282
+ ## Base64 encoded image
283
+ messages = [
284
+ {
285
+ "role": "user",
286
+ "content": [
287
+ {"type": "image", "image": "data:image;base64,/9j/..."},
288
+ {"type": "text", "text": "Describe this image."},
289
+ ],
290
+ }
291
+ ]
292
+ ```
293
+
294
+
295
+ ## Citation
296
+
297
+ If you find our work helpful, feel free to give us a cite.
298
+
299
+ ```
300
+ @article{guo2025ssl4rl,
301
+ title={SSL4RL: Revisiting Self-supervised Learning as Intrinsic Reward for Visual-Language Reasoning},
302
+ author={Guo, Xiaojun and Zhou, Runyu and Wang, Yifei and Zhang, Qi and Zhang, Chenheng and Jegelka, Stefanie and Wang, Xiaohan and Chai, Jiajun and Yin, Guojun and Lin, Wei and others},
303
+ journal={arXiv preprint arXiv:2510.16416},
304
+ year={2025}
305
+ }
306
+ ```