alexmarques commited on
Commit
ea88407
·
verified ·
1 Parent(s): 854e789

Create README.md

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