Shashata commited on
Commit
47f6973
1 Parent(s): ac6b186

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +196 -3
README.md CHANGED
@@ -1,3 +1,196 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from transformers import AutoTokenizer
40
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
41
+ from llmcompressor.modifiers.quantization import GPTQModifier
42
+ from compressed_tensors.quantization import QuantizationArgs, QuantizationType, QuantizationStrategy
43
+ from datasets import load_dataset
44
+ import random
45
+
46
+ model_id = "HuggingFaceTB/SmolLM-135M-Instruct"
47
+
48
+
49
+ num_samples = 512
50
+ max_seq_len = 4096
51
+
52
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
53
+
54
+ 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)}
55
+
56
+ dataset_name = "neuralmagic/LLM_compression_calibration"
57
+ dataset = load_dataset(dataset_name, split="train")
58
+ ds = dataset.shuffle().select(range(num_samples))
59
+ ds = ds.map(preprocess_fn)
60
+
61
+ examples = [
62
+ tokenizer(
63
+ example["text"], padding=False, max_length=max_seq_len, truncation=True,
64
+ ) for example in ds
65
+ ]
66
+
67
+ # recipe = "w4a16_nohead_recipe.yaml"
68
+ recipe = GPTQModifier(
69
+ targets="Linear",
70
+ scheme="W4A16",
71
+ ignore=["lm_head"],
72
+ dampening_frac=0.1,
73
+ )
74
+
75
+
76
+ model = SparseAutoModelForCausalLM.from_pretrained(
77
+ model_id,
78
+ device_map="auto",
79
+ trust_remote_code=True
80
+ )
81
+
82
+ print(model)
83
+
84
+ oneshot(
85
+ model=model,
86
+ dataset=ds,
87
+ recipe=recipe,
88
+ max_seq_length=max_seq_len,
89
+ num_calibration_samples=num_samples,
90
+ oneshot_device="cuda:1,2,3",
91
+ )
92
+
93
+ model_name = model_id.split("/")[-1]
94
+
95
+ model.save_pretrained(f"{model_name}-quantized.w4a16")
96
+ tokenizer.save_pretrained(f"{model_name}-quantized.w4a16")
97
+
98
+ ```
99
+
100
+
101
+ ## Evaluation
102
+
103
+ 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:
104
+ ```
105
+ lm_eval \
106
+ --model sparseml \
107
+ --model_args pretrained=nm-testing/SmolLM-1.7B-Instruct-quantized.w4a16,dtype=bfloat16,max_legth=2048,add_bos_token=True,parallelize=True \
108
+ --tasks openllm \
109
+ --batch_size auto
110
+ ```
111
+
112
+ ### Accuracy
113
+
114
+ #### Open LLM Leaderboard evaluation scores
115
+ <table>
116
+ <tr>
117
+ <td><strong>Benchmark</strong>
118
+ </td>
119
+ <td><strong>SmolLM-135M-Instruct </strong>
120
+ </td>
121
+ <td><strong>SmolLM-135M-Instruct-quantized.w4a16(this model)</strong>
122
+ </td>
123
+ <td><strong>Recovery</strong>
124
+ </td>
125
+ </tr>
126
+ <tr>
127
+ <td>MMLU (5-shot)
128
+ </td>
129
+ <td>26.220
130
+ </td>
131
+ <td>25.202
132
+ </td>
133
+ <td>96.12%
134
+ </td>
135
+ </tr>
136
+ <tr>
137
+ <td>ARC Challenge (25-shot)
138
+ </td>
139
+ <td>29.948
140
+ </td>
141
+ <td>30.034
142
+ </td>
143
+ <td>100.29%
144
+ </td>
145
+ </tr>
146
+ <tr>
147
+ <td>GSM-8K (5-shot, strict-match)
148
+ </td>
149
+ <td>1.289
150
+ </td>
151
+ <td>1.971
152
+ </td>
153
+ <td>152.91%
154
+ </td>
155
+ </tr>
156
+ <tr>
157
+ <td>Hellaswag (10-shot)
158
+ </td>
159
+ <td>41.41
160
+ </td>
161
+ <td>40.81
162
+ </td>
163
+ <td>98.55%
164
+ </td>
165
+ </tr>
166
+ <tr>
167
+ <td>Winogrande (5-shot)
168
+ </td>
169
+ <td>50.039
170
+ </td>
171
+ <td>53.591
172
+ </td>
173
+ <td>107.10%
174
+ </td>
175
+ </tr>
176
+ <tr>
177
+ <td>TruthfulQA (0-shot)
178
+ </td>
179
+ <td>40.38
180
+ </td>
181
+ <td>39.87
182
+ </td>
183
+ <td>98.74%
184
+ </td>
185
+ </tr>
186
+ <tr>
187
+ <td><strong>Average</strong>
188
+ </td>
189
+ <td><strong>31.55</strong>
190
+ </td>
191
+ <td><strong>31.91</strong>
192
+ </td>
193
+ <td><strong>101.16%</strong>
194
+ </td>
195
+ </tr>
196
+ </table>