|
|
--- |
|
|
base_model: |
|
|
- Qwen/Qwen2.5-VL-3B-Instruct |
|
|
tags: |
|
|
- multimodal |
|
|
- reasoning |
|
|
- arxiv:2505.14677 |
|
|
--- |
|
|
|
|
|
|
|
|
### Model Sources |
|
|
|
|
|
<!-- Provide the basic links for the model. --> |
|
|
|
|
|
- **Repository:** https://github.com/maifoundations/Visionary-R1 |
|
|
- **Paper:** https://arxiv.org/pdf/2505.14677 |
|
|
- **Blog:** https://www.maifoundations.com/blog/visionary-r1/ |
|
|
|
|
|
## Quick Start |
|
|
The model is trained based on the Qwen2.5-VL-3B-Instruct. Here we present an example of the use of inference. |
|
|
``` |
|
|
import torch |
|
|
from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor |
|
|
from qwen_vl_utils import process_vision_info |
|
|
|
|
|
|
|
|
model = Qwen2_5_VLForConditionalGeneration.from_pretrained( |
|
|
"maifoundations/Visionary-R1", |
|
|
torch_dtype=torch.bfloat16, |
|
|
attn_implementation="flash_attention_2", |
|
|
device_map="auto", |
|
|
) |
|
|
|
|
|
# default processer |
|
|
processor = AutoProcessor.from_pretrained("maifoundations/Visionary-R1") |
|
|
|
|
|
SYSTEM_PROMPT = ( |
|
|
'''You are tasked with analyzing an image to generate an exhaustive and detailed description. Your goal is to extract and describe all possible information from the image, including but not limited to objects, numbers, text, and the relationships between these elements. The description should be as fine and detailed as possible, capturing every nuance. After generating the detailed description, you need to analyze it and provide step-by-step detailed reasoning for the given question based on the information. Finally, provide a single word or phrase answer to the question. The description, reasoning process and answer are enclosed within <info> </info>, <think> </think> and <answer> </answer> tags, respectively, i.e., <info> image description here </info> <think> reasoning process here </think> <answer> answer here </answer>. |
|
|
''' |
|
|
) |
|
|
|
|
|
messages = [ |
|
|
{"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]}, |
|
|
{ |
|
|
"role": "user", |
|
|
"content": [ |
|
|
{ |
|
|
"type": "image", |
|
|
"image": image_path, |
|
|
}, |
|
|
{"type": "text", "text": question}, |
|
|
], |
|
|
} |
|
|
] |
|
|
|
|
|
# Preparation for inference |
|
|
text = processor.apply_chat_template( |
|
|
messages, tokenize=False, add_generation_prompt=True |
|
|
) |
|
|
image_inputs, video_inputs = process_vision_info(messages) |
|
|
inputs = processor( |
|
|
text=[text], |
|
|
images=image_inputs, |
|
|
videos=video_inputs, |
|
|
padding=True, |
|
|
return_tensors="pt", |
|
|
) |
|
|
inputs = inputs.to("cuda") |
|
|
|
|
|
# Inference: Generation of the output |
|
|
generated_ids = model.generate(**inputs, max_new_tokens=512) |
|
|
generated_ids_trimmed = [ |
|
|
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids) |
|
|
] |
|
|
output_text = processor.batch_decode( |
|
|
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False |
|
|
) |
|
|
print(output_text) |
|
|
``` |
|
|
|
|
|
## Citation |
|
|
|
|
|
``` |
|
|
@article{xia2025visionary, |
|
|
title={Visionary-R1: Mitigating Shortcuts in Visual Reasoning with Reinforcement Learning}, |
|
|
author={Xia, Jiaer and Zang, Yuhang and Gao, Peng and Li, Yixuan and Zhou, Kaiyang}, |
|
|
journal={arXiv preprint arXiv:2505.14677}, |
|
|
year={2025} |
|
|
} |
|
|
``` |