Views
No views yet
| Feature | This (Merged) | Adapter Version |
|---|---|---|
| Setup complexity | Simple | Requires PEFT |
| Load time | Faster | Slower |
| Flexibility | Single task mode | Switch adapters |
| Best for | Production deployment | Research/experimentation |
1from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
2import torch
3
4# Load merged model directly - no adapter loading needed!
5model = Qwen2VLForConditionalGeneration.from_pretrained(
6 "mmrech/pitvqa-qwen2vl-merged",
7 torch_dtype=torch.bfloat16,
8 device_map="auto"
9)
10processor = AutoProcessor.from_pretrained("mmrech/pitvqa-qwen2vl-merged")
11
12# Run inference
13from PIL import Image
14image = Image.open("surgical_frame.jpg")
15
16messages = [{"role": "user", "content": [
17 {"type": "image", "image": image},
18 {"type": "text", "text": "Point to the suction device in this surgical image."}
19]}]
20
21text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
22inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
23
24output = model.generate(**inputs, max_new_tokens=128)
25print(processor.decode(output[0], skip_special_tokens=True))
26# Output: <point x='75.8' y='75.1'>suction device</point>1from transformers import BitsAndBytesConfig
2
3bnb_config = BitsAndBytesConfig(
4 load_in_4bit=True,
5 bnb_4bit_quant_type="nf4",
6 bnb_4bit_compute_dtype=torch.bfloat16,
7)
8
9model = Qwen2VLForConditionalGeneration.from_pretrained(
10 "mmrech/pitvqa-qwen2vl-merged",
11 quantization_config=bnb_config,
12 device_map="auto"
13)Prompt: "Point to the suction device in this surgical image."
Output: <point x='75.8' y='75.1'>suction device</point>Prompt: "Draw a bounding box around the tumor region."
Output: <box x1='30' y1='30' x2='70' y2='70'>tumor region</box>Prompt: "What surgical phase is shown?"
Output: sellar phasePrompt: "What instruments are visible in this surgical scene?"
Output: The image shows a suction device positioned in the surgical field...merge_and_unload()1@misc{pitvqa2026,
2 title={PitVQA: Multi-Task Vision-Language Model for Pituitary Surgery},
3 author={Matheus Rech},
4 year={2026},
5 url={https://huggingface.co/mmrech/pitvqa-qwen2vl-merged}
6}