This is a fine-tuned version of
Qwen/Qwen2.5-VL-3B-Instruct trained on the
VQA-RAD radiology visual question answering dataset using
QLoRA. The LoRA adapter weights have been
merged into the base model, so no PEFT dependency is required at inference time.
Language attention and MLP layers. Vision encoder weights were frozen during training — only the language decoder was adapted.
VQA-RAD (
flaviagiammarino/vqa-rad) is a clinician-generated radiology VQA dataset with 2,248 question-answer pairs across 315 radiology images covering chest X-rays, head CTs, and abdominal scans.
1from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
2from qwen_vl_utils import process_vision_info
3from PIL import Image
4import torch
5
6model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
7 "vishal98m/qwen2.5-vl-3b-finetuned-medical-vqa-rad",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11processor = AutoProcessor.from_pretrained(
12 "Qwen/Qwen2.5-VL-3B-Instruct",
13 use_fast=False
14)
15
16def ask(image: Image.Image, question: str) -> str:
17 prompt = (
18 f"{question}\n"
19 "Provide only the short direct answer in 1-5 words. "
20 "Do not explain or add any extra text."
21 )
22 messages = [
23 {
24 "role": "user",
25 "content": [
26 {"type": "image", "image": image},
27 {"type": "text", "text": prompt},
28 ],
29 }
30 ]
31 text = processor.apply_chat_template(
32 messages, tokenize=False, add_generation_prompt=True
33 )
34 image_inputs, video_inputs = process_vision_info(messages)
35 inputs = processor(
36 text=[text],
37 images=image_inputs,
38 videos=video_inputs,
39 padding=True,
40 return_tensors="pt",
41 ).to("cuda")
42
43 with torch.no_grad():
44 generated_ids = model.generate(**inputs, max_new_tokens=32)
45
46 trimmed = [
47 out[len(inp):]
48 for inp, out in zip(inputs.input_ids, generated_ids)
49 ]
50 return processor.batch_decode(
51 trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
52 )[0].strip()
53
54# Example
55image = Image.open("chest_xray.jpg")
56print(ask(image, "Is there any abnormality in this chest X-ray?"))
1@article{lau2018dataset,
2 title={A Dataset of Clinically Generated Visual Questions and Answers about Radiology Images},
3 author={Lau, Jason J and Gayen, Soumya and Ben Abacha, Asma and Demner-Fushman, Dina},
4 journal={Scientific data},
5 volume={5},
6 number={1},
7 pages={1--10},
8 year={2018},
9 publisher={Nature Publishing Group}
10}
1@article{hu2022lora,
2 title={LoRA: Low-Rank Adaptation of Large Language Models},
3 author={Hu, Edward J and Shen, Yelong and Wallis, Phillip and Allen-Zhu, Zeyuan and Li, Yuanzhi and Wang, Shean and Wang, Lu and Chen, Weizhu},
4 journal={ICLR},
5 year={2022}
6}
7
8@article{dettmers2023qlora,
9 title={QLoRA: Efficient Finetuning of Quantized LLMs},
10 author={Dettmers, Tim and Pagnoni, Artidoro and Fansi, Ari and Zettlemoyer, Luke},
11 journal={NeurIPS},
12 year={2023}
13}
This qwen2_5_vl model was trained 2x faster with
Unsloth