abhinavnmagic commited on
Commit
2abcd4a
1 Parent(s): eadc452

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +285 -0
README.md ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-405B-Instruct-quantized.w4a16
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Meta-Llama-3
19
+ - **Input:** Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Weight quantization:** INT4
23
+ - **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Meta-Llama-3.1-405B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-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). Use in languages other than English.
25
+ - **Release Date:** 8/9/2024
26
+ - **Version:** 1.0
27
+ - **License(s):** Llama3.1
28
+ - **Model Developers:** Neural Magic
29
+
30
+ Quantized version of [Meta-Llama-3.1-405B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct).
31
+ It achieves an average score of x.x on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves x.x.
32
+
33
+ ### Model Optimizations
34
+
35
+ This model was obtained by quantizing the weights of [Meta-Llama-3.1-405B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct) to INT4 data type.
36
+ This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.
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 INT4 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 512 sequences of 4,096 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-405B-Instruct-quantized.w4a16"
51
+ number_gpus = 8
52
+ max_model_len = 4096
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-405B-Instruct"
88
+
89
+ num_samples = 512
90
+ max_seq_len = 8192
91
+
92
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
93
+
94
+ preprocess_fn = lambda example: {"text": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n{text}".format_map(example)}
95
+
96
+ dataset_name = "neuralmagic/LLM_compression_calibration"
97
+ dataset = load_dataset(dataset_name, split="train")
98
+ ds = dataset.shuffle().select(range(num_samples))
99
+ ds = ds.map(preprocess_fn)
100
+
101
+ recipe = GPTQModifier(
102
+ targets="Linear",
103
+ scheme="W4A16",
104
+ ignore=["lm_head"],
105
+ dampening_frac=0.01,
106
+ )
107
+
108
+ model = SparseAutoModelForCausalLM.from_pretrained(
109
+ model_id,
110
+ device_map="auto",
111
+ trust_remote_code=True,
112
+ )
113
+
114
+ oneshot(
115
+ model=model,
116
+ dataset=ds,
117
+ recipe=recipe,
118
+ max_seq_length=max_seq_len,
119
+ num_calibration_samples=num_samples,
120
+ )
121
+ model.save_pretrained("Meta-Llama-3.1-405B-Instruct-quantized.w4a16")
122
+ ```
123
+
124
+
125
+ ## Evaluation
126
+
127
+ The model was evaluated on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) leaderboard tasks (version 1) with the [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness/tree/383bbd54bc621086e05aa1b030d8d4d5635b25e6) (commit 383bbd54bc621086e05aa1b030d8d4d5635b25e6) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
128
+ ```
129
+ lm_eval \
130
+ --model vllm \
131
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
132
+ --tasks openllm \
133
+ --batch_size auto
134
+ ```
135
+
136
+ ### Accuracy
137
+
138
+ #### Open LLM Leaderboard evaluation scores
139
+ <table>
140
+ <tr>
141
+ <td><strong>Benchmark</strong>
142
+ </td>
143
+ <td><strong>Meta-Llama-3.1-405B-Instruct </strong>
144
+ </td>
145
+ <td><strong>Meta-Llama-3.1-405B-Instruct-quantized.w4a16 (this model)</strong>
146
+ </td>
147
+ <td><strong>Recovery (this model) </strong>
148
+ </td>
149
+ </tr>
150
+ <tr>
151
+ <td>MMLU (5-shot)
152
+ </td>
153
+ <td>xx.xx
154
+ </td>
155
+ <td>xx.xx
156
+ </td>
157
+ <td>xx.xx%
158
+ </td>
159
+ </tr>
160
+ <tr>
161
+ <td>ARC Challenge (0-shot)
162
+ </td>
163
+ <td>96.93
164
+ </td>
165
+ <td>95.39
166
+ </td>
167
+ <td>98.41%
168
+ </td>
169
+ </tr>
170
+ <tr>
171
+ <td>GSM-8K (CoT, 8-shot, strict-match)
172
+ </td>
173
+ <td>96.44
174
+ </td>
175
+ <td>95.83
176
+ </td>
177
+ <td>99.36%
178
+ </td>
179
+ </tr>
180
+ <tr>
181
+ <td>Hellaswag (10-shot)
182
+ </td>
183
+ <td>xx.xx
184
+ </td>
185
+ <td>xx.xx%
186
+ </td>
187
+ </tr>
188
+ <tr>
189
+ <td>Winogrande (5-shot)
190
+ </td>
191
+ <td>xx.xx
192
+ </td>
193
+ <td>xx.xx%
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>TruthfulQA (0-shot)
198
+ </td>
199
+ <td>xx.xx
200
+ </td>
201
+ <td>xx.xx
202
+ </td>
203
+ <td>xx.xx%
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <td><strong>Average</strong>
208
+ </td>
209
+ <td><strong>xx.xx</strong>
210
+ </td>
211
+ <td><strong>xx.xx</strong>
212
+ </td>
213
+ <td><strong>xx.xx%</strong>
214
+ </td>
215
+ </tr>
216
+ </table>
217
+
218
+ ### Reproduction
219
+
220
+ The results were obtained using the following commands:
221
+
222
+ #### MMLU
223
+ ```
224
+ lm_eval \
225
+ --model vllm \
226
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,max_gen_toks=10,tensor_parallel_size=8 \
227
+ --tasks mmlu_llama_3.1_instruct \
228
+ --apply_chat_template \
229
+ --fewshot_as_multiturn \
230
+ --num_fewshot 5 \
231
+ --batch_size auto
232
+ ```
233
+
234
+ #### ARC-Challenge
235
+ ```
236
+ lm_eval \
237
+ --model vllm \
238
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
239
+ --tasks arc_challenge_llama_3.1_instruct \
240
+ --apply_chat_template \
241
+ --num_fewshot 0 \
242
+ --batch_size auto
243
+ ```
244
+
245
+ #### GSM-8K
246
+ ```
247
+ lm_eval \
248
+ --model vllm \
249
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
250
+ --tasks gsm8k_cot_llama_3.1_instruct \
251
+ --apply_chat_template \
252
+ --fewshot_as_multiturn \
253
+ --num_fewshot 8 \
254
+ --batch_size auto
255
+ ```
256
+
257
+ #### Hellaswag
258
+ ```
259
+ lm_eval \
260
+ --model vllm \
261
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
262
+ --tasks hellaswag \
263
+ --num_fewshot 10 \
264
+ --batch_size auto
265
+ ```
266
+
267
+ #### Winogrande
268
+ ```
269
+ lm_eval \
270
+ --model vllm \
271
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
272
+ --tasks winogrande \
273
+ --num_fewshot 5 \
274
+ --batch_size auto
275
+ ```
276
+
277
+ #### TruthfulQA
278
+ ```
279
+ lm_eval \
280
+ --model vllm \
281
+ --model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
282
+ --tasks truthfulqa \
283
+ --num_fewshot 0 \
284
+ --batch_size auto
285
+ ```