File size: 2,879 Bytes
50bb8d4
 
 
48ae906
 
 
50bb8d4
 
 
 
 
 
 
 
e8d4b46
50bb8d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a606c2
 
 
 
 
 
 
 
 
 
 
 
 
50bb8d4
1
2
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
---
base_model:
- Qwen/Qwen2.5-VL-7B-Instruct
license: apache-2.0
library_name: transformers
pipeline_tag: image-text-to-text
---

## Overview
OpenVLThinker-7B is a vision-language reasoning model designed to handle multimodal tasks. It is especially tuned for visual mathematical problem-solving.

For more details: [Blog](https://yihe-deng.notion.site/openvlthinker), [GitHub](https://github.com/yihedeng9/OpenVLThinker)

## How to use
```python
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
import torch
from qwen_vl_utils import process_vision_info
import requests
from PIL import Image

# 1. Define model and processor names
model_name = "ydeng9/OpenVLThinker-7B"
processor_name = "Qwen/Qwen2.5-VL-7B-Instruct"

# 2. Load the OpenVLThinker-7B model and processor
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
    model_name,
    torch_dtype=torch.bfloat16,
    attn_implementation="flash_attention_2",
    device_map=device
)
processor = AutoProcessor.from_pretrained(processor_name)

# 3. Define a sample image URL and an instruction
image_url = "https://example.com/sample_image.jpg"  # replace with your image URL
instruction = "Example question"

# 4. Create a multimodal prompt using a chat message structure
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": image_url},
            {"type": "text", "text": instruction},
        ],
    }
]

# 5. Generate a text prompt from the chat messages
text_prompt = processor.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)

# 6. Process image (and video) inputs from the messages
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
    text=[text_prompt],
    images=image_inputs,
    videos=video_inputs,
    padding=True,
    return_tensors="pt",
).to(device)

# 7. Generate the model's response (with specified generation parameters)
generated_ids = model.generate(
    **inputs,
    do_sample=True,
    max_new_tokens=2048,
    top_p=0.001,
    top_k=1,
    temperature=0.01,
    repetition_penalty=1.0,
)

# 8. Decode the generated tokens into human-readable text
generated_text = processor.batch_decode(
    generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
)[0]

# 9. Print the generated response
print("Generated Response:")
print(generated_text)
```

### Citation
```text
@misc{deng2025openvlthinker,
      title={OpenVLThinker: An Early Exploration to Complex Vision-Language Reasoning via Iterative Self-Improvement}, 
      author={Yihe Deng and Hritik Bansal and Fan Yin and Nanyun Peng and Wei Wang and Kai-Wei Chang},
      year={2025},
      eprint={2503.17352},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2503.17352}, 
}
```