alexmarques commited on
Commit
7799071
1 Parent(s): 3a9931b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +316 -0
README.md ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-FP8
22
+
23
+ ## Model Overview
24
+ - **Model Architecture:** Llama-3
25
+ - **Input:** Text
26
+ - **Output:** Text
27
+ - **Model Optimizations:**
28
+ - **Activation quantization:** FP8
29
+ - **Weight quantization:** FP8
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 0.7% 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 FP8 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 FP8 and floating point representations for each output channel dimension.
48
+ Activations are quantized with a symmetric per-tensor scheme, where a fixed linear scaling factor is applied between FP8 and floating point representations for the entire activation tensor.
49
+ Linear scaling factors are computed via by minimizing the mean squarred error (MSE).
50
+ Weights are quantized by rounding to nearest FP8 representation.
51
+ The [llm-compressor](https://github.com/vllm-project/llm-compressor) library was applied to quantize the model, usin 512 sequences sequences taken from Neural Magic's [LLM compression calibration dataset](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
52
+
53
+ ## Deployment
54
+
55
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
56
+
57
+ ```python
58
+ from vllm import LLM, SamplingParams
59
+ from transformers import AutoTokenizer
60
+
61
+ model_id = "neuralmagic/Llama-3.2-3B-Instruct-FP8"
62
+ number_gpus = 1
63
+ max_model_len = 8192
64
+
65
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
66
+
67
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
68
+
69
+ messages = [
70
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
71
+ {"role": "user", "content": "Who are you?"},
72
+ ]
73
+
74
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
75
+
76
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
77
+
78
+ outputs = llm.generate(prompts, sampling_params)
79
+
80
+ generated_text = outputs[0].outputs[0].text
81
+ print(generated_text)
82
+ ```
83
+
84
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
85
+
86
+
87
+ ## Creation
88
+
89
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
90
+
91
+ ```python
92
+ from transformers import AutoTokenizer
93
+ from datasets import load_dataset
94
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
95
+ from llmcompressor.modifiers.quantization import QuantizationModifier
96
+
97
+ model_id = "meta-llama/Llama-3.2-3B-Instruct"
98
+
99
+ num_samples = 512
100
+ max_seq_len = 8192
101
+
102
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
103
+
104
+ def preprocess_fn(example):
105
+ return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
106
+
107
+ ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
108
+ ds = ds.shuffle().select(range(num_samples))
109
+ ds = ds.map(preprocess_fn)
110
+
111
+ recipe = QuantizationModifier(
112
+ targets="Linear",
113
+ scheme="FP8",
114
+ ignore=["lm_head"],
115
+ observer="mse",
116
+ )
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-3B-Instruct-FP8")
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-3B-Instruct </strong>
150
+ </td>
151
+ <td><strong>Llama-3.2-3B-Instruct-FP8 (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>62.98
160
+ </td>
161
+ <td>62.61
162
+ </td>
163
+ <td>99.4%
164
+ </td>
165
+ </tr>
166
+ <tr>
167
+ <td>MMLU (CoT, 0-shot)
168
+ </td>
169
+ <td>65.40
170
+ </td>
171
+ <td>65.20
172
+ </td>
173
+ <td>99.7%
174
+ </td>
175
+ </tr>
176
+ <tr>
177
+ <td>ARC Challenge (0-shot)
178
+ </td>
179
+ <td>77.13
180
+ </td>
181
+ <td>76.62
182
+ </td>
183
+ <td>99.3%
184
+ </td>
185
+ </tr>
186
+ <tr>
187
+ <td>GSM-8K (CoT, 8-shot, strict-match)
188
+ </td>
189
+ <td>77.94
190
+ </td>
191
+ <td>77.86
192
+ </td>
193
+ <td>99.9%
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>Hellaswag (10-shot)
198
+ </td>
199
+ <td>73.62
200
+ </td>
201
+ <td>73.48
202
+ </td>
203
+ <td>99.8%
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <td>Winogrande (5-shot)
208
+ </td>
209
+ <td>71.11
210
+ </td>
211
+ <td>70.88
212
+ </td>
213
+ <td>99.7%
214
+ </td>
215
+ </tr>
216
+ <tr>
217
+ <td>TruthfulQA (0-shot, mc2)
218
+ </td>
219
+ <td>51.47
220
+ </td>
221
+ <td>51.65
222
+ </td>
223
+ <td>100.3%
224
+ </td>
225
+ </tr>
226
+ <tr>
227
+ <td><strong>Average</strong>
228
+ </td>
229
+ <td><strong>68.52</strong>
230
+ </td>
231
+ <td><strong>68.33</strong>
232
+ </td>
233
+ <td><strong>99.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-3B-Instruct-FP8",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-3B-Instruct-FP8",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-3B-Instruct-FP8",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-3B-Instruct-FP8",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-3B-Instruct-FP8",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-3B-Instruct-FP8",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-3B-Instruct-FP8",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
+ ```