alexmarques commited on
Commit
1eed01c
·
verified ·
1 Parent(s): faa056e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +226 -0
README.md ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-8B-quantized.w8a8
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Meta-Llama-3
19
+ - **Input:** Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Activation quantization:** INT8
23
+ - **Weight quantization:** INT8
24
+ - **Intended Use Cases:** Intended for commercial and research use multiple languages. Similarly to [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B), this models is intended for assistant-like chat.
25
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
26
+ - **Release Date:** 7/31/2024
27
+ - **Version:** 1.0
28
+ - **License(s):** Llama3.1
29
+ - **Model Developers:** Neural Magic
30
+
31
+ Quantized version of [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B).
32
+ It achieves an average score of 62.71 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 63.03.
33
+
34
+ ### Model Optimizations
35
+
36
+ This model was obtained by quantizing the weights of [Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B) to INT8 data type.
37
+ 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).
38
+ Weight quantization also reduces disk size requirements by approximately 50%.
39
+
40
+ Only weights and activations of the linear operators within transformers blocks are quantized.
41
+ 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.
42
+ 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.
43
+ 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.
44
+ GPTQ used a 1% damping factor and 256 sequences sequences taken from Neural Magic's [LLM compression calibration dataset](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
45
+
46
+
47
+ ## Deployment
48
+
49
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
50
+
51
+ ```python
52
+ from vllm import LLM, SamplingParams
53
+ from transformers import AutoTokenizer
54
+
55
+ model_id = "neuralmagic/Meta-Llama-3.1-8B-quantized.w8a8"
56
+ number_gpus = 1
57
+ max_model_len = 8192
58
+
59
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
60
+
61
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
62
+
63
+ messages = [
64
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
65
+ {"role": "user", "content": "Who are you?"},
66
+ ]
67
+
68
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
69
+
70
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
71
+
72
+ outputs = llm.generate(prompts, sampling_params)
73
+
74
+ generated_text = outputs[0].outputs[0].text
75
+ print(generated_text)
76
+ ```
77
+
78
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
79
+
80
+
81
+ ## Creation
82
+
83
+ This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
84
+
85
+ ```python
86
+ from transformers import AutoTokenizer
87
+ from datasets import Dataset
88
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
89
+ from llmcompressor.modifiers.quantization import GPTQModifier
90
+ import random
91
+
92
+ model_id = "meta-llama/Meta-Llama-3.1-8B"
93
+
94
+ num_samples = 256
95
+ max_seq_len = 8192
96
+
97
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
98
+
99
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
100
+
101
+ def preprocess_fn(example):
102
+ return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
103
+
104
+ ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
105
+ ds = ds.shuffle().select(range(num_samples))
106
+ ds = ds.map(preprocess_fn)
107
+
108
+ recipe = GPTQModifier(
109
+ targets="Linear",
110
+ scheme="W8A8",
111
+ ignore=["lm_head"],
112
+ dampening_frac=0.01,
113
+ )
114
+
115
+ model = SparseAutoModelForCausalLM.from_pretrained(
116
+ model_id,
117
+ device_map="auto",
118
+ trust_remote_code=True,
119
+ )
120
+
121
+ oneshot(
122
+ model=model,
123
+ dataset=ds,
124
+ recipe=recipe,
125
+ max_seq_length=max_seq_len,
126
+ num_calibration_samples=num_samples,
127
+ )
128
+ model.save_pretrained("Meta-Llama-3.1-8B-quantized.w8a16")
129
+ ```
130
+
131
+ ## Evaluation
132
+
133
+ 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:
134
+ ```
135
+ lm_eval \
136
+ --model vllm \
137
+ --model_args pretrained="neuralmagic/Meta-Llama-3-8B-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
138
+ --tasks openllm \
139
+ --batch_size auto
140
+ ```
141
+
142
+ ### Accuracy
143
+
144
+ #### Open LLM Leaderboard evaluation scores
145
+ <table>
146
+ <tr>
147
+ <td><strong>Benchmark</strong>
148
+ </td>
149
+ <td><strong>Meta-Llama-3-8B </strong>
150
+ </td>
151
+ <td><strong>Meta-Llama-3-8B-quantized.w8a8(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>65.07
160
+ </td>
161
+ <td>64.95
162
+ </td>
163
+ <td>99.8%
164
+ </td>
165
+ </tr>
166
+ <tr>
167
+ <td>ARC Challenge (25-shot)
168
+ </td>
169
+ <td>58.11
170
+ </td>
171
+ <td>58.62
172
+ </td>
173
+ <td>100.9%
174
+ </td>
175
+ </tr>
176
+ <tr>
177
+ <td>GSM-8K (5-shot, strict-match)
178
+ </td>
179
+ <td>50.64
180
+ </td>
181
+ <td>49.51
182
+ </td>
183
+ <td>97.8%
184
+ </td>
185
+ </tr>
186
+ <tr>
187
+ <td>Hellaswag (10-shot)
188
+ </td>
189
+ <td>82.30
190
+ </td>
191
+ <td>81.63
192
+ </td>
193
+ <td>99.2%
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>Winogrande (5-shot)
198
+ </td>
199
+ <td>77.90
200
+ </td>
201
+ <td>78.22
202
+ </td>
203
+ <td>100.4%
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <td>TruthfulQA (0-shot, mc2)
208
+ </td>
209
+ <td>44.15
210
+ </td>
211
+ <td>43.36
212
+ </td>
213
+ <td>98.2%
214
+ </td>
215
+ </tr>
216
+ <tr>
217
+ <td><strong>Average</strong>
218
+ </td>
219
+ <td><strong>63.03</strong>
220
+ </td>
221
+ <td><strong>62.71</strong>
222
+ </td>
223
+ <td><strong>99.5%</strong>
224
+ </td>
225
+ </tr>
226
+ </table>