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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# SmolLM-135M-Instruct-quantized.w4a16
|
| 9 |
+
|
| 10 |
+
## Model Overview
|
| 11 |
+
- **Model Architecture:** SmolLM-135M-Instruct
|
| 12 |
+
- **Input:** Text
|
| 13 |
+
- **Output:** Text
|
| 14 |
+
- **Model Optimizations:**
|
| 15 |
+
- **Weight quantization:** INT4
|
| 16 |
+
- **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [[SmolLM-135M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM-135M), 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:** 8/23/2024
|
| 19 |
+
- **Version:** 1.0
|
| 20 |
+
- **License(s)**: [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 21 |
+
- **Model Developers:** Neural Magic
|
| 22 |
+
|
| 23 |
+
Quantized version of [SmolLM-135M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM-135M).
|
| 24 |
+
It achieves an average score of 31.91 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 31.55.
|
| 25 |
+
|
| 26 |
+
### Model Optimizations
|
| 27 |
+
|
| 28 |
+
This model was obtained by quantizing the weights of [SmolLM-135M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM-135M) to INT4 data type.
|
| 29 |
+
This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.
|
| 30 |
+
|
| 31 |
+
Only the weights of the linear operators within transformers blocks are quantized. Symmetric group-wise quantization is applied, in which a linear scaling per group maps the INT4 and floating point representations of the quantized weights.
|
| 32 |
+
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. Quantization is performed with 10% damping factor, group-size as 64 and 512 sequences sampled from [LLM Compression Calibration](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
|
| 33 |
+
|
| 34 |
+
## Creation
|
| 35 |
+
|
| 36 |
+
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
from transformers import AutoTokenizer
|
| 46 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
| 47 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
| 48 |
+
from compressed_tensors.quantization import QuantizationArgs, QuantizationType, QuantizationStrategy
|
| 49 |
+
from datasets import load_dataset
|
| 50 |
+
import random
|
| 51 |
+
|
| 52 |
+
model_id = "HuggingFaceTB/SmolLM-135M-Instruct"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
num_samples = 512
|
| 56 |
+
max_seq_len = 4096
|
| 57 |
+
|
| 58 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 59 |
+
|
| 60 |
+
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)}
|
| 61 |
+
|
| 62 |
+
dataset_name = "neuralmagic/LLM_compression_calibration"
|
| 63 |
+
dataset = load_dataset(dataset_name, split="train")
|
| 64 |
+
ds = dataset.shuffle().select(range(num_samples))
|
| 65 |
+
ds = ds.map(preprocess_fn)
|
| 66 |
+
|
| 67 |
+
examples = [
|
| 68 |
+
tokenizer(
|
| 69 |
+
example["text"], padding=False, max_length=max_seq_len, truncation=True,
|
| 70 |
+
) for example in ds
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
# recipe = "w4a16_nohead_recipe.yaml"
|
| 74 |
+
recipe = GPTQModifier(
|
| 75 |
+
targets="Linear",
|
| 76 |
+
scheme="W4A16",
|
| 77 |
+
ignore=["lm_head"],
|
| 78 |
+
dampening_frac=0.1,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
| 83 |
+
model_id,
|
| 84 |
+
device_map="auto",
|
| 85 |
+
trust_remote_code=True
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
print(model)
|
| 89 |
+
|
| 90 |
+
oneshot(
|
| 91 |
+
model=model,
|
| 92 |
+
dataset=ds,
|
| 93 |
+
recipe=recipe,
|
| 94 |
+
max_seq_length=max_seq_len,
|
| 95 |
+
num_calibration_samples=num_samples,
|
| 96 |
+
oneshot_device="cuda:1,2,3",
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
model_name = model_id.split("/")[-1]
|
| 100 |
+
|
| 101 |
+
model.save_pretrained(f"{model_name}-quantized.w4a16")
|
| 102 |
+
tokenizer.save_pretrained(f"{model_name}-quantized.w4a16")
|
| 103 |
+
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
## Evaluation
|
| 108 |
+
|
| 109 |
+
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 [sparseML](https://github.com/neuralmagic/sparseml) engine, using the following command:
|
| 110 |
+
```
|
| 111 |
+
lm_eval \
|
| 112 |
+
--model sparseml \
|
| 113 |
+
--model_args pretrained=nm-testing/SmolLM-1.7B-Instruct-quantized.w4a16,dtype=bfloat16,max_legth=2048,add_bos_token=True,parallelize=True \
|
| 114 |
+
--tasks openllm \
|
| 115 |
+
--batch_size auto
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
### Accuracy
|
| 119 |
+
|
| 120 |
+
#### Open LLM Leaderboard evaluation scores
|
| 121 |
+
<table>
|
| 122 |
+
<tr>
|
| 123 |
+
<td><strong>Benchmark</strong>
|
| 124 |
+
</td>
|
| 125 |
+
<td><strong>SmolLM-135M-Instruct </strong>
|
| 126 |
+
</td>
|
| 127 |
+
<td><strong>SmolLM-135M-Instruct-quantized.w4a16(this model)</strong>
|
| 128 |
+
</td>
|
| 129 |
+
<td><strong>Recovery</strong>
|
| 130 |
+
</td>
|
| 131 |
+
</tr>
|
| 132 |
+
<tr>
|
| 133 |
+
<td>MMLU (5-shot)
|
| 134 |
+
</td>
|
| 135 |
+
<td>26.22
|
| 136 |
+
</td>
|
| 137 |
+
<td>25.20
|
| 138 |
+
</td>
|
| 139 |
+
<td>96.12%
|
| 140 |
+
</td>
|
| 141 |
+
</tr>
|
| 142 |
+
<tr>
|
| 143 |
+
<td>ARC Challenge (25-shot)
|
| 144 |
+
</td>
|
| 145 |
+
<td>29.948
|
| 146 |
+
</td>
|
| 147 |
+
<td>30.034
|
| 148 |
+
</td>
|
| 149 |
+
<td>100.29%
|
| 150 |
+
</td>
|
| 151 |
+
</tr>
|
| 152 |
+
<tr>
|
| 153 |
+
<td>GSM-8K (5-shot, strict-match)
|
| 154 |
+
</td>
|
| 155 |
+
<td>1.289
|
| 156 |
+
</td>
|
| 157 |
+
<td>1.971
|
| 158 |
+
</td>
|
| 159 |
+
<td>152.91%
|
| 160 |
+
</td>
|
| 161 |
+
</tr>
|
| 162 |
+
<tr>
|
| 163 |
+
<td>Hellaswag (10-shot)
|
| 164 |
+
</td>
|
| 165 |
+
<td>71.22
|
| 166 |
+
</td>
|
| 167 |
+
<td>70.53
|
| 168 |
+
</td>
|
| 169 |
+
<td>99.03%
|
| 170 |
+
</td>
|
| 171 |
+
</tr>
|
| 172 |
+
<tr>
|
| 173 |
+
<td>Winogrande (5-shot)
|
| 174 |
+
</td>
|
| 175 |
+
<td>68.67
|
| 176 |
+
</td>
|
| 177 |
+
<td>68.35
|
| 178 |
+
</td>
|
| 179 |
+
<td>99.53%
|
| 180 |
+
</td>
|
| 181 |
+
</tr>
|
| 182 |
+
<tr>
|
| 183 |
+
<td>TruthfulQA (0-shot)
|
| 184 |
+
</td>
|
| 185 |
+
<td>53.11
|
| 186 |
+
</td>
|
| 187 |
+
<td>52.57
|
| 188 |
+
</td>
|
| 189 |
+
<td>98.98%
|
| 190 |
+
</td>
|
| 191 |
+
</tr>
|
| 192 |
+
<tr>
|
| 193 |
+
<td><strong>Average</strong>
|
| 194 |
+
</td>
|
| 195 |
+
<td><strong>58.8</strong>
|
| 196 |
+
</td>
|
| 197 |
+
<td><strong>57.75</strong>
|
| 198 |
+
</td>
|
| 199 |
+
<td><strong>98.21%</strong>
|
| 200 |
+
</td>
|
| 201 |
+
</tr>
|
| 202 |
+
</table>
|