Instructions to use ydeng9/OpenVLThinker-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ydeng9/OpenVLThinker-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ydeng9/OpenVLThinker-7B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("ydeng9/OpenVLThinker-7B") model = AutoModelForImageTextToText.from_pretrained("ydeng9/OpenVLThinker-7B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use ydeng9/OpenVLThinker-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ydeng9/OpenVLThinker-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ydeng9/OpenVLThinker-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/ydeng9/OpenVLThinker-7B
- SGLang
How to use ydeng9/OpenVLThinker-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ydeng9/OpenVLThinker-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ydeng9/OpenVLThinker-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ydeng9/OpenVLThinker-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ydeng9/OpenVLThinker-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use ydeng9/OpenVLThinker-7B with Docker Model Runner:
docker model run hf.co/ydeng9/OpenVLThinker-7B
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model:
|
| 4 |
+
- Qwen/Qwen2.5-VL-7B-Instruct
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## Overview
|
| 8 |
+
OpenVLThinker-7B is a vision-language reasoning model designed to handle multimodal tasks. It is especially tuned for visual mathematical problem-solving.
|
| 9 |
+
|
| 10 |
+
For more details: [Blog](https://yihe-deng.notion.site/openvlthinker), [GitHub](https://github.com/yihedeng9/OpenVLThinker)
|
| 11 |
+
|
| 12 |
+
## How to use
|
| 13 |
+
```
|
| 14 |
+
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
|
| 15 |
+
import torch
|
| 16 |
+
from qwen_vl_utils import process_vision_info
|
| 17 |
+
import requests
|
| 18 |
+
from PIL import Image
|
| 19 |
+
|
| 20 |
+
# 1. Define model and processor names
|
| 21 |
+
model_name = "ydeng9/OpenVLThinker-7B"
|
| 22 |
+
processor_name = "Qwen/Qwen2.5-VL-7B-Instruct"
|
| 23 |
+
|
| 24 |
+
# 2. Load the OpenVLThinker-7B model and processor
|
| 25 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 26 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 27 |
+
model_name,
|
| 28 |
+
torch_dtype=torch.bfloat16,
|
| 29 |
+
attn_implementation="flash_attention_2",
|
| 30 |
+
device_map=device
|
| 31 |
+
)
|
| 32 |
+
processor = AutoProcessor.from_pretrained(processor_name)
|
| 33 |
+
|
| 34 |
+
# 3. Define a sample image URL and an instruction
|
| 35 |
+
image_url = "https://example.com/sample_image.jpg" # replace with your image URL
|
| 36 |
+
instruction = "Example question"
|
| 37 |
+
|
| 38 |
+
# 4. Create a multimodal prompt using a chat message structure
|
| 39 |
+
messages = [
|
| 40 |
+
{
|
| 41 |
+
"role": "user",
|
| 42 |
+
"content": [
|
| 43 |
+
{"type": "image", "image": image_url},
|
| 44 |
+
{"type": "text", "text": instruction},
|
| 45 |
+
],
|
| 46 |
+
}
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
# 5. Generate a text prompt from the chat messages
|
| 50 |
+
text_prompt = processor.apply_chat_template(
|
| 51 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# 6. Process image (and video) inputs from the messages
|
| 55 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 56 |
+
inputs = processor(
|
| 57 |
+
text=[text_prompt],
|
| 58 |
+
images=image_inputs,
|
| 59 |
+
videos=video_inputs,
|
| 60 |
+
padding=True,
|
| 61 |
+
return_tensors="pt",
|
| 62 |
+
).to(device)
|
| 63 |
+
|
| 64 |
+
# 7. Generate the model's response (with specified generation parameters)
|
| 65 |
+
generated_ids = model.generate(
|
| 66 |
+
**inputs,
|
| 67 |
+
do_sample=True,
|
| 68 |
+
max_new_tokens=2048,
|
| 69 |
+
top_p=0.001,
|
| 70 |
+
top_k=1,
|
| 71 |
+
temperature=0.01,
|
| 72 |
+
repetition_penalty=1.0,
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# 8. Decode the generated tokens into human-readable text
|
| 76 |
+
generated_text = processor.batch_decode(
|
| 77 |
+
generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 78 |
+
)[0]
|
| 79 |
+
|
| 80 |
+
# 9. Print the generated response
|
| 81 |
+
print("Generated Response:")
|
| 82 |
+
print(generated_text)
|
| 83 |
+
```
|