alexmarques commited on
Commit
518b068
1 Parent(s): 1c42cac

Create README.md

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