MaziyarPanahi commited on
Commit
2699cb4
·
verified ·
1 Parent(s): c33d35a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +65 -6
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
- ## Quick Start
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  ```python
30
- from transformers import AutoModelForCausalLM, AutoProcessor
31
 
32
- model = AutoModelForCausalLM.from_pretrained(
33
- "OpenMed/Ministral-3B-MedVL",
34
- torch_dtype="auto", device_map="auto"
 
 
 
 
 
35
  )
36
- processor = AutoProcessor.from_pretrained("OpenMed/Ministral-3B-MedVL")
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