Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -24,16 +24,75 @@ Ministral-3B fine-tuned on ~200K medical VQA records from the SynthVision pipeli
|
|
| 24 |
| **Fine-tuned** | **0.4789** | **0.3669** | **0.5664** | **0.4708** |
|
| 25 |
| Delta | +1.9% | +13.2% | +14.5% | +9.6% |
|
| 26 |
|
| 27 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
```python
|
| 30 |
-
from
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
-
|
| 37 |
```
|
| 38 |
|
| 39 |
## Training Details
|
|
|
|
| 24 |
| **Fine-tuned** | **0.4789** | **0.3669** | **0.5664** | **0.4708** |
|
| 25 |
| Delta | +1.9% | +13.2% | +14.5% | +9.6% |
|
| 26 |
|
| 27 |
+
## Usage
|
| 28 |
+
|
| 29 |
+
### Transformers
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 33 |
+
|
| 34 |
+
model_id = "OpenMed/Ministral-3B-MedVL"
|
| 35 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 36 |
+
model = AutoModelForImageTextToText.from_pretrained(model_id, torch_dtype="auto", device_map="auto")
|
| 37 |
+
|
| 38 |
+
messages = [
|
| 39 |
+
{
|
| 40 |
+
"role": "user",
|
| 41 |
+
"content": [
|
| 42 |
+
{"type": "image", "url": "https://example.com/xray.jpg"},
|
| 43 |
+
{"type": "text", "text": "What are the key findings in this chest X-ray?"},
|
| 44 |
+
],
|
| 45 |
+
}
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
inputs = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt").to(model.device)
|
| 49 |
+
output = model.generate(**inputs, max_new_tokens=512)
|
| 50 |
+
print(processor.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
### vLLM
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
from vllm import LLM, SamplingParams
|
| 57 |
+
|
| 58 |
+
llm = LLM(
|
| 59 |
+
model="OpenMed/Ministral-3B-MedVL",
|
| 60 |
+
tokenizer_mode="mistral",
|
| 61 |
+
config_format="mistral",
|
| 62 |
+
load_format="mistral",
|
| 63 |
+
max_model_len=4096,
|
| 64 |
+
limit_mm_per_prompt={"image": 1},
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
messages = [{"role": "user", "content": [
|
| 68 |
+
{"type": "image_url", "image_url": {"url": "https://example.com/xray.jpg"}},
|
| 69 |
+
{"type": "text", "text": "What are the key findings in this chest X-ray?"},
|
| 70 |
+
]}]
|
| 71 |
+
|
| 72 |
+
output = llm.chat(messages, SamplingParams(temperature=0, max_tokens=512))
|
| 73 |
+
print(output[0].outputs[0].text)
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
### SGLang
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
# Launch server
|
| 80 |
+
python -m sglang.launch_server --model-path OpenMed/Ministral-3B-MedVL --port 8000
|
| 81 |
+
```
|
| 82 |
|
| 83 |
```python
|
| 84 |
+
from openai import OpenAI
|
| 85 |
|
| 86 |
+
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
|
| 87 |
+
response = client.chat.completions.create(
|
| 88 |
+
model="OpenMed/Ministral-3B-MedVL",
|
| 89 |
+
messages=[{"role": "user", "content": [
|
| 90 |
+
{"type": "image_url", "image_url": {"url": "https://example.com/xray.jpg"}},
|
| 91 |
+
{"type": "text", "text": "What are the key findings in this chest X-ray?"},
|
| 92 |
+
]}],
|
| 93 |
+
max_tokens=512,
|
| 94 |
)
|
| 95 |
+
print(response.choices[0].message.content)
|
| 96 |
```
|
| 97 |
|
| 98 |
## Training Details
|