Safetensors
English
qwen2_vl
File size: 3,181 Bytes
fcdc55a
 
 
 
 
 
 
f4d9f07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7f7d7e
f4d9f07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
license: mit
datasets:
- lmms-lab/multimodal-open-r1-8k-verified
language:
- en
base_model:
- Qwen/Qwen2-VL-7B-Instruct
---


# lmms-lab/Qwen2-VL-7B-GRPO-8k

## Model Summary

This model is 7B parameter models trained on 8k curated [dataset](https://huggingface.co/datasets/lmms-lab/multimodal-open-r1-8k-verified) with GRPO

- **Repository:** [EvolvingLMMs-Lab/open-r1-multimodal](https://github.com/EvolvingLMMs-Lab/open-r1-multimodal)
- **Languages:** English, Chinese


### Generation

The generation of this model is the same as the original `Qwen/Qwen2-VL-7B-Instruct` simply changes the model_id in from pretrained would works

```python
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info

SYSTEM_PROMPT = (
    "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant "
    "first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning "
    "process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., "
    "<think> reasoning process here </think><answer> answer here </answer>"
)

# default: Load the model on the available device(s)
model = Qwen2VLForConditionalGeneration.from_pretrained(
    "lmms-lab/Qwen2-VL-7B-GRPO-8k", torch_dtype="auto", device_map="cuda"
)

# default processer
processor = AutoProcessor.from_pretrained("lmms-lab/Qwen2-VL-7B-GRPO-8k")

# The default range for the number of visual tokens per image in the model is 4-16384. You can set min_pixels and max_pixels according to your needs, such as a token count range of 256-1280, to balance speed and memory usage.
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("lmms-lab/Qwen2-VL-7B-GRPO-8k", min_pixels=min_pixels, max_pixels=max_pixels)

messages = [
    {"role": "system", "content": SYSTEM_PROMPT},
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
            },
            {"type": "text", "text": "Describe this image."},
        ],
    }
]

# Preparation for inference
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")

# Inference: Generation of the output
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)


```


# Training

## Model

- **Architecture:** Qwen/Qwen2-VL-7B-Instruct
- **Initialized Model:** Qwen/Qwen2-VL-7B-Instruct
- **Data:** lmms-lab/multimodal-open-r1-8k-verified
- **Precision:** bfloat16