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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- fp8
|
4 |
+
- vllm
|
5 |
+
license: llama3.1
|
6 |
+
license_link: https://huggingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE
|
7 |
+
language:
|
8 |
+
- en
|
9 |
+
---
|
10 |
+
|
11 |
+
# Meta-Llama-3.1-70B-FP8
|
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 multiple languages. Similarly to [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B), this model serves as a base version.
|
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](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B).
|
28 |
+
It achieves an average score of 79.70 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 79.84.
|
29 |
+
|
30 |
+
### Model Optimizations
|
31 |
+
|
32 |
+
This model was obtained by quantizing the weights and activations of [Meta-Llama-3.1-70B](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B) 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-tensor quantization is applied, in which a single linear scaling maps the FP8 representations of the quantized weights and activations.
|
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-FP8"
|
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 |
+
from datasets import load_dataset
|
79 |
+
from transformers import AutoTokenizer
|
80 |
+
|
81 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
82 |
+
from llmcompressor.transformers.compression.helpers import (
|
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: tensor
|
98 |
+
dynamic: false
|
99 |
+
symmetric: true
|
100 |
+
input_activations:
|
101 |
+
num_bits: 8
|
102 |
+
type: float
|
103 |
+
strategy: tensor
|
104 |
+
dynamic: false
|
105 |
+
symmetric: true
|
106 |
+
targets: ["Linear"]
|
107 |
+
"""
|
108 |
+
|
109 |
+
model_stub = "meta-llama/Meta-Llama-3.1-70B"
|
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 |
+
tokenizer = AutoTokenizer.from_pretrained(model_stub)
|
120 |
+
|
121 |
+
output_dir = f"./{model_name}-FP8"
|
122 |
+
|
123 |
+
DATASET_ID = "HuggingFaceH4/ultrachat_200k"
|
124 |
+
DATASET_SPLIT = "train_sft"
|
125 |
+
NUM_CALIBRATION_SAMPLES = 512
|
126 |
+
MAX_SEQUENCE_LENGTH = 4096
|
127 |
+
|
128 |
+
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
|
129 |
+
ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
|
130 |
+
|
131 |
+
def preprocess(example):
|
132 |
+
return {
|
133 |
+
"text": tokenizer.apply_chat_template(
|
134 |
+
example["messages"],
|
135 |
+
tokenize=False,
|
136 |
+
)
|
137 |
+
}
|
138 |
+
|
139 |
+
ds = ds.map(preprocess)
|
140 |
+
|
141 |
+
def tokenize(sample):
|
142 |
+
return tokenizer(
|
143 |
+
sample["text"],
|
144 |
+
padding=False,
|
145 |
+
max_length=MAX_SEQUENCE_LENGTH,
|
146 |
+
truncation=True,
|
147 |
+
add_special_tokens=False,
|
148 |
+
)
|
149 |
+
|
150 |
+
ds = ds.map(tokenize, remove_columns=ds.column_names)
|
151 |
+
|
152 |
+
oneshot(
|
153 |
+
model=model,
|
154 |
+
output_dir=output_dir,
|
155 |
+
dataset=ds,
|
156 |
+
recipe=recipe,
|
157 |
+
max_seq_length=MAX_SEQUENCE_LENGTH,
|
158 |
+
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
|
159 |
+
save_compressed=True,
|
160 |
+
)
|
161 |
+
```
|
162 |
+
|
163 |
+
## Evaluation
|
164 |
+
|
165 |
+
The model was evaluated on MMLU, ARC-Challenge, GSM-8K, Hellaswag, Winogrande and TruthfulQA.
|
166 |
+
Evaluation was conducted using the Neural Magic fork of [lm-evaluation-harness](https://github.com/neuralmagic/lm-evaluation-harness/tree/llama_3.1_instruct) (branch llama_3.1_instruct) and the [vLLM](https://docs.vllm.ai/en/stable/) engine.
|
167 |
+
This version of the lm-evaluation-harness includes versions of ARC-Challenge that matches the prompting style of [Meta-Llama-3.1-evals](https://huggingface.co/datasets/meta-llama/Meta-Llama-3.1-8B-evals).
|
168 |
+
|
169 |
+
### Accuracy
|
170 |
+
|
171 |
+
#### Open LLM Leaderboard evaluation scores
|
172 |
+
<table>
|
173 |
+
<tr>
|
174 |
+
<td><strong>Benchmark</strong>
|
175 |
+
</td>
|
176 |
+
<td><strong>Meta-Llama-3.1-70B </strong>
|
177 |
+
</td>
|
178 |
+
<td><strong>Meta-Llama-3.1-70B-FP8(this model)</strong>
|
179 |
+
</td>
|
180 |
+
<td><strong>Recovery</strong>
|
181 |
+
</td>
|
182 |
+
</tr>
|
183 |
+
<tr>
|
184 |
+
<td>MMLU (5-shot)
|
185 |
+
</td>
|
186 |
+
<td>78.81
|
187 |
+
</td>
|
188 |
+
<td>78.85
|
189 |
+
</td>
|
190 |
+
<td>100.0%
|
191 |
+
</td>
|
192 |
+
</tr>
|
193 |
+
<tr>
|
194 |
+
<td>ARC Challenge (0-shot)
|
195 |
+
</td>
|
196 |
+
<td>93.43
|
197 |
+
</td>
|
198 |
+
<td>93.43
|
199 |
+
</td>
|
200 |
+
<td>100.0%
|
201 |
+
</td>
|
202 |
+
</tr>
|
203 |
+
<tr>
|
204 |
+
<td>GSM-8K (5-shot, strict-match)
|
205 |
+
</td>
|
206 |
+
<td>81.88
|
207 |
+
</td>
|
208 |
+
<td>81.35
|
209 |
+
</td>
|
210 |
+
<td>99.35%
|
211 |
+
</td>
|
212 |
+
</tr>
|
213 |
+
<tr>
|
214 |
+
<td>Hellaswag (10-shot)
|
215 |
+
</td>
|
216 |
+
<td>87.98
|
217 |
+
</td>
|
218 |
+
<td>87.82
|
219 |
+
</td>
|
220 |
+
<td>99.82%
|
221 |
+
</td>
|
222 |
+
</tr>
|
223 |
+
<tr>
|
224 |
+
<td>Winogrande (5-shot)
|
225 |
+
</td>
|
226 |
+
<td>85.78
|
227 |
+
</td>
|
228 |
+
<td>85.87
|
229 |
+
</td>
|
230 |
+
<td>100.1%
|
231 |
+
</td>
|
232 |
+
</tr>
|
233 |
+
<tr>
|
234 |
+
<td>TruthfulQA (0-shot)
|
235 |
+
</td>
|
236 |
+
<td>51.18
|
237 |
+
</td>
|
238 |
+
<td>50.90
|
239 |
+
</td>
|
240 |
+
<td>99.45%
|
241 |
+
</td>
|
242 |
+
</tr>
|
243 |
+
<tr>
|
244 |
+
<td><strong>Average</strong>
|
245 |
+
</td>
|
246 |
+
<td><strong>79.84</strong>
|
247 |
+
</td>
|
248 |
+
<td><strong>79.70</strong>
|
249 |
+
</td>
|
250 |
+
<td><strong>99.82%</strong>
|
251 |
+
</td>
|
252 |
+
</tr>
|
253 |
+
</table>
|
254 |
+
|
255 |
+
### Reproduction
|
256 |
+
|
257 |
+
The results were obtained using the following commands:
|
258 |
+
|
259 |
+
#### MMLU
|
260 |
+
```
|
261 |
+
lm_eval \
|
262 |
+
--model vllm \
|
263 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-FP8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
|
264 |
+
--tasks mmlu \
|
265 |
+
--num_fewshot 5 \
|
266 |
+
--batch_size auto
|
267 |
+
```
|
268 |
+
|
269 |
+
#### ARC-Challenge
|
270 |
+
```
|
271 |
+
lm_eval \
|
272 |
+
--model vllm \
|
273 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-FP8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
|
274 |
+
--tasks arc_challenge_llama_3.1_instruct \
|
275 |
+
--num_fewshot 25 \
|
276 |
+
--batch_size auto
|
277 |
+
```
|
278 |
+
|
279 |
+
#### GSM-8K
|
280 |
+
```
|
281 |
+
lm_eval \
|
282 |
+
--model vllm \
|
283 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-FP8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
|
284 |
+
--tasks gsm8k \
|
285 |
+
--num_fewshot 5 \
|
286 |
+
--batch_size auto
|
287 |
+
```
|
288 |
+
|
289 |
+
#### Hellaswag
|
290 |
+
```
|
291 |
+
lm_eval \
|
292 |
+
--model vllm \
|
293 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-FP8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
|
294 |
+
--tasks hellaswag \
|
295 |
+
--num_fewshot 10 \
|
296 |
+
--batch_size auto
|
297 |
+
```
|
298 |
+
|
299 |
+
#### Winogrande
|
300 |
+
```
|
301 |
+
lm_eval \
|
302 |
+
--model vllm \
|
303 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-FP8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
|
304 |
+
--tasks winogrande \
|
305 |
+
--num_fewshot 5 \
|
306 |
+
--batch_size auto
|
307 |
+
```
|
308 |
+
|
309 |
+
#### TruthfulQA
|
310 |
+
```
|
311 |
+
lm_eval \
|
312 |
+
--model vllm \
|
313 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-FP8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
|
314 |
+
--tasks truthfulqa_mc \
|
315 |
+
--num_fewshot 0 \
|
316 |
+
--batch_size auto
|
317 |
+
```
|