This model retains the excellent visual perception capabilities of the Qwen2.5-VL ecosystem (including object detection, OCR, chart analysis, and dense image understanding). The key differentiator is that it has been trained to prioritize generating intermediate analytical steps (Chain-of-Thought) before formulating the final response.
Users should be aware of these limitations. A "Human-in-the-loop" approach is strongly recommended when dealing with sensitive data or critical information extraction.
1from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
2import torch
3
4# 1. Initialize model and processor
5model_id = "Manh1011/Qwen2.5-VL-3B-GRPO-Thinking"
6model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
7 model_id,
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11processor = AutoProcessor.from_pretrained(model_id)
12
13# 2. Prepare multi-modal inputs
14messages = [
15 {
16 "role": "user",
17 "content": [
18 {"type": "image", "url": "[https://example.com/image.jpg](https://example.com/image.jpg)"}, # Replace with actual image URL
19 {"type": "text", "text": "Carefully analyze this image and explain step-by-step what is happening."}
20 ]
21 }
22]
23
24# 3. Process the data
25text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
26inputs = processor(
27 text=[text],
28 images=["[https://example.com/image.jpg](https://example.com/image.jpg)"],
29 return_tensors="pt",
30 padding=True
31).to(model.device)
32
33# 4. Generate Output (Inference)
34generated_ids = model.generate(**inputs, max_new_tokens=1024)
35generated_ids_trimmed = [
36 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
37]
38
39output_text = processor.batch_decode(
40 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
41)
42print(output_text[0])