Instructions to use erow/MedVE-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use erow/MedVE-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="erow/MedVE-4B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("erow/MedVE-4B") model = AutoModelForMultimodalLM.from_pretrained("erow/MedVE-4B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use erow/MedVE-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "erow/MedVE-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "erow/MedVE-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/erow/MedVE-4B
- SGLang
How to use erow/MedVE-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "erow/MedVE-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "erow/MedVE-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "erow/MedVE-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "erow/MedVE-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use erow/MedVE-4B with Docker Model Runner:
docker model run hf.co/erow/MedVE-4B
MedVE-4B
MedVE-4B is a medical visual question answering model based on Qwen3-VL-4B-Instruct. It is trained to produce visual evidence as conceptโbounding-box pairs, reasoning, and a final answer. After grounding supervised fine-tuning (V4-SFT), reinforcement learning rewards regions from which a separate frozen model can answer the question, with a blank-image control to discount answers available from language priors.
This release contains the full BF16 policy weights at RL step 200, from the v4sft_medix_pv_calibrated_anyjev_v2_rules_focus2 run. The frozen reward answerer, judge, and text encoder are training components and are not needed at inference.
Method: rewarding evidence by what can be answered from it
Supervised training can teach plausible evidence boxes without making the answer depend on that evidence. Our method connects localisation to answerability during RL.
- Grounding SFT. Starting from Qwen3-VL-4B-Instruct, the policy learns a structured response: a modality tag, a
<vision>block containing up to six<evidence>items (each a short<concept>and<bbox>), followed by<think>and<answer>. Box coordinates are integers normalised to[0, 1000]. - Evidence-only view. The policy sees the full image and proposes boxes. For reward computation, duplicate boxes are removed and sides shorter than 100 coordinate units are expanded to that minimum. Each box is padded by 15% per side. Only those regions are retained on a black canvas, preserving their relative positions; the canvas is cropped to their joint extent and resized with a target minimum short side of 448 px and maximum long side of 896 px. No boxes means the full image is used.
- Frozen answerer. A separate Qwen3-VL-4B answerer is fine-tuned for one epoch on 18,155 grounding examples, half with full images and half with ground-truth evidence-only views, then frozen. It receives the question, the view, and a coordinate sentence. It receives neither the policy's concept text nor its reasoning or final answer.
- Blank control. The same answerer answers the same question and coordinate sentence with an all-black image of the same dimensions. Region credit is awarded only when the region answer is correct and the blank-image answer is incorrect.
- Policy optimisation. FIPO uses group-normalised rewards (GRPO advantages) and DAPO-style group filtering, with a PPO-style loss and token influence weights derived from discounted future policy log-ratios. RL uses 51,335 MediX-R1 imageโquestion pairs and answer labels; it requires no box annotations for those RL examples.
Reward
Let s be the binary answer scorer, f the structured-format check, and u the union area fraction of the scored boxes (1 for no boxes). The region term is
rho(u) = 1 - 0.5 * max(0, u - 0.25) / 0.75
r_region = f * s(region_answer) * (1 - s(blank_answer)) * rho(u)
r_acc = 0.5 * s(policy_answer) + 0.5 * r_region
R = 0.9 * (0.95 * r_acc + 0.05 * modality_correct) + 0.1 * f
Area has no cost below 25% coverage, and the region term retains half its area factor at full-image coverage. Together with the blank control and minimum box size, this avoids directly rewarding vanishing boxes. The policy's own answer is still rewarded from the full image.
Answer scoring (JEV). Normalised exact matches and recognised closed questions are handled by rules, including yes/no and two-option questions. Open answers use an AnyJev L0 correctness readout from Qwen/Qwen3-4B-Instruct-2507 and cosine similarity from abhinand/MedEmbed-large-v0.1. A logistic calibrator combines the judge logit and raw cosine, with a fixed decision threshold of 0.5. The calibration was fitted on 800 answers labelled by an LLM annotator, not clinicians; it measures reference agreement. This training scorer is separate from the benchmark judge below.
RL configuration. 200 steps; learning rate 1e-6; 512 prompts per training batch; five sampled responses per prompt at temperature 1; mini-batch 128; maximum response length 2,048 tokens. The vision tower is trainable. FIPO uses a 32-token discount half-life and influence-weight clipping of 0.2.
VQA accuracy
Accuracy (%) on the complete MedixEval five-task VLM panel, using the Qwen3-14B LLM judge. Every model and prompt mode covers all 11,630 questions. These are semantic judge scores, not exact-match scores or clinical adjudications. Baselines are Qwen3-VL-4B-Instruct and the MediX-R1-4B checkpoint in Shayan0179/Medix-R1.
no prompt
| Task | Questions | Qwen3-VL-4B-Instruct | MediX-R1-4B | MedVE-4B |
|---|---|---|---|---|
| SLAKE | 1,061 | 64.56 | 71.25 | 72.29 |
| VQA-RAD | 451 | 57.43 | 58.76 | 63.19 |
| PathVQA | 6,719 | 39.49 | 43.74 | 46.21 |
| PMC-VQA | 1,997 | 55.18 | 56.13 | 55.28 |
| PMC-VQA Hard | 1,402 | 31.03 | 30.17 | 31.53 |
| Macro average | 11,630 | 49.54 | 52.01 | 53.70 |
pv prompt
| Task | Questions | Qwen3-VL-4B-Instruct | MediX-R1-4B | MedVE-4B |
|---|---|---|---|---|
| SLAKE | 1,061 | 42.88 | 53.53 | 73.14 |
| VQA-RAD | 451 | 30.16 | 40.80 | 62.08 |
| PathVQA | 6,719 | 22.56 | 28.43 | 48.67 |
| PMC-VQA | 1,997 | 42.76 | 46.07 | 46.62 |
| PMC-VQA Hard | 1,402 | 19.61 | 21.04 | 35.02 |
| Macro average | 11,630 | 31.60 | 37.97 | 53.11 |
All three models use the same prompt mode and evaluation settings in each table. The pv comparison uses the shared evidence-format prompt below; it does not use a model-specific MediX-R1 prompt.
no: no system prompt; the image and question are supplied as a user message.pv: the system prompt requests a<vision>block with up to six conceptโbox pairs, then<think>and<answer>. The exact evaluated prompt is included inpv_system_prompt.txt. It does not explicitly request a modality tag, although the training format includes one.- Generation uses temperature 0, a 16,384-token context limit, a 2,048-token output budget for both modes, and an image cap of 4,194,304 pixels.
- Macro accuracy is the unweighted mean of the five task accuracies, not pooled accuracy over all questions. Results come from one evaluation run per prompt mode; uncertainty across seeds is not estimated.
evaluation_results.jsonpreserves the reported task values and sample counts for all three models.
Exact pv system prompt
You are a medical visual question answering assistant.
Emit exactly one <vision>...</vision> block before <think>. Put all evidence tags inside it. Emit </vision> once after the last evidence as the end of visual evidence.
Emit zero or more <evidence> tags, no more than 6. Each <evidence> tag wraps a short <concept>...</concept> and a <bbox>x1,y1,x2,y2</bbox> with integer coordinates normalized to [0, 1000] and x1 < x2, y1 < y2. Repeat the whole <evidence> tag for each pair.
Do not put multiple <bbox> tags in one <evidence> block, and do not add attributes or extra text inside tag names.
After </vision>, emit <think>...</think> and <answer>...</answer>, in that order. Output no text outside these tags.
Usage
Use a recent Transformers version supporting Qwen3-VL and the bundled processor configuration. The checkpoint was exported with Transformers 5.10.1. Install transformers, torch, accelerate, pillow, and huggingface_hub in your environment.
from pathlib import Path
from PIL import Image
from huggingface_hub import hf_hub_download
from transformers import AutoProcessor, Qwen3VLForConditionalGeneration
model_id = "erow/MedVE-4B"
model = Qwen3VLForConditionalGeneration.from_pretrained(
model_id, dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_id)
mode = "pv" # "no" omits the system message
messages = []
if mode == "pv":
prompt_file = hf_hub_download(model_id, "pv_system_prompt.txt")
messages.append({"role": "system", "content": Path(prompt_file).read_text()})
messages.append({
"role": "user",
"content": [
{"type": "image", "image": Image.open("medical_image.png").convert("RGB")},
{"type": "text", "text": "What abnormality is visible?"},
],
})
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
return_dict=True, return_tensors="pt",
processor_kwargs={"images_kwargs": {"max_pixels": 4194304}},
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
answer_ids = outputs[:, inputs["input_ids"].shape[1]:]
print(processor.batch_decode(answer_ids, skip_special_tokens=True)[0])
Intended use and limitations
This is a research model for medical VQA and visual evidence experiments. It has not been clinically validated and is not intended for diagnosis or treatment decisions. It can produce incorrect answers, unsupported reasoning, and inaccurate boxes.
The reward encourages regions that help a particular frozen answerer. It does not establish that the policy's final answer causally depends on its written evidence, nor that a box is clinically correct. The answerer can rely on question and coordinate priors, and the blank control only discounts the cases detected by that answerer and scorer. Questions the answerer cannot solve provide little localisation signal. Some questions need context outside a tight region.
The calibrated training judge and benchmark judge are automated text-based reference comparisons; both can accept incorrect answers or reject valid alternatives. Calibration labels were generated by an LLM on earlier policies, so calibration may drift as policy outputs change. VQA accuracy alone does not measure visual grounding or establish an advantage of the reward over a matched control.
Release details
- Backbone: Qwen3-VL-4B-Instruct; full BF16 weights, not an adapter.
- Training: grounding V4-SFT followed by region-answer-v2 RL (
focus2), step 200. - Reward settings: region weight 0.5, free area 0.25, area cost 0.5, minimum box side 100/1000, calibrated AnyJev v2 with closed-question rules.
- Base-model license: Apache 2.0.
- Method description follows the author's
paper/method.mddraft of 2026-11-13; the evaluation table uses the completed step-200 artifacts rather than that draft's preliminary step-30 results.
- Downloads last month
- 37