Image-Text-to-Text
Transformers
Safetensors
Romanian
qwen2_vl
qwen2-vl
qwen
romanian
vlm
instruct
multimodal
conversational
Eval Results (legacy)
text-generation-inference
Instructions to use OpenLLM-Ro/RoQwen2-VL-2B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenLLM-Ro/RoQwen2-VL-2B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenLLM-Ro/RoQwen2-VL-2B-Instruct") 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, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("OpenLLM-Ro/RoQwen2-VL-2B-Instruct") model = AutoModelForMultimodalLM.from_pretrained("OpenLLM-Ro/RoQwen2-VL-2B-Instruct", device_map="auto") 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 Settings
- vLLM
How to use OpenLLM-Ro/RoQwen2-VL-2B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenLLM-Ro/RoQwen2-VL-2B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenLLM-Ro/RoQwen2-VL-2B-Instruct", "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/OpenLLM-Ro/RoQwen2-VL-2B-Instruct
- SGLang
How to use OpenLLM-Ro/RoQwen2-VL-2B-Instruct 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 "OpenLLM-Ro/RoQwen2-VL-2B-Instruct" \ --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": "OpenLLM-Ro/RoQwen2-VL-2B-Instruct", "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 "OpenLLM-Ro/RoQwen2-VL-2B-Instruct" \ --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": "OpenLLM-Ro/RoQwen2-VL-2B-Instruct", "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 OpenLLM-Ro/RoQwen2-VL-2B-Instruct with Docker Model Runner:
docker model run hf.co/OpenLLM-Ro/RoQwen2-VL-2B-Instruct
Unify Getting Started snippet (consistency + decode slice fix)
Browse files
README.md
CHANGED
|
@@ -269,11 +269,13 @@ than Romanian.
|
|
| 269 |
```python
|
| 270 |
import torch
|
| 271 |
from PIL import Image
|
| 272 |
-
from transformers import
|
| 273 |
|
| 274 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 275 |
-
"OpenLLM-Ro/RoQwen2-VL-2B-Instruct",
|
| 276 |
-
|
|
|
|
|
|
|
| 277 |
processor = AutoProcessor.from_pretrained("OpenLLM-Ro/RoQwen2-VL-2B-Instruct")
|
| 278 |
|
| 279 |
image = Image.open("example.jpg").convert("RGB")
|
|
@@ -281,16 +283,21 @@ question = "Descrie imaginea în detaliu."
|
|
| 281 |
|
| 282 |
messages = [
|
| 283 |
{"role": "user", "content": [
|
| 284 |
-
{"type": "image"},
|
| 285 |
{"type": "text", "text": question},
|
| 286 |
]},
|
| 287 |
]
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
```
|
| 295 |
|
| 296 |
## Benchmarks
|
|
|
|
| 269 |
```python
|
| 270 |
import torch
|
| 271 |
from PIL import Image
|
| 272 |
+
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
|
| 273 |
|
| 274 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 275 |
+
"OpenLLM-Ro/RoQwen2-VL-2B-Instruct",
|
| 276 |
+
torch_dtype=torch.bfloat16,
|
| 277 |
+
device_map="auto",
|
| 278 |
+
).eval()
|
| 279 |
processor = AutoProcessor.from_pretrained("OpenLLM-Ro/RoQwen2-VL-2B-Instruct")
|
| 280 |
|
| 281 |
image = Image.open("example.jpg").convert("RGB")
|
|
|
|
| 283 |
|
| 284 |
messages = [
|
| 285 |
{"role": "user", "content": [
|
| 286 |
+
{"type": "image", "image": image},
|
| 287 |
{"type": "text", "text": question},
|
| 288 |
]},
|
| 289 |
]
|
| 290 |
+
inputs = processor.apply_chat_template(
|
| 291 |
+
messages,
|
| 292 |
+
add_generation_prompt=True,
|
| 293 |
+
tokenize=True,
|
| 294 |
+
return_dict=True,
|
| 295 |
+
return_tensors="pt",
|
| 296 |
+
).to(model.device, dtype=torch.bfloat16)
|
| 297 |
+
|
| 298 |
+
with torch.inference_mode():
|
| 299 |
+
outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
|
| 300 |
+
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 301 |
```
|
| 302 |
|
| 303 |
## Benchmarks
|