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 = Qwen2_5_VLForConditionalGeneration.from_pretrained(
7 "UCSC-VLAA/MedVLThinker-7B-RL_m23k-RL_PMC",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11processor = AutoProcessor.from_pretrained("UCSC-VLAA/MedVLThinker-7B-RL_m23k-RL_PMC")
12
13# Example usage
14messages = [
15 {
16 "role": "system",
17 "content": "You will solve a problem/request. You should provide your thoughts within <think> </think> tags before providing the answer. Write your final answer within <answer> </answer> tags.",
18 },
19 {
20 "role": "user",
21 "content": [
22 {
23 "type": "image",
24 "image": "path/to/medical/image.jpg",
25 },
26 {"type": "text", "text": "What can you see in this medical image?"},
27 ],
28 }
29]
30
31# Preparation for inference
32text = processor.apply_chat_template(
33 messages, tokenize=False, add_generation_prompt=True
34)
35image_inputs, video_inputs = process_vision_info(messages)
36inputs = processor(
37 text=[text],
38 images=image_inputs,
39 videos=video_inputs,
40 padding=True,
41 return_tensors="pt",
42)
43inputs = inputs.to("cuda")
44
45# Inference
46generated_ids = model.generate(**inputs, max_new_tokens=2048, temperature=0.6, top_p=0.95, do_sample=True)
47generated_ids_trimmed = [
48 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
49]
50output_text = processor.batch_decode(
51 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
52)
53print(output_text)1@article{medvlthinker2025,
2 title={MedVLThinker: Simple Baselines for Multimodal Medical Reasoning},
3 author={Huang, Xiaoke and Wu, Juncheng and Liu, Hui and Tang, Xianfeng and Zhou, Yuyin},
4 journal={arXiv preprint},
5 year={2025}
6}