alexmarques commited on
Commit
cb167f6
1 Parent(s): 534f742

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +260 -0
README.md ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ pipeline_tag: text-generation
5
+ ---
6
+
7
+ # Meta-Llama-3-8B-Instruct-quantized.w8a16
8
+
9
+ ## Model Overview
10
+ - **Model Architecture:** Meta-Llama-3
11
+ - **Input:** Text
12
+ - **Output:** Text
13
+ - **Model Optimizations:**
14
+ - **Activation quantization:** INT8
15
+ - **Weight quantization:** INT8
16
+ - **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct), this models is intended for assistant-like chat.
17
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
18
+ - **Release Date:** 7/11/2024
19
+ - **Version:** 1.0
20
+ - **Model Developers:** Neural Magic
21
+
22
+ Quantized version of [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct).
23
+ It achieves an average score of 68.66 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 68.54.
24
+
25
+ ### Model Optimizations
26
+
27
+ This model was obtained by quantizing the weights of [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) to INT8 data type.
28
+ 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).
29
+ Weight quantization also reduces disk size requirements by approximately 50%.
30
+
31
+ Only weights and activations of the linear operators within transformers blocks are quantized.
32
+ 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.
33
+ 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.
34
+ 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.
35
+ GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
36
+
37
+
38
+ ## Deployment
39
+
40
+ ### Use with vLLM
41
+
42
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
43
+
44
+ ```python
45
+ from vllm import LLM, SamplingParams
46
+ from transformers import AutoTokenizer
47
+
48
+ model_id = "neuralmagic/Meta-Llama-3-8B-Instruct-quantized.w8a8"
49
+ number_gpus = 1
50
+
51
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
52
+
53
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
54
+
55
+ messages = [
56
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
57
+ {"role": "user", "content": "Who are you?"},
58
+ ]
59
+
60
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
61
+
62
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
63
+
64
+ outputs = llm.generate(prompts, sampling_params)
65
+
66
+ generated_text = outputs[0].outputs[0].text
67
+ print(generated_text)
68
+ ```
69
+
70
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
71
+
72
+ ### Use with transformers
73
+
74
+ The following example contemplates how the model can be deployed in Transformers using the `generate()` function.
75
+
76
+
77
+ ```python
78
+ from transformers import AutoTokenizer, AutoModelForCausalLM
79
+
80
+ model_id = "neuralmagic/Meta-Llama-3-8B-Instruct-quantized.w8a8"
81
+
82
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
83
+ model = AutoModelForCausalLM.from_pretrained(
84
+ model_id,
85
+ torch_dtype="auto",
86
+ device_map="auto",
87
+ )
88
+
89
+ messages = [
90
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
91
+ {"role": "user", "content": "Who are you?"},
92
+ ]
93
+
94
+ input_ids = tokenizer.apply_chat_template(
95
+ messages,
96
+ add_generation_prompt=True,
97
+ return_tensors="pt"
98
+ ).to(model.device)
99
+
100
+ terminators = [
101
+ tokenizer.eos_token_id,
102
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
103
+ ]
104
+
105
+ outputs = model.generate(
106
+ input_ids,
107
+ max_new_tokens=256,
108
+ eos_token_id=terminators,
109
+ do_sample=True,
110
+ temperature=0.6,
111
+ top_p=0.9,
112
+ )
113
+ response = outputs[0][input_ids.shape[-1]:]
114
+ print(tokenizer.decode(response, skip_special_tokens=True))
115
+ ```
116
+
117
+ ## Creation
118
+
119
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
120
+
121
+ ```python
122
+ from transformers import AutoTokenizer
123
+ from datasets import Dataset
124
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
125
+ from llmcompressor.modifiers.quantization import GPTQModifier
126
+ import random
127
+
128
+ model_id = "microsoft/Phi-3-mini-128k-instruct"
129
+
130
+ num_samples = 256
131
+ max_seq_len = 8192
132
+
133
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
134
+
135
+ max_token_id = len(tokenizer.get_vocab()) - 1
136
+ input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
137
+ attention_mask = num_samples * [max_seq_len * [1]]
138
+ ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
139
+
140
+ recipe = GPTQModifier(
141
+ targets="Linear",
142
+ scheme="W8A8",
143
+ ignore=["lm_head"],
144
+ dampening_frac=0.01,
145
+ )
146
+
147
+ model = SparseAutoModelForCausalLM.from_pretrained(
148
+ model_id,
149
+ device_map="auto",
150
+ trust_remote_code=True,
151
+ )
152
+
153
+ oneshot(
154
+ model=model,
155
+ dataset=ds,
156
+ recipe=recipe,
157
+ max_seq_length=max_seq_len,
158
+ num_calibration_samples=num_samples,
159
+ )
160
+
161
+ model.save_pretrained("Meta-Llama-3-8B-Instruct-quantized.w8a8")
162
+ ```
163
+
164
+
165
+ ## Evaluation
166
+
167
+ 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:
168
+ ```
169
+ lm_eval \
170
+ --model vllm \
171
+ --model_args pretrained="neuralmagic/Meta-Llama-3-8B-Instruct-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
172
+ --tasks openllm \
173
+ --batch_size auto
174
+ ```
175
+
176
+ ### Accuracy
177
+
178
+ #### Open LLM Leaderboard evaluation scores
179
+ <table>
180
+ <tr>
181
+ <td><strong>Benchmark</strong>
182
+ </td>
183
+ <td><strong>Meta-Llama-3-8B-Instruct </strong>
184
+ </td>
185
+ <td><strong>Meta-Llama-3-8B-Instruct-quantized.w8a8 (this model)</strong>
186
+ </td>
187
+ <td><strong>Recovery</strong>
188
+ </td>
189
+ </tr>
190
+ <tr>
191
+ <td>MMLU (5-shot)
192
+ </td>
193
+ <td>66.54
194
+ </td>
195
+ <td>66.13
196
+ </td>
197
+ <td>99.4%
198
+ </td>
199
+ </tr>
200
+ <tr>
201
+ <td>ARC Challenge (25-shot)
202
+ </td>
203
+ <td>62.63
204
+ </td>
205
+ <td>62.20
206
+ </td>
207
+ <td>99.3%
208
+ </td>
209
+ </tr>
210
+ <tr>
211
+ <td>GSM-8K (5-shot, strict-match)
212
+ </td>
213
+ <td>75.21
214
+ </td>
215
+ <td>76.27
216
+ </td>
217
+ <td>101.4%
218
+ </td>
219
+ </tr>
220
+ <tr>
221
+ <td>Hellaswag (10-shot)
222
+ </td>
223
+ <td>78.81
224
+ </td>
225
+ <td>78.41
226
+ </td>
227
+ <td>99.5%
228
+ </td>
229
+ </tr>
230
+ <tr>
231
+ <td>Winogrande (5-shot)
232
+ </td>
233
+ <td>76.48
234
+ </td>
235
+ <td>76.48
236
+ </td>
237
+ <td>100.0%
238
+ </td>
239
+ </tr>
240
+ <tr>
241
+ <td>TruthfulQA (0-shot)
242
+ </td>
243
+ <td>52.49
244
+ </td>
245
+ <td>52.49
246
+ </td>
247
+ <td>100.0%
248
+ </td>
249
+ </tr>
250
+ <tr>
251
+ <td><strong>Average</strong>
252
+ </td>
253
+ <td><strong>68.69</strong>
254
+ </td>
255
+ <td><strong>68.66</strong>
256
+ </td>
257
+ <td><strong>100.0%</strong>
258
+ </td>
259
+ </tr>
260
+ </table>