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