Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,305 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
2 |
license: other
|
3 |
license_name: writer-open-model-license
|
4 |
license_link: https://writer.com/legal/open-model-license/
|
|
|
|
|
5 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
tags:
|
3 |
+
- fp8
|
4 |
+
- vllm
|
5 |
+
- medical
|
6 |
+
- med
|
7 |
license: other
|
8 |
license_name: writer-open-model-license
|
9 |
license_link: https://writer.com/legal/open-model-license/
|
10 |
+
language:
|
11 |
+
- en
|
12 |
---
|
13 |
+
|
14 |
+
# Palmyra-Med-70B-FP8
|
15 |
+
This is a quantized version of [Palmyra-Med-70B](https://huggingface.co/Writer/Palmyra-Med-70B), which was developed by Writer.
|
16 |
+
|
17 |
+
The original model performance on biomedical benchmarks is 85.87%.
|
18 |
+
**This quantized version acheives an average score of 85.62%.**
|
19 |
+
|
20 |
+
## Model Overview:
|
21 |
+
- **Model:** Llama based model finetuned to form Palmyra-X-004 and then again to form Palmyra-Med-70B.
|
22 |
+
- **Input:** Text
|
23 |
+
- **Output:** Text
|
24 |
+
- **Model Optimizations:**
|
25 |
+
- **Weight quantization:** FP8
|
26 |
+
- **Activation quantization:** FP8
|
27 |
+
- **Intended Use Cases:** Palmyra-Med-70B is intended for non-commercial and research use in English. Instruction tuned models are intended for assistant-like chat, whereas pretrained models can be adapted for a variety of natural language generation tasks.
|
28 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
|
29 |
+
- **License(s):** [writer-open-model-license](https://writer.com/legal/open-model-license/)
|
30 |
+
|
31 |
+
### Writer Resources and Technical Documentation:
|
32 |
+
+ [Writer Blog](https://writer.com/blog/palmyra-med-fin-models/)
|
33 |
+
+ [Writer Developer Website](https://dev.writer.com/home/models)
|
34 |
+
+ [Writer AI Studio](https://writer.com/product/ai-studio/)
|
35 |
+
+ [Palmyra Model API](https://dev.writer.com/api-guides/chat-completion)
|
36 |
+
|
37 |
+
### Model Optimizations
|
38 |
+
|
39 |
+
[LLM_Compressor](https://github.com/vllm-project/llm-compressor) library.
|
40 |
+
Using this optimization, the original FP16 weights and linear activations within the transformer blocks are adjusted to FP8, which decreases the model size and VRAM requirements by 50% overall.
|
41 |
+
|
42 |
+
## Deployment with vLLM
|
43 |
+
|
44 |
+
This model can be deployed using the [vLLM](https://docs.vllm.ai/en/latest/) library, as shown in the example below.
|
45 |
+
|
46 |
+
```python
|
47 |
+
from vllm import LLM, SamplingParams
|
48 |
+
from transformers import AutoTokenizer
|
49 |
+
|
50 |
+
model_id = "bprice9/Palmyra-Med-70B-FP8"
|
51 |
+
number_gpus = 2
|
52 |
+
|
53 |
+
sampling_params = SamplingParams(temperature=0.5, top_p=0.9, max_tokens=512, stop_token_ids=[128001, 128009])
|
54 |
+
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
56 |
+
|
57 |
+
messages = [
|
58 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
59 |
+
{"role": "user", "content": "Who are you?"},
|
60 |
+
]
|
61 |
+
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
62 |
+
|
63 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
|
64 |
+
|
65 |
+
outputs = llm.generate(prompts, sampling_params)
|
66 |
+
|
67 |
+
generated_text = outputs[0].outputs[0].text
|
68 |
+
print(generated_text)
|
69 |
+
```
|
70 |
+
|
71 |
+
## Creation
|
72 |
+
|
73 |
+
This model was created by applying [LLM Compressor with calibration samples from UltraChat](https://github.com/vllm-project/llm-compressor/blob/sa/big_model_support/examples/big_model_offloading/big_model_w8a8_calibrate.py), as presented in the code below.
|
74 |
+
|
75 |
+
```python
|
76 |
+
import torch
|
77 |
+
from datasets import load_dataset
|
78 |
+
from transformers import AutoTokenizer
|
79 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
80 |
+
from llmcompressor.transformers.compression.helpers import (
|
81 |
+
calculate_offload_device_map,
|
82 |
+
custom_offload_device_map,
|
83 |
+
)
|
84 |
+
recipe = """
|
85 |
+
quant_stage:
|
86 |
+
quant_modifiers:
|
87 |
+
QuantizationModifier:
|
88 |
+
ignore: ["lm_head"]
|
89 |
+
config_groups:
|
90 |
+
group_0:
|
91 |
+
weights:
|
92 |
+
num_bits: 8
|
93 |
+
type: float
|
94 |
+
strategy: tensor
|
95 |
+
dynamic: false
|
96 |
+
symmetric: true
|
97 |
+
input_activations:
|
98 |
+
num_bits: 8
|
99 |
+
type: float
|
100 |
+
strategy: tensor
|
101 |
+
dynamic: false
|
102 |
+
symmetric: true
|
103 |
+
targets: ["Linear"]
|
104 |
+
"""
|
105 |
+
model_stub = "Writer/Palmyra-Med-70B"
|
106 |
+
model_name = model_stub.split("/")[-1]
|
107 |
+
device_map = calculate_offload_device_map(
|
108 |
+
model_stub, reserve_for_hessians=False, num_gpus=2, torch_dtype=torch.float16
|
109 |
+
)
|
110 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
111 |
+
model_stub, torch_dtype=torch.float16, device_map=device_map
|
112 |
+
)
|
113 |
+
tokenizer = AutoTokenizer.from_pretrained(model_stub)
|
114 |
+
output_dir = f"./{model_name}-FP8"
|
115 |
+
DATASET_ID = "HuggingFaceH4/ultrachat_200k"
|
116 |
+
DATASET_SPLIT = "train_sft"
|
117 |
+
NUM_CALIBRATION_SAMPLES = 128
|
118 |
+
MAX_SEQUENCE_LENGTH = 4096
|
119 |
+
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
|
120 |
+
ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
|
121 |
+
def preprocess(example):
|
122 |
+
return {
|
123 |
+
"text": tokenizer.apply_chat_template(
|
124 |
+
example["messages"],
|
125 |
+
tokenize=False,
|
126 |
+
)
|
127 |
+
}
|
128 |
+
ds = ds.map(preprocess)
|
129 |
+
def tokenize(sample):
|
130 |
+
return tokenizer(
|
131 |
+
sample["text"],
|
132 |
+
padding=False,
|
133 |
+
max_length=MAX_SEQUENCE_LENGTH,
|
134 |
+
truncation=True,
|
135 |
+
add_special_tokens=False,
|
136 |
+
)
|
137 |
+
ds = ds.map(tokenize, remove_columns=ds.column_names)
|
138 |
+
oneshot(
|
139 |
+
model=model,
|
140 |
+
output_dir=output_dir,
|
141 |
+
dataset=ds,
|
142 |
+
recipe=recipe,
|
143 |
+
max_seq_length=MAX_SEQUENCE_LENGTH,
|
144 |
+
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
|
145 |
+
save_compressed=True,
|
146 |
+
)
|
147 |
+
```
|
148 |
+
|
149 |
+
## Evaluation
|
150 |
+
|
151 |
+
<table>
|
152 |
+
<tr>
|
153 |
+
<td style="width: 20%;"><strong>Biomedical Benchmark</strong>
|
154 |
+
</td>
|
155 |
+
<td style="width: 20%;"><strong>Med-PaLM-2 (5-shot)</strong>
|
156 |
+
</td>
|
157 |
+
<td style="width: 20%;"><strong>GPT-4</strong>
|
158 |
+
</td>
|
159 |
+
<td style="width: 20%;"><strong>Palmyra-Med-70B (Original FP16)</strong>
|
160 |
+
</td>
|
161 |
+
<td style="width: 20%;"><strong>Palmyra-Med-70B-FP8 (This Model)</strong>
|
162 |
+
</td>
|
163 |
+
</tr>
|
164 |
+
<tr>
|
165 |
+
<td>MMLU Clincal Knowledge
|
166 |
+
</td>
|
167 |
+
<td>88.3
|
168 |
+
</td>
|
169 |
+
<td>86.0
|
170 |
+
</td>
|
171 |
+
<td>90.9
|
172 |
+
</td>
|
173 |
+
<td>90.2
|
174 |
+
</td>
|
175 |
+
</tr>
|
176 |
+
<tr>
|
177 |
+
<td>MMLU Medical Genetics
|
178 |
+
</td>
|
179 |
+
<td>90.0
|
180 |
+
</td>
|
181 |
+
<td>91.0
|
182 |
+
</td>
|
183 |
+
<td>94.0
|
184 |
+
</td>
|
185 |
+
<td>93.0
|
186 |
+
</td>
|
187 |
+
</tr>
|
188 |
+
<tr>
|
189 |
+
<td>MMLU Anatomy
|
190 |
+
</td>
|
191 |
+
<td>77.8
|
192 |
+
</td>
|
193 |
+
<td>80.0
|
194 |
+
</td>
|
195 |
+
<td>83.7
|
196 |
+
</td>
|
197 |
+
<td>83.7
|
198 |
+
</td>
|
199 |
+
</tr>
|
200 |
+
<tr>
|
201 |
+
<td>MMLU Professional Medicine
|
202 |
+
</td>
|
203 |
+
<td>95.2
|
204 |
+
</td>
|
205 |
+
<td>93.0
|
206 |
+
</td>
|
207 |
+
<td>92.7
|
208 |
+
</td>
|
209 |
+
<td>92.3
|
210 |
+
</td>
|
211 |
+
</tr>
|
212 |
+
<tr>
|
213 |
+
<td>MMLU College Biology
|
214 |
+
</td>
|
215 |
+
<td>94.4
|
216 |
+
</td>
|
217 |
+
<td>95.1
|
218 |
+
</td>
|
219 |
+
<td>94.4
|
220 |
+
</td>
|
221 |
+
<td>93.8
|
222 |
+
</td>
|
223 |
+
</tr>
|
224 |
+
<tr>
|
225 |
+
<td>MMLU College Medicine
|
226 |
+
</td>
|
227 |
+
<td>80.9
|
228 |
+
</td>
|
229 |
+
<td>76.9
|
230 |
+
</td>
|
231 |
+
<td>84.4
|
232 |
+
</td>
|
233 |
+
<td>84.4
|
234 |
+
</td>
|
235 |
+
</tr>
|
236 |
+
<tr>
|
237 |
+
<td>MedQA 4-options
|
238 |
+
</td>
|
239 |
+
<td>79.9
|
240 |
+
</td>
|
241 |
+
<td>78.9
|
242 |
+
</td>
|
243 |
+
<td>78.6
|
244 |
+
</td>
|
245 |
+
<td>79.5
|
246 |
+
</td>
|
247 |
+
</tr>
|
248 |
+
<tr>
|
249 |
+
<td>PubMed QA
|
250 |
+
</td>
|
251 |
+
<td>79.2
|
252 |
+
</td>
|
253 |
+
<td>75.2
|
254 |
+
</td>
|
255 |
+
<td>79.6
|
256 |
+
</td>
|
257 |
+
<td>78.0
|
258 |
+
</td>
|
259 |
+
</tr>
|
260 |
+
<tr>
|
261 |
+
<tr>
|
262 |
+
<td>MedMCQA
|
263 |
+
</td>
|
264 |
+
<td>71.3
|
265 |
+
</td>
|
266 |
+
<td>69.5
|
267 |
+
</td>
|
268 |
+
<td>74.4
|
269 |
+
</td>
|
270 |
+
<td>75.7
|
271 |
+
</td>
|
272 |
+
</tr>
|
273 |
+
<tr>
|
274 |
+
<td><strong>Average</strong>
|
275 |
+
</td>
|
276 |
+
<td><strong>84.1</strong>
|
277 |
+
</td>
|
278 |
+
<td><strong>82.8</strong>
|
279 |
+
</td>
|
280 |
+
<td><strong>85.9</strong>
|
281 |
+
</td>
|
282 |
+
<td><strong>85.6</strong>
|
283 |
+
</td>
|
284 |
+
</tr>
|
285 |
+
</table>
|
286 |
+
|
287 |
+
### Citation and Related Information Provided by Writer
|
288 |
+
|
289 |
+
To cite this model:
|
290 |
+
|
291 |
+
```
|
292 |
+
@misc{Palmyra-Med-70B,
|
293 |
+
author = {Writer Engineering team},
|
294 |
+
title = {{Palmyra-Med-70b: A powerful LLM designed for healthcare}},
|
295 |
+
howpublished = {\url{https://dev.writer.com}},
|
296 |
+
year = 2024,
|
297 |
+
month = June
|
298 |
+
}
|
299 |
+
```
|
300 |
+
|
301 |
+
|
302 |
+
|
303 |
+
|
304 |
+
|
305 |
+
|