alexmarques commited on
Commit
35c3e29
1 Parent(s): ef8e2c3

Create README.md

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