Views
No views yet
1from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
2from qwen_vl_utils import process_vision_info
3import torch
4
5# Load the model
6model_name="MedVLSynther/MedVLSynther-3B-RL_5K_qwen-glm"
7model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
8 model_name,
9 torch_dtype=torch.bfloat16,
10 device_map="auto"
11)
12processor = AutoProcessor.from_pretrained(model_name)
13
14# Example usage
15messages_1 = [
16 {
17 "role": "system",
18 "content": "You will solve a problem/request. You should provide your thoughts within <think> </think> tags before providing the answer.\nWrite your final answer within <answer> </answer> tags.",
19 },
20 {
21 "role": "user",
22 "content": [
23 {
24 "type": "image",
25 "image": "assets/7bMMMU.png",
26 },
27 {"type": "text", "text": "This line of of myelinated axons in layer IV of visual cortex represents the axons of cells in the Choices: (A) Superior colliculus. (B) Lateral geniculate.(C) Retina. (D) Medial geniculate."},
28 ],
29 }
30]
31
32messages_2 = [
33 {
34 "role": "system",
35 "content": "You will solve a problem/request. You should provide your thoughts within <think> </think> tags before providing the answer.\nWrite your final answer within <answer> </answer> tags.",
36 },
37 {
38 "role": "user",
39 "content": [
40 {
41 "type": "image",
42 "image": "assets/7bslake.png",
43 },
44 {"type": "text", "text": "Does the picture contain kidney? Choices: (A) Yes (B) No"},
45 ],
46 }
47]
48
49# Preparation for inference
50messages = messages_2
51
52text = processor.apply_chat_template(
53 messages, tokenize=False, add_generation_prompt=True
54)
55image_inputs, video_inputs = process_vision_info(messages)
56inputs = processor(
57 text=[text],
58 images=image_inputs,
59 videos=video_inputs,
60 padding=True,
61 return_tensors="pt",
62)
63inputs = inputs.to("cuda")
64
65# Inference
66generated_ids = model.generate(**inputs, max_new_tokens=2048, temperature=0.6, top_p=0.95, do_sample=True)
67generated_ids_trimmed = [
68 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
69]
70output_text = processor.batch_decode(
71 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
72)
73print(output_text)1@article{MedVLSynther,
2 title={MedVLSynther: Synthesizing High-Quality Visual Question Answering from Medical Documents with Generator-Verifier LMMs},
3 author={Huang, Xiaoke and Wang, Ningsen and Liu, Hui and Tang, Xianfeng and Zhou, Yuyin},
4 journal={arXiv preprint arXiv:2510.25867},
5 year={2025}
6}
7@article{MedVLThinker,
8 title={Medvlthinker: Simple baselines for multimodal medical reasoning},
9 author={Huang, Xiaoke and Wu, Juncheng and Liu, Hui and Tang, Xianfeng and Zhou, Yuyin},
10 journal={arXiv preprint arXiv:2508.02669},
11 year={2025}
12}