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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: llama3.2
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
- de
|
6 |
+
- fr
|
7 |
+
- it
|
8 |
+
- pt
|
9 |
+
- hi
|
10 |
+
- es
|
11 |
+
- th
|
12 |
+
pipeline_tag: text-generation
|
13 |
+
tags:
|
14 |
+
- llama
|
15 |
+
- llama-3
|
16 |
+
- neuralmagic
|
17 |
+
- llmcompressor
|
18 |
+
---
|
19 |
+
|
20 |
+
# Llama-3.2-1B-Instruct-quantized.w8a8
|
21 |
+
|
22 |
+
## Model Overview
|
23 |
+
- **Model Architecture:** Llama-3
|
24 |
+
- **Input:** Text
|
25 |
+
- **Output:** Text
|
26 |
+
- **Model Optimizations:**
|
27 |
+
- **Activation quantization:** INT8
|
28 |
+
- **Weight quantization:** INT8
|
29 |
+
- **Intended Use Cases:** Intended for commercial and research use multiple languages. Similarly to [Llama-3.2-1B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct), this models is intended for assistant-like chat.
|
30 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
|
31 |
+
- **Release Date:** 9/25/2024
|
32 |
+
- **Version:** 1.0
|
33 |
+
- **License(s):** Llama3.2
|
34 |
+
- **Model Developers:** Neural Magic
|
35 |
+
|
36 |
+
Quantized version of [Llama-3.2-1B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct).
|
37 |
+
It achieves scores within 1.3% of the scores of the unquantized model for MMLU, ARC-Challenge, GSM-8k, Hellaswag, Winogrande and TruthfulQA.
|
38 |
+
|
39 |
+
### Model Optimizations
|
40 |
+
|
41 |
+
This model was obtained by quantizing the weights of [Llama-3.2-1B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct) to INT8 data type.
|
42 |
+
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).
|
43 |
+
Weight quantization also reduces disk size requirements by approximately 50%.
|
44 |
+
|
45 |
+
Only weights and activations of the linear operators within transformers blocks are quantized.
|
46 |
+
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.
|
47 |
+
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.
|
48 |
+
Linear scaling factors are computed via by minimizing the mean squarred error (MSE).
|
49 |
+
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.
|
50 |
+
GPTQ used a 1% damping factor and 512 sequences sequences taken from Neural Magic's [LLM compression calibration dataset](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
|
51 |
+
|
52 |
+
## Deployment
|
53 |
+
|
54 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
55 |
+
|
56 |
+
```python
|
57 |
+
from vllm import LLM, SamplingParams
|
58 |
+
from transformers import AutoTokenizer
|
59 |
+
|
60 |
+
model_id = "neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8"
|
61 |
+
number_gpus = 1
|
62 |
+
max_model_len = 8192
|
63 |
+
|
64 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
|
65 |
+
|
66 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
67 |
+
|
68 |
+
messages = [
|
69 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
70 |
+
{"role": "user", "content": "Who are you?"},
|
71 |
+
]
|
72 |
+
|
73 |
+
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
74 |
+
|
75 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
|
76 |
+
|
77 |
+
outputs = llm.generate(prompts, sampling_params)
|
78 |
+
|
79 |
+
generated_text = outputs[0].outputs[0].text
|
80 |
+
print(generated_text)
|
81 |
+
```
|
82 |
+
|
83 |
+
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
84 |
+
|
85 |
+
|
86 |
+
## Creation
|
87 |
+
|
88 |
+
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
|
89 |
+
|
90 |
+
```python
|
91 |
+
from transformers import AutoTokenizer
|
92 |
+
from datasets import load_dataset
|
93 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
94 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
95 |
+
|
96 |
+
model_id = "meta-llama/Llama-3.2-1B-Instruct"
|
97 |
+
|
98 |
+
num_samples = 512
|
99 |
+
max_seq_len = 8192
|
100 |
+
|
101 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
102 |
+
|
103 |
+
def preprocess_fn(example):
|
104 |
+
return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
|
105 |
+
|
106 |
+
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
|
107 |
+
ds = ds.shuffle().select(range(num_samples))
|
108 |
+
ds = ds.map(preprocess_fn)
|
109 |
+
|
110 |
+
recipe = GPTQModifier(
|
111 |
+
use_sequential=True,
|
112 |
+
targets="Linear",
|
113 |
+
scheme="W8A8",
|
114 |
+
ignore=["lm_head"],
|
115 |
+
dampening_frac=0.01,
|
116 |
+
observer="mse",
|
117 |
+
)
|
118 |
+
|
119 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
120 |
+
model_id,
|
121 |
+
device_map="auto",
|
122 |
+
)
|
123 |
+
|
124 |
+
oneshot(
|
125 |
+
model=model,
|
126 |
+
dataset=ds,
|
127 |
+
recipe=recipe,
|
128 |
+
max_seq_length=max_seq_len,
|
129 |
+
num_calibration_samples=num_samples,
|
130 |
+
)
|
131 |
+
|
132 |
+
model.save_pretrained("Llama-3.2-1B-Instruct-quantized.w8a8")
|
133 |
+
```
|
134 |
+
|
135 |
+
|
136 |
+
## Evaluation
|
137 |
+
|
138 |
+
The model was evaluated on MMLU, ARC-Challenge, GSM-8K, Hellaswag, Winogrande and TruthfulQA.
|
139 |
+
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.
|
140 |
+
This version of the lm-evaluation-harness includes versions of MMLU, 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-8B-Instruct-evals).
|
141 |
+
|
142 |
+
### Accuracy
|
143 |
+
|
144 |
+
#### Open LLM Leaderboard evaluation scores
|
145 |
+
<table>
|
146 |
+
<tr>
|
147 |
+
<td><strong>Benchmark</strong>
|
148 |
+
</td>
|
149 |
+
<td><strong>Llama-3.2-1B-Instruct </strong>
|
150 |
+
</td>
|
151 |
+
<td><strong>Llama-3.2-1B-Instruct-quantized.w8a8 (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>47.66
|
160 |
+
</td>
|
161 |
+
<td>47.95
|
162 |
+
</td>
|
163 |
+
<td>100.6%
|
164 |
+
</td>
|
165 |
+
</tr>
|
166 |
+
<tr>
|
167 |
+
<td>MMLU (CoT, 0-shot)
|
168 |
+
</td>
|
169 |
+
<td>47.10
|
170 |
+
</td>
|
171 |
+
<td>44.63
|
172 |
+
</td>
|
173 |
+
<td>94.8%
|
174 |
+
</td>
|
175 |
+
</tr>
|
176 |
+
<tr>
|
177 |
+
<td>ARC Challenge (0-shot)
|
178 |
+
</td>
|
179 |
+
<td>58.36
|
180 |
+
</td>
|
181 |
+
<td>56.14
|
182 |
+
</td>
|
183 |
+
<td>96.2%
|
184 |
+
</td>
|
185 |
+
</tr>
|
186 |
+
<tr>
|
187 |
+
<td>GSM-8K (CoT, 8-shot, strict-match)
|
188 |
+
</td>
|
189 |
+
<td>45.72
|
190 |
+
</td>
|
191 |
+
<td>46.70
|
192 |
+
</td>
|
193 |
+
<td>102.2%
|
194 |
+
</td>
|
195 |
+
</tr>
|
196 |
+
<tr>
|
197 |
+
<td>Hellaswag (10-shot)
|
198 |
+
</td>
|
199 |
+
<td>61.01
|
200 |
+
</td>
|
201 |
+
<td>60.95
|
202 |
+
</td>
|
203 |
+
<td>99.9%
|
204 |
+
</td>
|
205 |
+
</tr>
|
206 |
+
<tr>
|
207 |
+
<td>Winogrande (5-shot)
|
208 |
+
</td>
|
209 |
+
<td>62.27
|
210 |
+
</td>
|
211 |
+
<td>61.33
|
212 |
+
</td>
|
213 |
+
<td>98.5%
|
214 |
+
</td>
|
215 |
+
</tr>
|
216 |
+
<tr>
|
217 |
+
<td>TruthfulQA (0-shot, mc2)
|
218 |
+
</td>
|
219 |
+
<td>43.52
|
220 |
+
</td>
|
221 |
+
<td>42.84
|
222 |
+
</td>
|
223 |
+
<td>98.4%
|
224 |
+
</td>
|
225 |
+
</tr>
|
226 |
+
<tr>
|
227 |
+
<td><strong>Average</strong>
|
228 |
+
</td>
|
229 |
+
<td><strong>52.24</strong>
|
230 |
+
</td>
|
231 |
+
<td><strong>51.51</strong>
|
232 |
+
</td>
|
233 |
+
<td><strong>98.7%</strong>
|
234 |
+
</td>
|
235 |
+
</tr>
|
236 |
+
</table>
|
237 |
+
|
238 |
+
### Reproduction
|
239 |
+
|
240 |
+
The results were obtained using the following commands:
|
241 |
+
|
242 |
+
#### MMLU
|
243 |
+
```
|
244 |
+
lm_eval \
|
245 |
+
--model vllm \
|
246 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
|
247 |
+
--tasks mmlu_llama_3.1_instruct \
|
248 |
+
--fewshot_as_multiturn \
|
249 |
+
--apply_chat_template \
|
250 |
+
--num_fewshot 5 \
|
251 |
+
--batch_size auto
|
252 |
+
```
|
253 |
+
|
254 |
+
#### MMLU-CoT
|
255 |
+
```
|
256 |
+
lm_eval \
|
257 |
+
--model vllm \
|
258 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4064,max_gen_toks=1024,tensor_parallel_size=1 \
|
259 |
+
--tasks mmlu_cot_0shot_llama_3.1_instruct \
|
260 |
+
--apply_chat_template \
|
261 |
+
--num_fewshot 0 \
|
262 |
+
--batch_size auto
|
263 |
+
```
|
264 |
+
|
265 |
+
#### ARC-Challenge
|
266 |
+
```
|
267 |
+
lm_eval \
|
268 |
+
--model vllm \
|
269 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=3940,max_gen_toks=100,tensor_parallel_size=1 \
|
270 |
+
--tasks arc_challenge_llama_3.1_instruct \
|
271 |
+
--apply_chat_template \
|
272 |
+
--num_fewshot 0 \
|
273 |
+
--batch_size auto
|
274 |
+
```
|
275 |
+
|
276 |
+
#### GSM-8K
|
277 |
+
```
|
278 |
+
lm_eval \
|
279 |
+
--model vllm \
|
280 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,max_gen_toks=1024,tensor_parallel_size=1 \
|
281 |
+
--tasks gsm8k_cot_llama_3.1_instruct \
|
282 |
+
--fewshot_as_multiturn \
|
283 |
+
--apply_chat_template \
|
284 |
+
--num_fewshot 8 \
|
285 |
+
--batch_size auto
|
286 |
+
```
|
287 |
+
|
288 |
+
#### Hellaswag
|
289 |
+
```
|
290 |
+
lm_eval \
|
291 |
+
--model vllm \
|
292 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
|
293 |
+
--tasks hellaswag \
|
294 |
+
--num_fewshot 10 \
|
295 |
+
--batch_size auto
|
296 |
+
```
|
297 |
+
|
298 |
+
#### Winogrande
|
299 |
+
```
|
300 |
+
lm_eval \
|
301 |
+
--model vllm \
|
302 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
|
303 |
+
--tasks winogrande \
|
304 |
+
--num_fewshot 5 \
|
305 |
+
--batch_size auto
|
306 |
+
```
|
307 |
+
|
308 |
+
#### TruthfulQA
|
309 |
+
```
|
310 |
+
lm_eval \
|
311 |
+
--model vllm \
|
312 |
+
--model_args pretrained="neuralmagic/Llama-3.2-1B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
|
313 |
+
--tasks truthfulqa \
|
314 |
+
--num_fewshot 0 \
|
315 |
+
--batch_size auto
|
316 |
+
```
|