Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "bprice9/Palmyra-Medical-70B-32K-FP8"
5number_gpus = 2
6
7sampling_params = SamplingParams(temperature=0.0, top_p=0.9, max_tokens=512, stop_token_ids=[128001, 128009])
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11messages = [
12 {"role": "user", "content": "Give a differential for an intrahepatic lesion with early arterial phase enhancement and rapid washout."},
13]
14prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
15
16llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
17
18outputs = llm.generate(prompts, sampling_params)
19
20generated_text = outputs[0].outputs[0].text
21print(generated_text)1import torch
2from datasets import load_dataset
3from transformers import AutoTokenizer
4from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
5from llmcompressor.transformers.compression.helpers import (
6 calculate_offload_device_map,
7 custom_offload_device_map,
8)
9recipe = """
10quant_stage:
11 quant_modifiers:
12 QuantizationModifier:
13 ignore: ["lm_head"]
14 config_groups:
15 group_0:
16 weights:
17 num_bits: 8
18 type: float
19 strategy: tensor
20 dynamic: false
21 symmetric: true
22 input_activations:
23 num_bits: 8
24 type: float
25 strategy: tensor
26 dynamic: false
27 symmetric: true
28 targets: ["Linear"]
29"""
30model_stub = "Writer/Palmyra-Med-70B-32K"
31model_name = model_stub.split("/")[-1]
32device_map = calculate_offload_device_map(
33 model_stub, reserve_for_hessians=False, num_gpus=2, torch_dtype=torch.float16
34)
35model = SparseAutoModelForCausalLM.from_pretrained(
36 model_stub, torch_dtype=torch.float16, device_map=device_map
37)
38tokenizer = AutoTokenizer.from_pretrained(model_stub)
39output_dir = f"./{model_name}-FP8"
40DATASET_ID = "HuggingFaceH4/ultrachat_200k"
41DATASET_SPLIT = "train_sft"
42NUM_CALIBRATION_SAMPLES = 128
43MAX_SEQUENCE_LENGTH = 4096
44ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
45ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
46def preprocess(example):
47 return {
48 "text": tokenizer.apply_chat_template(
49 example["messages"],
50 tokenize=False,
51 )
52 }
53ds = ds.map(preprocess)
54def tokenize(sample):
55 return tokenizer(
56 sample["text"],
57 padding=False,
58 max_length=MAX_SEQUENCE_LENGTH,
59 truncation=True,
60 add_special_tokens=False,
61 )
62ds = ds.map(tokenize, remove_columns=ds.column_names)
63oneshot(
64 model=model,
65 output_dir=output_dir,
66 dataset=ds,
67 recipe=recipe,
68 max_seq_length=MAX_SEQUENCE_LENGTH,
69 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
70 save_compressed=True,
71)| Biomedical Benchmark | Med-PaLM-2 (5-shot) | GPT-4 | Palmyra-Med-70B (Original FP16) | Palmyra-Medical-70B-FP8 (This Model) |
| MMLU Clincal Knowledge | 88.3 | 86.0 | 90.9 | 90.2 |
| MMLU Medical Genetics | 90.0 | 91.0 | 94.0 | 93.0 |
| MMLU Anatomy | 77.8 | 80.0 | 83.7 | 83.7 |
| MMLU Professional Medicine | 95.2 | 93.0 | 92.7 | 92.3 |
| MMLU College Biology | 94.4 | 95.1 | 94.4 | 93.8 |
| MMLU College Medicine | 80.9 | 76.9 | 84.4 | 84.4 |
| MedQA 4-options | 79.9 | 78.9 | 78.6 | 79.5 |
| PubMed QA | 79.2 | 75.2 | 79.6 | 78.0 |
| MedMCQA | 71.3 | 69.5 | 74.4 | 75.7 |
| Average | 84.1 | 82.8 | 85.9 | 85.6 |
@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
}