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|
|
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-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-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-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:** 7/26/2024
|
26 |
+
- **Version:** 1.0
|
27 |
+
- **License(s):** [Llama3](https://llama.meta.com/llama3/license/)
|
28 |
+
- **Model Developers:** Neural Magic
|
29 |
+
|
30 |
+
Quantized version of [Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct).
|
31 |
+
It achieves an average score of 67.57 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 69.32.
|
32 |
+
|
33 |
+
### Model Optimizations
|
34 |
+
|
35 |
+
This model was obtained by quantizing the weights of [Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-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 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-8B-Instruct-quantized.w4a16"
|
51 |
+
number_gpus = 1
|
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-8B-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-8B-Instruct-quantized.w4a16")
|
122 |
+
```
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
## Evaluation
|
127 |
+
|
128 |
+
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:
|
129 |
+
```
|
130 |
+
lm_eval \
|
131 |
+
--model vllm \
|
132 |
+
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
|
133 |
+
--tasks openllm \
|
134 |
+
--batch_size auto
|
135 |
+
```
|
136 |
+
|
137 |
+
### Accuracy
|
138 |
+
|
139 |
+
#### Open LLM Leaderboard evaluation scores
|
140 |
+
<table>
|
141 |
+
<tr>
|
142 |
+
<td><strong>Benchmark</strong>
|
143 |
+
</td>
|
144 |
+
<td><strong>Meta-Llama-3.1-8B-Instruct </strong>
|
145 |
+
</td>
|
146 |
+
<td><strong>hugging-quants/Meta-Llama-3.1-8B-Instruct-AWQ-INT4</strong>
|
147 |
+
</td>
|
148 |
+
<td><strong>Meta-Llama-3.1-8B-Instruct-quantized.w4a16 (this model)</strong>
|
149 |
+
</td>
|
150 |
+
<td><strong>Recovery (this model) </strong>
|
151 |
+
</td>
|
152 |
+
</tr>
|
153 |
+
<tr>
|
154 |
+
<td>MMLU (5-shot)
|
155 |
+
</td>
|
156 |
+
<td>67.94
|
157 |
+
</td>
|
158 |
+
<td>66.33
|
159 |
+
</td>
|
160 |
+
<td>65.38
|
161 |
+
</td>
|
162 |
+
<td>96.23%
|
163 |
+
</td>
|
164 |
+
</tr>
|
165 |
+
<tr>
|
166 |
+
<td>ARC Challenge (25-shot)
|
167 |
+
</td>
|
168 |
+
<td>60.41
|
169 |
+
</td>
|
170 |
+
<td>58.36
|
171 |
+
</td>
|
172 |
+
<td>59.30
|
173 |
+
</td>
|
174 |
+
<td>98.16%
|
175 |
+
</td>
|
176 |
+
</tr>
|
177 |
+
<tr>
|
178 |
+
<td>GSM-8K (5-shot, strict-match)
|
179 |
+
</td>
|
180 |
+
<td>75.66
|
181 |
+
</td>
|
182 |
+
<td>74.07
|
183 |
+
</td>
|
184 |
+
<td>75.43
|
185 |
+
</td>
|
186 |
+
<td>99.69%
|
187 |
+
</td>
|
188 |
+
</tr>
|
189 |
+
<tr>
|
190 |
+
<td>Hellaswag (10-shot)
|
191 |
+
</td>
|
192 |
+
<td>80.01
|
193 |
+
</td>
|
194 |
+
<td>79.18
|
195 |
+
</td>
|
196 |
+
<td>79.05
|
197 |
+
</td>
|
198 |
+
<td>98.80%
|
199 |
+
</td>
|
200 |
+
</tr>
|
201 |
+
<tr>
|
202 |
+
<td>Winogrande (5-shot)
|
203 |
+
</td>
|
204 |
+
<td>77.90
|
205 |
+
</td>
|
206 |
+
<td>76.00
|
207 |
+
</td>
|
208 |
+
<td>76.08
|
209 |
+
</td>
|
210 |
+
<td>97.66%
|
211 |
+
</td>
|
212 |
+
</tr>
|
213 |
+
<tr>
|
214 |
+
<td>TruthfulQA (0-shot)
|
215 |
+
</td>
|
216 |
+
<td>54.04
|
217 |
+
</td>
|
218 |
+
<td>51.91
|
219 |
+
</td>
|
220 |
+
<td>50.19
|
221 |
+
</td>
|
222 |
+
<td>92.8%
|
223 |
+
</td>
|
224 |
+
</tr>
|
225 |
+
<tr>
|
226 |
+
<td><strong>Average</strong>
|
227 |
+
</td>
|
228 |
+
<td><strong>69.33</strong>
|
229 |
+
</td>
|
230 |
+
<td><strong>67.64</strong>
|
231 |
+
</td>
|
232 |
+
<td><strong>67.57</strong>
|
233 |
+
</td>
|
234 |
+
<td><strong>97.47%</strong>
|
235 |
+
</td>
|
236 |
+
</tr>
|
237 |
+
</table>
|