-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoffline_visionExample.py
More file actions
34 lines (28 loc) · 1.02 KB
/
offline_visionExample.py
File metadata and controls
34 lines (28 loc) · 1.02 KB
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
import PIL
from vllm import LLM, SamplingParams
data = PIL.Image.open("../data/example.jpg")
model_name = "Qwen/Qwen2-VL-7B-Instruct"
llm = LLM(
model=model_name,
max_num_seqs=5,
)
stop_token_ids = None
question = "Describe the image"
prompt_template = ("<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
"<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>"
f"{question}<|im_end|>\n"
"<|im_start|>assistant\n")
inputs = {
"prompt": prompt_template,
"multi_modal_data": {
"image": data
},
}
sampling_params = SamplingParams(temperature=0.2,
max_tokens=128,
stop_token_ids=stop_token_ids,
)
outputs = llm.generate(inputs, sampling_params=sampling_params)
for o in outputs:
generated_text = o.outputs[0].text
print(generated_text)