初始化项目,由ModelHub XC社区提供模型
Model: ydeng9/OpenVLThinker-7B Source: Original Platform
This commit is contained in:
98
README.md
Normal file
98
README.md
Normal file
@@ -0,0 +1,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},
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user