Update README.md
Browse files
README.md
CHANGED
@@ -7,19 +7,66 @@ tags:
|
|
7 |
# Phi-3-mini-128k-instruct-FP8
|
8 |
|
9 |
## Model Overview
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
Phi-3-mini-128k-instruct
|
16 |
-
|
17 |
-
Reduces space on disk by ~50%.
|
18 |
-
Part of the [FP8 LLMs for vLLM collection](https://huggingface.co/collections/neuralmagic/fp8-llms-for-vllm-666742ed2b78b7ac8df13127).
|
19 |
|
|
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
```python
|
25 |
from datasets import load_dataset
|
@@ -46,63 +93,99 @@ model.quantize(examples)
|
|
46 |
model.save_quantized(quantized_model_dir)
|
47 |
```
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
```bash
|
52 |
-
#!/bin/bash
|
53 |
-
|
54 |
-
# Example usage:
|
55 |
-
# CUDA_VISIBLE_DEVICES=0 ./eval_openllm.sh "neuralmagic/Phi-3-mini-128k-instruct-FP8" "tensor_parallel_size=1,max_model_len=4096,add_bos_token=True,gpu_memory_utilization=0.7"
|
56 |
-
|
57 |
-
export MODEL_DIR=${1}
|
58 |
-
export MODEL_ARGS=${2}
|
59 |
-
|
60 |
-
declare -A tasks_fewshot=(
|
61 |
-
["arc_challenge"]=25
|
62 |
-
["winogrande"]=5
|
63 |
-
["truthfulqa_mc2"]=0
|
64 |
-
["hellaswag"]=10
|
65 |
-
["mmlu"]=5
|
66 |
-
["gsm8k"]=5
|
67 |
-
)
|
68 |
-
|
69 |
-
declare -A batch_sizes=(
|
70 |
-
["arc_challenge"]="auto"
|
71 |
-
["winogrande"]="auto"
|
72 |
-
["truthfulqa_mc2"]="auto"
|
73 |
-
["hellaswag"]="auto"
|
74 |
-
["mmlu"]=1
|
75 |
-
["gsm8k"]="auto"
|
76 |
-
)
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
--write_out \
|
86 |
-
--show_config \
|
87 |
-
--device cuda \
|
88 |
-
--batch_size ${BATCH_SIZE} \
|
89 |
-
--output_path="results/${TASK}"
|
90 |
-
done
|
91 |
```
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Phi-3-mini-128k-instruct-FP8
|
8 |
|
9 |
## Model Overview
|
10 |
+
- **Model Architecture:** Phi-3
|
11 |
+
- **Input:** Text
|
12 |
+
- **Output:** Text
|
13 |
+
- **Model Optimizations:**
|
14 |
+
- **Weight quantization:** FP8
|
15 |
+
- **Activation quantization:** FP8
|
16 |
+
- **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct), this models is intended for assistant-like chat.
|
17 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
|
18 |
+
- **Release Date:** 6/29/2024
|
19 |
+
- **Version:** 1.0
|
20 |
+
- **Model Developers:** Neural Magic
|
21 |
|
22 |
+
Quantized version of [Phi-3-mini-128k-instruct](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct).
|
23 |
+
It achieves an average score of 68.99 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 69.13.
|
|
|
|
|
24 |
|
25 |
+
### Model Optimizations
|
26 |
|
27 |
+
This model was obtained by quantizing the weights and activations of [Phi-3-mini-128k-instruct](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) to FP8 data type, ready for inference with vLLM >= 0.5.1.
|
28 |
+
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
|
29 |
+
|
30 |
+
Only the weights and activations of the linear operators within transformers blocks are quantized. Symmetric per-tensor quantization is applied, in which a linear scaling per output dimension maps the FP8 representations of the quantized weights and activations.
|
31 |
+
[AutoFP8](https://github.com/neuralmagic/AutoFP8) is used for quantization with 512 sequences of UltraChat.
|
32 |
+
|
33 |
+
## Deployment
|
34 |
+
|
35 |
+
### Use with vLLM
|
36 |
+
|
37 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
38 |
+
|
39 |
+
```python
|
40 |
+
from vllm import LLM, SamplingParams
|
41 |
+
from transformers import AutoTokenizer
|
42 |
+
|
43 |
+
model_id = "neuralmagic/Phi-3-mini-128k-instruct-FP8"
|
44 |
+
|
45 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
|
46 |
+
|
47 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
48 |
+
|
49 |
+
messages = [
|
50 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
51 |
+
{"role": "user", "content": "Who are you?"},
|
52 |
+
]
|
53 |
+
|
54 |
+
prompts = tokenizer.apply_chat_template(messages, tokenize=False)
|
55 |
+
|
56 |
+
llm = LLM(model=model_id)
|
57 |
+
|
58 |
+
outputs = llm.generate(prompts, sampling_params)
|
59 |
+
|
60 |
+
generated_text = outputs[0].outputs[0].text
|
61 |
+
print(generated_text)
|
62 |
+
```
|
63 |
+
|
64 |
+
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
65 |
+
|
66 |
+
## Creation
|
67 |
+
|
68 |
+
This model was created by applying [AutoFP8 with calibration samples from ultrachat](https://github.com/neuralmagic/AutoFP8/blob/147fa4d9e1a90ef8a93f96fc7d9c33056ddc017a/example_dataset.py), as presented in the code snipet below.
|
69 |
+
Although AutoFP8 was used for this particular model, Neural Magic is transitioning to using [llm-compressor](https://github.com/vllm-project/llm-compressor) which supports several quantization schemes and models not supported by AutoFP8.
|
70 |
|
71 |
```python
|
72 |
from datasets import load_dataset
|
|
|
93 |
model.save_quantized(quantized_model_dir)
|
94 |
```
|
95 |
|
96 |
+
## Evaluation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
The model was evaluated on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) leaderboard tasks (version 1) with the [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness/tree/383bbd54bc621086e05aa1b030d8d4d5635b25e6) (commit 383bbd54bc621086e05aa1b030d8d4d5635b25e6) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
|
99 |
+
```
|
100 |
+
lm_eval \
|
101 |
+
--model vllm \
|
102 |
+
--model_args pretrained="neuralmagic/Phi-3-mini-128k-instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
|
103 |
+
--tasks openllm \
|
104 |
+
--batch_size auto
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
```
|
106 |
|
107 |
+
### Accuracy
|
108 |
+
|
109 |
+
#### Open LLM Leaderboard evaluation scores
|
110 |
+
<table>
|
111 |
+
<tr>
|
112 |
+
<td><strong>Benchmark</strong>
|
113 |
+
</td>
|
114 |
+
<td><strong>Phi-3-mini-128k-instruct</strong>
|
115 |
+
</td>
|
116 |
+
<td><strong>Phi-3-mini-128k-instruct-FP8(this model)</strong>
|
117 |
+
</td>
|
118 |
+
<td><strong>Recovery</strong>
|
119 |
+
</td>
|
120 |
+
</tr>
|
121 |
+
<tr>
|
122 |
+
<td>MMLU (5-shot)
|
123 |
+
</td>
|
124 |
+
<td>68.10
|
125 |
+
</td>
|
126 |
+
<td>67.93
|
127 |
+
</td>
|
128 |
+
<td>99.75%
|
129 |
+
</td>
|
130 |
+
</tr>
|
131 |
+
<tr>
|
132 |
+
<td>ARC Challenge (25-shot)
|
133 |
+
</td>
|
134 |
+
<td>63.65
|
135 |
+
</td>
|
136 |
+
<td>64.24
|
137 |
+
</td>
|
138 |
+
<td>100.9%
|
139 |
+
</td>
|
140 |
+
</tr>
|
141 |
+
<tr>
|
142 |
+
<td>GSM-8K (5-shot, strict-match)
|
143 |
+
</td>
|
144 |
+
<td>75.59
|
145 |
+
</td>
|
146 |
+
<td>74.37
|
147 |
+
</td>
|
148 |
+
<td>98.38%
|
149 |
+
</td>
|
150 |
+
</tr>
|
151 |
+
<tr>
|
152 |
+
<td>Hellaswag (10-shot)
|
153 |
+
</td>
|
154 |
+
<td>79.76
|
155 |
+
</td>
|
156 |
+
<td>79.79
|
157 |
+
</td>
|
158 |
+
<td>100.0%
|
159 |
+
</td>
|
160 |
+
</tr>
|
161 |
+
<tr>
|
162 |
+
<td>Winogrande (5-shot)
|
163 |
+
</td>
|
164 |
+
<td>73.72
|
165 |
+
</td>
|
166 |
+
<td>74.11
|
167 |
+
</td>
|
168 |
+
<td>100.5%
|
169 |
+
</td>
|
170 |
+
</tr>
|
171 |
+
<tr>
|
172 |
+
<td>TruthfulQA (0-shot)
|
173 |
+
</td>
|
174 |
+
<td>53.97
|
175 |
+
</td>
|
176 |
+
<td>53.50
|
177 |
+
</td>
|
178 |
+
<td>99.12%
|
179 |
+
</td>
|
180 |
+
</tr>
|
181 |
+
<tr>
|
182 |
+
<td><strong>Average</strong>
|
183 |
+
</td>
|
184 |
+
<td><strong>69.13</strong>
|
185 |
+
</td>
|
186 |
+
<td><strong>68.99</strong>
|
187 |
+
</td>
|
188 |
+
<td><strong>99.80%</strong>
|
189 |
+
</td>
|
190 |
+
</tr>
|
191 |
+
</table>
|