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_tag: text-generation
|
7 |
+
tags:
|
8 |
+
- int8
|
9 |
+
- vllm
|
10 |
+
base_model: HuggingFaceTB/SmolLM-360M-Instruct
|
11 |
+
---
|
12 |
+
|
13 |
+
# SmolLM-360M-Instruct-quantized.w8a8
|
14 |
+
|
15 |
+
## Model Overview
|
16 |
+
- **Model Architecture:** Llama
|
17 |
+
- **Input:** Text
|
18 |
+
- **Output:** Text
|
19 |
+
- **Model Optimizations:**
|
20 |
+
- **Activation quantization:** INT8
|
21 |
+
- **Weight quantization:** INT8
|
22 |
+
- **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [SmolLM-360M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM-360M-Instruct), this models is intended for assistant-like chat.
|
23 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
|
24 |
+
- **Release Date:** 8/22/2024
|
25 |
+
- **Version:** 1.0
|
26 |
+
- **License(s):** [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
27 |
+
- **Model Developers:** Neural Magic
|
28 |
+
|
29 |
+
Quantized version of [SmolLM-360M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM-360M-Instruct).
|
30 |
+
It achieves an average score of 35.49 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 35.15.
|
31 |
+
|
32 |
+
### Model Optimizations
|
33 |
+
|
34 |
+
This model was obtained by quantizing the weights of [SmolLM-360M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM-360M-Instruct) to INT8 data type.
|
35 |
+
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
|
36 |
+
|
37 |
+
Only weights and activations of the linear operators within transformers blocks are quantized.
|
38 |
+
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.
|
39 |
+
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.
|
40 |
+
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.
|
41 |
+
GPTQ used a 1% damping factor and 1,024 sequences sequences taken from Neural Magic's [LLM compression calibration dataset](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
|
42 |
+
|
43 |
+
## Deployment
|
44 |
+
|
45 |
+
### Use with vLLM
|
46 |
+
|
47 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
48 |
+
|
49 |
+
```python
|
50 |
+
from vllm import LLM, SamplingParams
|
51 |
+
from transformers import AutoTokenizer
|
52 |
+
|
53 |
+
model_id = "neuralmagic/SmolLM-360M-Instruct-quantized.w8a8"
|
54 |
+
|
55 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.92, max_tokens=100)
|
56 |
+
|
57 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
58 |
+
|
59 |
+
messages = [
|
60 |
+
{"role": "user", "content": "List the steps to bake a chocolate cake from scratch."},
|
61 |
+
]
|
62 |
+
|
63 |
+
prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
64 |
+
|
65 |
+
llm = LLM(model=model_id)
|
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 also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
74 |
+
|
75 |
+
## Creation
|
76 |
+
|
77 |
+
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
|
78 |
+
|
79 |
+
```python
|
80 |
+
from transformers import AutoTokenizer
|
81 |
+
from datasets import Dataset
|
82 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
83 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
84 |
+
import random
|
85 |
+
|
86 |
+
model_id = "HuggingFaceTB/SmolLM-360M-Instruct"
|
87 |
+
|
88 |
+
num_samples = 1024
|
89 |
+
max_seq_len = 2048
|
90 |
+
|
91 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
92 |
+
|
93 |
+
def preprocess_fn(example):
|
94 |
+
return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
|
95 |
+
|
96 |
+
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
|
97 |
+
ds = ds.shuffle().select(range(num_samples))
|
98 |
+
ds = ds.map(preprocess_fn)
|
99 |
+
|
100 |
+
recipe = GPTQModifier(
|
101 |
+
targets="Linear",
|
102 |
+
scheme="W8A8",
|
103 |
+
ignore=["lm_head"],
|
104 |
+
dampening_frac=0.01,
|
105 |
+
)
|
106 |
+
|
107 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
108 |
+
model_id,
|
109 |
+
device_map="auto",
|
110 |
+
)
|
111 |
+
|
112 |
+
oneshot(
|
113 |
+
model=model,
|
114 |
+
dataset=ds,
|
115 |
+
recipe=recipe,
|
116 |
+
max_seq_length=max_seq_len,
|
117 |
+
num_calibration_samples=num_samples,
|
118 |
+
)
|
119 |
+
model.save_pretrained("SmolLM-360M-Instruct-quantized.w8a8")
|
120 |
+
```
|
121 |
+
|
122 |
+
## Evaluation
|
123 |
+
|
124 |
+
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:
|
125 |
+
```
|
126 |
+
lm_eval \
|
127 |
+
--model vllm \
|
128 |
+
--model_args pretrained="neuralmagic/SmolLM-360M-Instruct-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
|
129 |
+
--tasks openllm \
|
130 |
+
--batch_size auto
|
131 |
+
```
|
132 |
+
|
133 |
+
### Accuracy
|
134 |
+
|
135 |
+
#### Open LLM Leaderboard evaluation scores
|
136 |
+
<table>
|
137 |
+
<tr>
|
138 |
+
<td><strong>Benchmark</strong>
|
139 |
+
</td>
|
140 |
+
<td><strong>SmolLM-360M-Instruct-quantized</strong>
|
141 |
+
</td>
|
142 |
+
<td><strong>SmolLM-360M-Instruct-quantized.w8a8 (this model)</strong>
|
143 |
+
</td>
|
144 |
+
<td><strong>Recovery</strong>
|
145 |
+
</td>
|
146 |
+
</tr>
|
147 |
+
<tr>
|
148 |
+
<td>MMLU (5-shot)
|
149 |
+
</td>
|
150 |
+
<td>25.69
|
151 |
+
</td>
|
152 |
+
<td>25.77
|
153 |
+
</td>
|
154 |
+
<td>100.3%
|
155 |
+
</td>
|
156 |
+
</tr>
|
157 |
+
<tr>
|
158 |
+
<td>ARC Challenge (25-shot)
|
159 |
+
</td>
|
160 |
+
<td>37.46
|
161 |
+
</td>
|
162 |
+
<td>38.05
|
163 |
+
</td>
|
164 |
+
<td>101.6%
|
165 |
+
</td>
|
166 |
+
</tr>
|
167 |
+
<tr>
|
168 |
+
<td>GSM-8K (5-shot, strict-match)
|
169 |
+
</td>
|
170 |
+
<td>2.05
|
171 |
+
</td>
|
172 |
+
<td>1.44
|
173 |
+
</td>
|
174 |
+
<td>70.4%
|
175 |
+
</td>
|
176 |
+
</tr>
|
177 |
+
<tr>
|
178 |
+
<td>Hellaswag (10-shot)
|
179 |
+
</td>
|
180 |
+
<td>51.72
|
181 |
+
</td>
|
182 |
+
<td>52.02
|
183 |
+
</td>
|
184 |
+
<td>100.6%
|
185 |
+
</td>
|
186 |
+
</tr>
|
187 |
+
<tr>
|
188 |
+
<td>Winogrande (5-shot)
|
189 |
+
</td>
|
190 |
+
<td>55.25
|
191 |
+
</td>
|
192 |
+
<td>55.41
|
193 |
+
</td>
|
194 |
+
<td>100.3%
|
195 |
+
</td>
|
196 |
+
</tr>
|
197 |
+
<tr>
|
198 |
+
<td>TruthfulQA (0-shot)
|
199 |
+
</td>
|
200 |
+
<td>38.76
|
201 |
+
</td>
|
202 |
+
<td>40.22
|
203 |
+
</td>
|
204 |
+
<td>103.8%
|
205 |
+
</td>
|
206 |
+
</tr>
|
207 |
+
<tr>
|
208 |
+
<td><strong>Average</strong>
|
209 |
+
</td>
|
210 |
+
<td><strong>35.15</strong>
|
211 |
+
</td>
|
212 |
+
<td><strong>35.49</strong>
|
213 |
+
</td>
|
214 |
+
<td><strong>101.6%</strong>
|
215 |
+
</td>
|
216 |
+
</tr>
|
217 |
+
</table>
|