alexmarques commited on
Commit
dc44c57
·
verified ·
1 Parent(s): 3d7e3dc

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +283 -0
README.md ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - de
5
+ - fr
6
+ - it
7
+ - pt
8
+ - hi
9
+ - es
10
+ - th
11
+ pipeline_tag: text-generation
12
+ license: llama3.1
13
+ ---
14
+
15
+ # Meta-Llama-3.1-70B-Instruct-quantized.w8a16
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Meta-Llama-3
19
+ - **Input:** Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Weight quantization:** INT8
23
+ - **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.
24
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
25
+ - **Release Date:** 7/24/2024
26
+ - **Version:** 1.0
27
+ - **License(s):** Llama3.1
28
+ - **Model Developers:** Neural Magic
29
+
30
+ Quantized version of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
31
+ It achieves scores within 1.5% of the scores of the unquantized model for MMLU, ARC-Challenge, GSM-8k, Hellaswag, Winogrande and TruthfulQA.
32
+
33
+ ### Model Optimizations
34
+
35
+ 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.
36
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
37
+
38
+ Only the weights of the linear operators within transformers blocks are quantized. Symmetric per-channel quantization is applied, in which a linear scaling per output dimension maps the INT8 and floating point representations of the quantized weights.
39
+ 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. GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
40
+
41
+
42
+ ## Deployment
43
+
44
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
45
+
46
+ ```python
47
+ from vllm import LLM, SamplingParams
48
+ from transformers import AutoTokenizer
49
+
50
+ model_id = "neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16"
51
+ number_gpus = 4
52
+ max_model_len = 8192
53
+
54
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
55
+
56
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
57
+
58
+ messages = [
59
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
60
+ {"role": "user", "content": "Who are you?"},
61
+ ]
62
+
63
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
64
+
65
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
66
+
67
+ outputs = llm.generate(prompts, sampling_params)
68
+
69
+ generated_text = outputs[0].outputs[0].text
70
+ print(generated_text)
71
+ ```
72
+
73
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
74
+
75
+
76
+ ## Creation
77
+
78
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
79
+
80
+ ```python
81
+ from transformers import AutoTokenizer
82
+ from datasets import Dataset
83
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
84
+ from llmcompressor.modifiers.quantization import GPTQModifier
85
+ import random
86
+
87
+ model_id = "meta-llama/Meta-Llama-3.1-70B-Instruct"
88
+
89
+ num_samples = 256
90
+ max_seq_len = 8192
91
+
92
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
93
+
94
+ def preprocess_fn(example):
95
+ return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
96
+
97
+ ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
98
+ ds = ds.shuffle().select(range(num_samples))
99
+ ds = ds.map(preprocess_fn)
100
+
101
+ examples = [tokenizer(example["text"], padding=False, max_length=max_seq_len, truncation=True) for example in ds]
102
+
103
+ recipe = GPTQModifier(
104
+ targets="Linear",
105
+ scheme="W8A16",
106
+ ignore=["lm_head"],
107
+ dampening_frac=0.1,
108
+ )
109
+
110
+ model = SparseAutoModelForCausalLM.from_pretrained(
111
+ model_id,
112
+ device_map="auto",
113
+ trust_remote_code=True,
114
+ )
115
+
116
+ oneshot(
117
+ model=model,
118
+ dataset=ds,
119
+ recipe=recipe,
120
+ max_seq_length=max_seq_len,
121
+ num_calibration_samples=num_samples,
122
+ )
123
+ model.save_pretrained("Meta-Llama-3.1-70B-Instruct-quantized.w8a16")
124
+ ```
125
+
126
+
127
+
128
+ ## Evaluation
129
+
130
+ The model was evaluated on MMLU, ARC-Challenge, GSM-8K, Hellaswag, Winogrande and TruthfulQA.
131
+ 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.
132
+ 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).
133
+
134
+ ### Accuracy
135
+
136
+ <table>
137
+ <tr>
138
+ <td><strong>Benchmark</strong>
139
+ </td>
140
+ <td><strong>Meta-Llama-3.1-70B-Instruct </strong>
141
+ </td>
142
+ <td><strong>Meta-Llama-3.1-70B-Instruct-quantized.w8a16 (this model)</strong>
143
+ </td>
144
+ <td><strong>Recovery</strong>
145
+ </td>
146
+ </tr>
147
+ <tr>
148
+ <td>MMLU (5-shot)
149
+ </td>
150
+ <td>67.94
151
+ </td>
152
+ <td>68.09
153
+ </td>
154
+ <td>100.2%
155
+ </td>
156
+ </tr>
157
+ <tr>
158
+ <td>ARC Challenge (0-shot)
159
+ </td>
160
+ <td>83.19
161
+ </td>
162
+ <td>82.68
163
+ </td>
164
+ <td>99.4%
165
+ </td>
166
+ </tr>
167
+ <tr>
168
+ <td>GSM-8K (CoT, 8-shot, strict-match)
169
+ </td>
170
+ <td>82.79
171
+ </td>
172
+ <td>82.64
173
+ </td>
174
+ <td>99.8%
175
+ </td>
176
+ </tr>
177
+ <tr>
178
+ <td>Hellaswag (10-shot)
179
+ </td>
180
+ <td>80.01
181
+ </td>
182
+ <td>80.21
183
+ </td>
184
+ <td>100.3%
185
+ </td>
186
+ </tr>
187
+ <tr>
188
+ <td>Winogrande (5-shot)
189
+ </td>
190
+ <td>77.90
191
+ </td>
192
+ <td>77.27
193
+ </td>
194
+ <td>99.2%
195
+ </td>
196
+ </tr>
197
+ <tr>
198
+ <td>TruthfulQA (0-shot)
199
+ </td>
200
+ <td>54.04
201
+ </td>
202
+ <td>54.15
203
+ </td>
204
+ <td>100.2%
205
+ </td>
206
+ </tr>
207
+ <tr>
208
+ <td><strong>Average</strong>
209
+ </td>
210
+ <td><strong>74.31</strong>
211
+ </td>
212
+ <td><strong>74.17</strong>
213
+ </td>
214
+ <td><strong>99.8%</strong>
215
+ </td>
216
+ </tr>
217
+ </table>
218
+
219
+ ### Reproduction
220
+
221
+ The results were obtained using the following commands:
222
+
223
+ #### MMLU
224
+ ```
225
+ lm_eval \
226
+ --model vllm \
227
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4 \
228
+ --tasks mmlu \
229
+ --num_fewshot 5 \
230
+ --batch_size auto
231
+ ```
232
+
233
+ #### ARC-Challenge
234
+ ```
235
+ lm_eval \
236
+ --model vllm \
237
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4 \
238
+ --tasks arc_challenge_llama_3.1_instruct \
239
+ --apply_chat_template \
240
+ --num_fewshot 0 \
241
+ --batch_size auto
242
+ ```
243
+
244
+ #### GSM-8K
245
+ ```
246
+ lm_eval \
247
+ --model vllm \
248
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4 \
249
+ --tasks gsm8k_cot_llama_3.1_instruct \
250
+ --apply_chat_template \
251
+ --num_fewshot 8 \
252
+ --batch_size auto
253
+ ```
254
+
255
+ #### Hellaswag
256
+ ```
257
+ lm_eval \
258
+ --model vllm \
259
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4 \
260
+ --tasks hellaswag \
261
+ --num_fewshot 10 \
262
+ --batch_size auto
263
+ ```
264
+
265
+ #### Winogrande
266
+ ```
267
+ lm_eval \
268
+ --model vllm \
269
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4 \
270
+ --tasks winogrande \
271
+ --num_fewshot 5 \
272
+ --batch_size auto
273
+ ```
274
+
275
+ #### Hellaswag
276
+ ```
277
+ lm_eval \
278
+ --model vllm \
279
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-70B-Instruct-quantized.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4 \
280
+ --tasks truthfulqa_mc \
281
+ --num_fewshot 0 \
282
+ --batch_size auto
283
+ ```