Qwen2-VL-2B-Instruct
Compact Multimodal Model for Images and Video
2 min read
This 2.2-billion-parameter model from the Qwen team is designed for deep visual analysis and image- and video-based chat. It can process arbitrary resolution images, analyze videos over 20 minutes long, and recognize text in multiple languages within frames. Thanks to the M-ROPE architecture (a position embedding method for text, images, and video), the model accurately correlates visual and textual data. It is ideal for developers looking to integrate it into chatbots, agent-based device control systems, and multimedia analysis services.
Key features
- Support for arbitrary image resolution (Naive Dynamic Resolution) for more precise detail recognition.
- Analysis of video footage over 20 minutes long with the ability to answer questions about its content.
- Multilingual support for text content within images, including English, Chinese, European languages, and Japanese.
- Use of Multimodal Rotary Position Embedding (M-ROPE) for simultaneous processing of text, 2D visual, and 3D video data.
What you can do
- Build a smart assistant for recognizing screenshots, charts, and documents.
- Connect the model to analyze user video recordings and generate descriptions for them.
- Integrate the VLM (multimodal model) into automation projects using text and visual instructions.
- Process batches of images and multimedia within data processing pipelines.
Example
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
model = Qwen2VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen2-VL-2B-Instruct", torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained(
"Qwen/Qwen2-VL-2B-Instruct"
)
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "[https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg](https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg)",
},
{"type": "text", "text": "Describe this image."},
],
}
]
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")
generated_ids = model.generate(**inputs, max_new_tokens=128)
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)Read more
DetailsBenchmarks: MMMU (val) — 41.1, DocVQA (test) — 90.1, RealWorldQA — 62.9.
Requirements: running with flash_attention_2 enabled is recommended to save VRAM.
Installation notes: requires updating the transformers library from source via pip install git+[https://github.com/huggingface/transformers](https://github.com/huggingface/transformers).










Comments