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ingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE
|
7 |
+
language:
|
8 |
+
- en
|
9 |
+
---
|
10 |
+
|
11 |
+
# Meta-Llama-3.1-70B-Instruct-FP8-dynamic
|
12 |
+
|
13 |
+
## Model Overview
|
14 |
+
- **Model Architecture:** Meta-Llama-3.1
|
15 |
+
- **Input:** Text
|
16 |
+
- **Output:** Text
|
17 |
+
- **Model Optimizations:**
|
18 |
+
- **Weight quantization:** FP8
|
19 |
+
- **Activation quantization:** FP8
|
20 |
+
- **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct), this models is intended for assistant-like chat.
|
21 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
|
22 |
+
- **Release Date:** 7/23/2024
|
23 |
+
- **Version:** 1.0
|
24 |
+
- **License(s):** [llama3.1](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE)
|
25 |
+
- **Model Developers:** Neural Magic
|
26 |
+
|
27 |
+
Quantized version of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
|
28 |
+
It achieves an average score of 78.69 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 78.67.
|
29 |
+
|
30 |
+
### Model Optimizations
|
31 |
+
|
32 |
+
This model was obtained by quantizing the weights and activations of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) to FP8 data type, ready for inference with vLLM built from source.
|
33 |
+
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
|
34 |
+
|
35 |
+
Only the weights and activations of the linear operators within transformers blocks are quantized. Symmetric per-channel quantization is applied, in which a linear scaling per output dimension maps the FP8 representations of the quantized weights and activations. Activations are also quantized on a per-token dynamic basis.
|
36 |
+
[LLM Compressor](https://github.com/vllm-project/llm-compressor) is used for quantization with 512 sequences of UltraChat.
|
37 |
+
|
38 |
+
## Deployment
|
39 |
+
|
40 |
+
### Use with vLLM
|
41 |
+
|
42 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
43 |
+
|
44 |
+
```python
|
45 |
+
from vllm import LLM, SamplingParams
|
46 |
+
from transformers import AutoTokenizer
|
47 |
+
|
48 |
+
model_id = "neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8-dynamic"
|
49 |
+
number_gpus = 2
|
50 |
+
|
51 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
|
52 |
+
|
53 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
54 |
+
|
55 |
+
messages = [
|
56 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
57 |
+
{"role": "user", "content": "Who are you?"},
|
58 |
+
]
|
59 |
+
|
60 |
+
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
61 |
+
|
62 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
|
63 |
+
|
64 |
+
outputs = llm.generate(prompts, sampling_params)
|
65 |
+
|
66 |
+
generated_text = outputs[0].outputs[0].text
|
67 |
+
print(generated_text)
|
68 |
+
```
|
69 |
+
|
70 |
+
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
71 |
+
|
72 |
+
## Creation
|
73 |
+
|
74 |
+
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 snipet below.
|
75 |
+
|
76 |
+
```python
|
77 |
+
import torch
|
78 |
+
|
79 |
+
from transformers import AutoTokenizer
|
80 |
+
|
81 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
82 |
+
from llmcompressor.transformers.compression.helpers import ( # noqa
|
83 |
+
calculate_offload_device_map,
|
84 |
+
custom_offload_device_map,
|
85 |
+
)
|
86 |
+
|
87 |
+
recipe = """
|
88 |
+
quant_stage:
|
89 |
+
quant_modifiers:
|
90 |
+
QuantizationModifier:
|
91 |
+
ignore: ["lm_head"]
|
92 |
+
config_groups:
|
93 |
+
group_0:
|
94 |
+
weights:
|
95 |
+
num_bits: 8
|
96 |
+
type: float
|
97 |
+
strategy: channel
|
98 |
+
dynamic: false
|
99 |
+
symmetric: true
|
100 |
+
input_activations:
|
101 |
+
num_bits: 8
|
102 |
+
type: float
|
103 |
+
strategy: token
|
104 |
+
dynamic: true
|
105 |
+
symmetric: true
|
106 |
+
targets: ["Linear"]
|
107 |
+
"""
|
108 |
+
|
109 |
+
model_stub = "meta-llama/Meta-Llama-3.1-70B-Instruct"
|
110 |
+
model_name = model_stub.split("/")[-1]
|
111 |
+
|
112 |
+
device_map = calculate_offload_device_map(
|
113 |
+
model_stub, reserve_for_hessians=False, num_gpus=2, torch_dtype=torch.float16
|
114 |
+
)
|
115 |
+
|
116 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
117 |
+
model_stub, torch_dtype=torch.float16, device_map=device_map
|
118 |
+
)
|
119 |
+
|
120 |
+
output_dir = f"./{model_name}-FP8-dynamic"
|
121 |
+
|
122 |
+
oneshot(
|
123 |
+
model=model,
|
124 |
+
recipe=recipe,
|
125 |
+
output_dir=output_dir,
|
126 |
+
save_compressed=True,
|
127 |
+
tokenizer=AutoTokenizer.from_pretrained(model_stub),
|
128 |
+
)
|
129 |
+
```
|
130 |
+
|
131 |
+
## Evaluation
|
132 |
+
|
133 |
+
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) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
|
134 |
+
```
|
135 |
+
lm_eval \
|
136 |
+
--model vllm \
|
137 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8-dynamic",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
|
138 |
+
--tasks openllm \
|
139 |
+
--batch_size auto
|
140 |
+
```
|
141 |
+
|
142 |
+
### Accuracy
|
143 |
+
|
144 |
+
#### Open LLM Leaderboard evaluation scores
|
145 |
+
<table>
|
146 |
+
<tr>
|
147 |
+
<td><strong>Benchmark</strong>
|
148 |
+
</td>
|
149 |
+
<td><strong>Meta-Llama-3.1-70B-Instruct </strong>
|
150 |
+
</td>
|
151 |
+
<td><strong>Meta-Llama-3.1-70B-Instruct-FP8-dynamic(this model)</strong>
|
152 |
+
</td>
|
153 |
+
<td><strong>Recovery</strong>
|
154 |
+
</td>
|
155 |
+
</tr>
|
156 |
+
<tr>
|
157 |
+
<td>MMLU (5-shot)
|
158 |
+
</td>
|
159 |
+
<td>82.21
|
160 |
+
</td>
|
161 |
+
<td>82.13
|
162 |
+
</td>
|
163 |
+
<td>99.90%
|
164 |
+
</td>
|
165 |
+
</tr>
|
166 |
+
<tr>
|
167 |
+
<td>ARC Challenge (25-shot)
|
168 |
+
</td>
|
169 |
+
<td>70.65
|
170 |
+
</td>
|
171 |
+
<td>70.31
|
172 |
+
</td>
|
173 |
+
<td>99.52%
|
174 |
+
</td>
|
175 |
+
</tr>
|
176 |
+
<tr>
|
177 |
+
<td>GSM-8K (5-shot, strict-match)
|
178 |
+
</td>
|
179 |
+
<td>87.95
|
180 |
+
</td>
|
181 |
+
<td>88.40
|
182 |
+
</td>
|
183 |
+
<td>100.5%
|
184 |
+
</td>
|
185 |
+
</tr>
|
186 |
+
<tr>
|
187 |
+
<td>Hellaswag (10-shot)
|
188 |
+
</td>
|
189 |
+
<td>86.33
|
190 |
+
</td>
|
191 |
+
<td>86.27
|
192 |
+
</td>
|
193 |
+
<td>99.93%
|
194 |
+
</td>
|
195 |
+
</tr>
|
196 |
+
<tr>
|
197 |
+
<td>Winogrande (5-shot)
|
198 |
+
</td>
|
199 |
+
<td>85.00
|
200 |
+
</td>
|
201 |
+
<td>85.00
|
202 |
+
</td>
|
203 |
+
<td>100.0%
|
204 |
+
</td>
|
205 |
+
</tr>
|
206 |
+
<tr>
|
207 |
+
<td>TruthfulQA (0-shot)
|
208 |
+
</td>
|
209 |
+
<td>59.90
|
210 |
+
</td>
|
211 |
+
<td>60.01
|
212 |
+
</td>
|
213 |
+
<td>100.1%
|
214 |
+
</td>
|
215 |
+
</tr>
|
216 |
+
<tr>
|
217 |
+
<td><strong>Average</strong>
|
218 |
+
</td>
|
219 |
+
<td><strong>78.67</strong>
|
220 |
+
</td>
|
221 |
+
<td><strong>78.69</strong>
|
222 |
+
</td>
|
223 |
+
<td><strong>100.0%</strong>
|
224 |
+
</td>
|
225 |
+
</tr>
|
226 |
+
</table>
|