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+
- es
|
10 |
+
- th
|
11 |
+
pipeline_tag: text-generation
|
12 |
+
license: llama3.1
|
13 |
+
---
|
14 |
+
|
15 |
+
# Meta-Llama-3.1-70B-Instruct-quantized.w8a8
|
16 |
+
|
17 |
+
## Model Overview
|
18 |
+
- **Model Architecture:** Meta-Llama-3
|
19 |
+
- **Input:** Text
|
20 |
+
- **Output:** Text
|
21 |
+
- **Model Optimizations:**
|
22 |
+
- **Activation quantization:** INT8
|
23 |
+
- **Weight quantization:** INT8
|
24 |
+
- **Intended Use Cases:** Intended for commercial and research use multiple languages. Similarly to [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct), this models is intended for assistant-like chat.
|
25 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
|
26 |
+
- **Release Date:** 7/29/2024
|
27 |
+
- **Version:** 1.0
|
28 |
+
- **License(s):** [Llama3.1]
|
29 |
+
- **Model Developers:** Neural Magic
|
30 |
+
|
31 |
+
Quantized version of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
|
32 |
+
It achieves scores within 3% of the scores of the unquantized model for MMLU, ARC-Challenge, GSM-8k, Hellaswag, Winogrande and TruthfulQA.
|
33 |
+
|
34 |
+
### Model Optimizations
|
35 |
+
|
36 |
+
This model was obtained by quantizing the weights of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) to INT8 data type.
|
37 |
+
This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x).
|
38 |
+
Weight quantization also reduces disk size requirements by approximately 50%.
|
39 |
+
|
40 |
+
Only weights and activations of the linear operators within transformers blocks are quantized.
|
41 |
+
Weights are quantized with a symmetric static per-channel scheme, where a fixed linear scaling factor is applied between INT8 and floating point representations for each output channel dimension.
|
42 |
+
Activations are quantized with a symmetric dynamic per-token scheme, computing a linear scaling factor at runtime for each token between INT8 and floating point representations.
|
43 |
+
The [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization, as implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library.
|
44 |
+
GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
|
45 |
+
|
46 |
+
|
47 |
+
## Deployment
|
48 |
+
|
49 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
50 |
+
|
51 |
+
```python
|
52 |
+
from vllm import LLM, SamplingParams
|
53 |
+
from transformers import AutoTokenizer
|
54 |
+
|
55 |
+
model_id = "neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a8"
|
56 |
+
number_gpus = 2
|
57 |
+
max_model_len = 8192
|
58 |
+
|
59 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
|
60 |
+
|
61 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
62 |
+
|
63 |
+
messages = [
|
64 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
65 |
+
{"role": "user", "content": "Who are you?"},
|
66 |
+
]
|
67 |
+
|
68 |
+
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
69 |
+
|
70 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
|
71 |
+
|
72 |
+
outputs = llm.generate(prompts, sampling_params)
|
73 |
+
|
74 |
+
generated_text = outputs[0].outputs[0].text
|
75 |
+
print(generated_text)
|
76 |
+
```
|
77 |
+
|
78 |
+
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
79 |
+
|
80 |
+
|
81 |
+
## Creation
|
82 |
+
|
83 |
+
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
|
84 |
+
|
85 |
+
```python
|
86 |
+
from transformers import AutoTokenizer
|
87 |
+
from datasets import Dataset
|
88 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
89 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
90 |
+
import random
|
91 |
+
|
92 |
+
model_id = "meta-llama/Meta-Llama-3.1-70B-Instruct"
|
93 |
+
|
94 |
+
num_samples = 256
|
95 |
+
max_seq_len = 8192
|
96 |
+
|
97 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
98 |
+
|
99 |
+
def preprocess_fn(example):
|
100 |
+
return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
|
101 |
+
|
102 |
+
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
|
103 |
+
ds = ds.shuffle().select(range(num_samples))
|
104 |
+
ds = ds.map(preprocess_fn)
|
105 |
+
|
106 |
+
examples = [tokenizer(example["text"], padding=False, max_length=max_seq_len, truncation=True) for example in ds]
|
107 |
+
|
108 |
+
recipe = GPTQModifier(
|
109 |
+
targets="Linear",
|
110 |
+
scheme="W8A8",
|
111 |
+
ignore=["lm_head"],
|
112 |
+
dampening_frac=0.1,
|
113 |
+
)
|
114 |
+
|
115 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
116 |
+
model_id,
|
117 |
+
device_map="auto",
|
118 |
+
)
|
119 |
+
|
120 |
+
oneshot(
|
121 |
+
model=model,
|
122 |
+
dataset=ds,
|
123 |
+
recipe=recipe,
|
124 |
+
max_seq_length=max_seq_len,
|
125 |
+
num_calibration_samples=num_samples,
|
126 |
+
)
|
127 |
+
|
128 |
+
model.save_pretrained("Meta-Llama-3.1-70B-Instruct-quantized.w8a8")
|
129 |
+
```
|
130 |
+
|
131 |
+
|
132 |
+
## Evaluation
|
133 |
+
|
134 |
+
The model was evaluated on MMLU, ARC-Challenge, GSM-8K, Hellaswag, Winogrande and TruthfulQA.
|
135 |
+
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.
|
136 |
+
This version of the lm-evaluation-harness includes versions of ARC-Challenge and GSM-8K that match the prompting style of [Meta-Llama-3.1-Instruct-evals](https://huggingface.co/datasets/meta-llama/Meta-Llama-3.1-70B-Instruct-evals).
|
137 |
+
|
138 |
+
### Accuracy
|
139 |
+
|
140 |
+
#### Open LLM Leaderboard evaluation scores
|
141 |
+
<table>
|
142 |
+
<tr>
|
143 |
+
<td><strong>Benchmark</strong>
|
144 |
+
</td>
|
145 |
+
<td><strong>Meta-Llama-3.1-70B-Instruct </strong>
|
146 |
+
</td>
|
147 |
+
<td><strong>Meta-Llama-3.1-70B-Instruct-quantized.w8a8 (this model)</strong>
|
148 |
+
</td>
|
149 |
+
<td><strong>Recovery</strong>
|
150 |
+
</td>
|
151 |
+
</tr>
|
152 |
+
<tr>
|
153 |
+
<td>MMLU (5-shot)
|
154 |
+
</td>
|
155 |
+
<td>82.21
|
156 |
+
</td>
|
157 |
+
<td>79.91
|
158 |
+
</td>
|
159 |
+
<td>97.2%
|
160 |
+
</td>
|
161 |
+
</tr>
|
162 |
+
<tr>
|
163 |
+
<td>ARC Challenge (0-shot)
|
164 |
+
</td>
|
165 |
+
<td>95.05
|
166 |
+
</td>
|
167 |
+
<td>93.09
|
168 |
+
</td>
|
169 |
+
<td>97.9%
|
170 |
+
</td>
|
171 |
+
</tr>
|
172 |
+
<tr>
|
173 |
+
<td>GSM-8K (CoT, 8-shot, strict-match)
|
174 |
+
</td>
|
175 |
+
<td>93.10
|
176 |
+
</td>
|
177 |
+
<td>93.18
|
178 |
+
</td>
|
179 |
+
<td>100.1%
|
180 |
+
</td>
|
181 |
+
</tr>
|
182 |
+
<tr>
|
183 |
+
<td>Hellaswag (10-shot)
|
184 |
+
</td>
|
185 |
+
<td>86.40
|
186 |
+
</td>
|
187 |
+
<td>85.46
|
188 |
+
</td>
|
189 |
+
<td>98.9%
|
190 |
+
</td>
|
191 |
+
</tr>
|
192 |
+
<tr>
|
193 |
+
<td>Winogrande (5-shot)
|
194 |
+
</td>
|
195 |
+
<td>85.00
|
196 |
+
</td>
|
197 |
+
<td>85.24
|
198 |
+
</td>
|
199 |
+
<td>100.3%
|
200 |
+
</td>
|
201 |
+
</tr>
|
202 |
+
<tr>
|
203 |
+
<td>TruthfulQA (0-shot)
|
204 |
+
</td>
|
205 |
+
<td>59.83
|
206 |
+
</td>
|
207 |
+
<td>58.55
|
208 |
+
</td>
|
209 |
+
<td>97.9%
|
210 |
+
</td>
|
211 |
+
</tr>
|
212 |
+
<tr>
|
213 |
+
<td><strong>Average</strong>
|
214 |
+
</td>
|
215 |
+
<td><strong>83.60</strong>
|
216 |
+
</td>
|
217 |
+
<td><strong>82.57</strong>
|
218 |
+
</td>
|
219 |
+
<td><strong>98.8%</strong>
|
220 |
+
</td>
|
221 |
+
</tr>
|
222 |
+
</table>
|