Update README.md
Browse files
README.md
CHANGED
|
@@ -1,61 +1,266 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
-
|
| 7 |
-
|
| 8 |
-
- generated_from_trainer
|
| 9 |
-
model-index:
|
| 10 |
-
- name: Qwen3-VL-8B-Instruct
|
| 11 |
-
results: []
|
| 12 |
---
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
should probably proofread and complete it, then remove this comment. -->
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
##
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
-
|
| 40 |
-
|
| 41 |
-
- seed: 42
|
| 42 |
-
- distributed_type: multi-GPU
|
| 43 |
-
- num_devices: 8
|
| 44 |
-
- gradient_accumulation_steps: 64
|
| 45 |
-
- total_train_batch_size: 512
|
| 46 |
-
- total_eval_batch_size: 64
|
| 47 |
-
- optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
|
| 48 |
-
- lr_scheduler_type: cosine
|
| 49 |
-
- lr_scheduler_warmup_steps: 0.1
|
| 50 |
-
- num_epochs: 1.0
|
| 51 |
|
| 52 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- Qwen/Qwen3-VL-8B-Instruct
|
| 7 |
+
pipeline_tag: image-text-to-text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
+
# OctoMed-8B Model Card
|
| 10 |
|
| 11 |
+
## OctoMed-8B
|
|
|
|
| 12 |
|
| 13 |
+
OctoMed-8B is a high-performance multimodal medical reasoning model created through large-scale data curation and supervised fine-tuning (SFT). To support reliable clinical reasoning, we developed a scalable data pipeline that distills structured reasoning traces from DeepSeek-R1 and GPT-4o and produced the largest multimodal medical reasoning dataset to date with more than 8 million traces and 6.8 billion response tokens.
|
| 14 |
|
| 15 |
+
Using Qwen3-VL-8B-Instruct as the base model, OctoMed-8B is trained on this curated corpus and achieves strong, robust performance on a wide range of out-of-distribution medical benchmarks.
|
| 16 |
|
| 17 |
+
OctoMed-8B produces internal reasoning traces in `<think>...</think>` tokens before writing out its final answer. In general, the model has a tendency to think longer for harder or ill-defined questions, while sticking to shorter reasoning traces for easier queries.
|
| 18 |
|
| 19 |
+
## Requirements
|
| 20 |
|
| 21 |
+
We recommend installing the transformers version used in our experiments and other dependencies with this command:
|
| 22 |
|
| 23 |
+
```bash
|
| 24 |
+
pip install transformers==4.57.1 accelerate==1.12.0 torchvision==0.24.1 qwen-vl-utils==0.0.14
|
| 25 |
+
```
|
| 26 |
|
| 27 |
+
## Quickstart
|
| 28 |
|
| 29 |
+
### Inference with HF Transformers 🤗
|
| 30 |
|
| 31 |
+
Here we show a code snippet to show you how chat with OctoMed-8B using `transformers` and `qwen_vl_utils`:
|
| 32 |
|
| 33 |
+
```python
|
| 34 |
+
import torch
|
| 35 |
+
from transformers import Qwen3VLForConditionalGeneration, AutoTokenizer, AutoProcessor
|
| 36 |
+
from qwen_vl_utils import process_vision_info
|
| 37 |
|
| 38 |
+
# default: Load the model on the available device(s)
|
| 39 |
+
model = Qwen3VLForConditionalGeneration.from_pretrained(
|
| 40 |
+
"OctoMed/OctoMed-8B", dtype=torch.bfloat16, device_map="auto"
|
| 41 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
|
| 44 |
+
# model = Qwen3VLForConditionalGeneration.from_pretrained(
|
| 45 |
+
# "OctoMed/OctoMed-8B",
|
| 46 |
+
# dtype=torch.bfloat16,
|
| 47 |
+
# attn_implementation="flash_attention_2",
|
| 48 |
+
# device_map="auto",
|
| 49 |
+
# )
|
| 50 |
|
| 51 |
+
# The default range for the number of visual tokens per image in the model is 4-16384.
|
| 52 |
+
# You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.
|
| 53 |
+
min_pixels = 262144
|
| 54 |
+
max_pixels = 262144
|
| 55 |
+
processor = AutoProcessor.from_pretrained("OctoMed/OctoMed-8B", min_pixels=min_pixels, max_pixels=max_pixels)
|
| 56 |
|
| 57 |
+
# Text-Only Query
|
| 58 |
+
# messages = [
|
| 59 |
+
# {
|
| 60 |
+
# "role": "user",
|
| 61 |
+
# "content": [
|
| 62 |
+
# {"type": "text", "text": "I've had a persistent dry cough for two weeks but no fever. Could this be allergies, and when should I see a doctor?"},
|
| 63 |
+
# ],
|
| 64 |
+
# }
|
| 65 |
+
# ]
|
| 66 |
|
| 67 |
+
# General Query
|
| 68 |
+
# messages = [
|
| 69 |
+
# {
|
| 70 |
+
# "role": "user",
|
| 71 |
+
# "content": [
|
| 72 |
+
# {
|
| 73 |
+
# "type": "image",
|
| 74 |
+
# "image": "https://cdn.ncbi.nlm.nih.gov/pmc/blobs/51b2/10835941/13323b55fbb5/13256_2024_4349_Fig1_HTML.jpg",
|
| 75 |
+
# },
|
| 76 |
+
# {"type": "text", "text": "Describe this image."},
|
| 77 |
+
# ],
|
| 78 |
+
# }
|
| 79 |
+
# ]
|
| 80 |
|
| 81 |
+
# Multiple Choice Query
|
| 82 |
+
messages = [
|
| 83 |
+
{
|
| 84 |
+
"role": "user",
|
| 85 |
+
"content": [
|
| 86 |
+
{
|
| 87 |
+
"type": "image",
|
| 88 |
+
"image": "https://cdn.ncbi.nlm.nih.gov/pmc/blobs/51b2/10835941/13323b55fbb5/13256_2024_4349_Fig1_HTML.jpg",
|
| 89 |
+
},
|
| 90 |
+
{"type": "text", "text": "What orientation was the MRI in image B taken in?\nA. Axial\nB. Coronal\nC. Sagittal\nD. Oblique\n\nPlease reason step-by-step, and put your final answer within \\boxed{}."},
|
| 91 |
+
],
|
| 92 |
+
}
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
# Preparation for inference
|
| 96 |
+
text = processor.apply_chat_template(
|
| 97 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 98 |
+
)
|
| 99 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 100 |
+
inputs = processor(
|
| 101 |
+
text=[text],
|
| 102 |
+
images=image_inputs,
|
| 103 |
+
videos=video_inputs,
|
| 104 |
+
padding=True,
|
| 105 |
+
return_tensors="pt",
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
inputs = inputs.to(device="cuda")
|
| 109 |
+
|
| 110 |
+
# Inference: Generation of the output
|
| 111 |
+
generated_ids = model.generate(**inputs, max_new_tokens=8192)
|
| 112 |
+
generated_ids_trimmed = [
|
| 113 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 114 |
+
]
|
| 115 |
+
output_text = processor.batch_decode(
|
| 116 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 117 |
+
)
|
| 118 |
+
print(output_text)
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
### Inference with vLLM
|
| 122 |
+
|
| 123 |
+
Here we show an example of how to use OctoMed with vLLM (tested with vLLM==0.11.2 and transformers==4.57.1):
|
| 124 |
+
|
| 125 |
+
```python
|
| 126 |
+
from vllm import LLM, SamplingParams
|
| 127 |
+
from transformers import AutoProcessor
|
| 128 |
+
|
| 129 |
+
min_pixels = 262144
|
| 130 |
+
max_pixels = 262144
|
| 131 |
+
processor = AutoProcessor.from_pretrained("OctoMed/OctoMed-8B", min_pixels=min_pixels, max_pixels=max_pixels)
|
| 132 |
+
|
| 133 |
+
llm = LLM(
|
| 134 |
+
model="OctoMed/OctoMed-8B",
|
| 135 |
+
trust_remote_code=True,
|
| 136 |
+
dtype="bfloat16",
|
| 137 |
+
max_model_len=8192,
|
| 138 |
+
tensor_parallel_size=4,
|
| 139 |
+
gpu_memory_utilization=0.8,
|
| 140 |
+
limit_mm_per_prompt={"image": 1}
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
# Set up sampling parameters
|
| 144 |
+
sampling_params = SamplingParams(
|
| 145 |
+
temperature=0.6,
|
| 146 |
+
top_p=0.95,
|
| 147 |
+
max_tokens=8192,
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
image_data = []
|
| 151 |
+
|
| 152 |
+
# Text-Only Query
|
| 153 |
+
messages = [
|
| 154 |
+
{
|
| 155 |
+
"role": "user",
|
| 156 |
+
"content": [
|
| 157 |
+
{"type": "text", "text": "Explain the difference between type 1 and type 2 diabetes."},
|
| 158 |
+
],
|
| 159 |
+
}
|
| 160 |
+
]
|
| 161 |
+
|
| 162 |
+
# General Query
|
| 163 |
+
# image_data = ['https://cdn.ncbi.nlm.nih.gov/pmc/blobs/51b2/10835941/13323b55fbb5/13256_2024_4349_Fig1_HTML.jpg']
|
| 164 |
+
# messages = [
|
| 165 |
+
# {
|
| 166 |
+
# "role": "user",
|
| 167 |
+
# "content": [
|
| 168 |
+
# {
|
| 169 |
+
# "type": "image",
|
| 170 |
+
# "image": image_data[0],
|
| 171 |
+
# },
|
| 172 |
+
# {"type": "text", "text": "Describe this image."},
|
| 173 |
+
# ],
|
| 174 |
+
# }
|
| 175 |
+
# ]
|
| 176 |
+
|
| 177 |
+
# Multiple Choice Query
|
| 178 |
+
# image_data = ['https://cdn.ncbi.nlm.nih.gov/pmc/blobs/51b2/10835941/13323b55fbb5/13256_2024_4349_Fig1_HTML.jpg']
|
| 179 |
+
# messages = [
|
| 180 |
+
# {
|
| 181 |
+
# "role": "user",
|
| 182 |
+
# "content": [
|
| 183 |
+
# {
|
| 184 |
+
# "type": "image",
|
| 185 |
+
# "image": image_data[0],
|
| 186 |
+
# },
|
| 187 |
+
# {"type": "text", "text": "What orientation was the MRI in image B taken in?\nA. Axial\nB. Coronal\nC. Sagittal\nD. Oblique\n\nPlease reason step-by-step, and put your final answer within \\boxed{}."},
|
| 188 |
+
# ],
|
| 189 |
+
# }
|
| 190 |
+
# ]
|
| 191 |
+
|
| 192 |
+
prompt = processor.apply_chat_template(
|
| 193 |
+
messages, tokenize=False, add_generation_prompt=True)
|
| 194 |
+
|
| 195 |
+
if image_data:
|
| 196 |
+
mm_prompt = {
|
| 197 |
+
"prompt": prompt,
|
| 198 |
+
"multi_modal_data": {"image": image_data}
|
| 199 |
+
}
|
| 200 |
+
else:
|
| 201 |
+
mm_prompt = {"prompt": prompt}
|
| 202 |
+
|
| 203 |
+
# Generate response
|
| 204 |
+
outputs = llm.generate([mm_prompt], sampling_params)
|
| 205 |
+
|
| 206 |
+
# Print the generated response
|
| 207 |
+
for output in outputs:
|
| 208 |
+
prompt = output.prompt
|
| 209 |
+
generated_text = output.outputs[0].text
|
| 210 |
+
print(f"Prompt: {prompt}")
|
| 211 |
+
print(f"Generated text: {generated_text}")
|
| 212 |
+
print("-" * 50)
|
| 213 |
+
```
|
| 214 |
+
|
| 215 |
+
### Suggested Hyperparameters
|
| 216 |
+
|
| 217 |
+
We suggest using the same settings used in evaluation to reproduce results:
|
| 218 |
+
|
| 219 |
+
Format multiple choice questions with the following template:
|
| 220 |
+
|
| 221 |
+
```
|
| 222 |
+
{optional image(s)}
|
| 223 |
+
{question}
|
| 224 |
+
{options, 1 on each line}
|
| 225 |
+
|
| 226 |
+
Please reason step-by-step, and put your final answer within \boxed{}.
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
Example Prompt:
|
| 230 |
+
|
| 231 |
+
```
|
| 232 |
+
{image(s)}
|
| 233 |
+
What orientation was the MRI in image B taken in?
|
| 234 |
+
A: Axial
|
| 235 |
+
B: Coronal
|
| 236 |
+
C: Sagittal
|
| 237 |
+
D: Oblique
|
| 238 |
+
|
| 239 |
+
Please reason step-by-step, and put your final answer within \boxed{}.
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
- Use the default system prompt ("You are a helpful assistant.")
|
| 243 |
+
- Extract the answer by looking at the content within the last `\boxed{}`.
|
| 244 |
+
- Temperature of 0.6
|
| 245 |
+
- Top-p of 0.95
|
| 246 |
+
- min_pixels = 262144
|
| 247 |
+
- max_pixels = 262144
|
| 248 |
+
|
| 249 |
+
### Known Issues
|
| 250 |
+
|
| 251 |
+
- The model is finetuned for multiple-choice VQA. The model may follow instructions for other tasks but is not extensively tested or post-trained to do so.
|
| 252 |
+
|
| 253 |
+
We hope to address these concerns moving forward in future iterations!
|
| 254 |
+
|
| 255 |
+
## Citation
|
| 256 |
+
|
| 257 |
+
If you find our work helpful, feel free to give us a cite.
|
| 258 |
+
|
| 259 |
+
```bibtex
|
| 260 |
+
@article{ossowski2025octomed,
|
| 261 |
+
title={OctoMed: Data Recipes for State-of-the-Art Multimodal Medical Reasoning},
|
| 262 |
+
author={Ossowski, Timothy and Zhang, Sheng and Liu, Qianchu and Qin, Guanghui and Tan, Reuben and Naumann, Tristan and Hu, Junjie and Poon, Hoifung},
|
| 263 |
+
journal={arXiv preprint arXiv:2511.23269},
|
| 264 |
+
year={2025}
|
| 265 |
+
}
|
| 266 |
+
```
|