nm-research commited on
Commit
e02bd08
·
verified ·
1 Parent(s): 580efd3

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +278 -0
README.md ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - deepseek
5
+ - int4
6
+ - vllm
7
+ - llmcompressor
8
+ base_model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
9
+ library_name: transformers
10
+ ---
11
+
12
+ # DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16
13
+
14
+ ## Model Overview
15
+ - **Model Architecture:** Qwen2ForCausalLM
16
+ - **Input:** Text
17
+ - **Output:** Text
18
+ - **Model Optimizations:**
19
+ - **Weight quantization:** INT4
20
+ - **Release Date:** 2/4/2025
21
+ - **Version:** 1.0
22
+ - **Model Developers:** Neural Magic
23
+
24
+ Quantized version of [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B).
25
+
26
+
27
+ ### Model Optimizations
28
+
29
+ This model was obtained by quantizing the weights of [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B) to INT4 data type.
30
+ This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.
31
+
32
+
33
+ Only the weights of the linear operators within transformers blocks are quantized.
34
+ Weights are quantized using a symmetric per-group scheme, with group size 128.
35
+ 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.
36
+
37
+
38
+ ## Use with vLLM
39
+
40
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
41
+
42
+ ```python
43
+ from transformers import AutoTokenizer
44
+ from vllm import LLM, SamplingParams
45
+
46
+ number_gpus = 1
47
+ model_name = "neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16"
48
+
49
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
50
+ sampling_params = SamplingParams(temperature=0.6, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
51
+ llm = LLM(model=model_name, tensor_parallel_size=number_gpus, trust_remote_code=True)
52
+
53
+ messages_list = [
54
+ [{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
55
+ ]
56
+
57
+ prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
58
+
59
+ outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
60
+
61
+ generated_text = [output.outputs[0].text for output in outputs]
62
+ print(generated_text)
63
+ ```
64
+
65
+ vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
66
+
67
+ ## Creation
68
+
69
+ This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.
70
+
71
+
72
+ ```python
73
+ from transformers import AutoModelForCausalLM, AutoTokenizer
74
+ from llmcompressor.modifiers.quantization import QuantizationModifier
75
+ from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
76
+ from llmcompressor.transformers import oneshot
77
+
78
+ # Load model
79
+ model_stub = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
80
+ model_name = model_stub.split("/")[-1]
81
+
82
+ num_samples = 2048
83
+ max_seq_len = 8192
84
+
85
+ tokenizer = AutoTokenizer.from_pretrained(model_stub)
86
+
87
+ model = AutoModelForCausalLM.from_pretrained(
88
+ model_stub,
89
+ device_map="auto",
90
+ torch_dtype="auto",
91
+ )
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.map(preprocess_fn)
98
+
99
+ # Configure the quantization algorithm and scheme
100
+ recipe = QuantizationModifier(
101
+ targets="Linear",
102
+ scheme="W4A16",
103
+ ignore=["lm_head"],
104
+ dampening_frac=0.01,
105
+ )
106
+
107
+ # Apply quantization
108
+ oneshot(
109
+ model=model,
110
+ dataset=ds,
111
+ recipe=recipe,
112
+ max_seq_length=max_seq_len,
113
+ num_calibration_samples=num_samples,
114
+ )
115
+
116
+ # Save to disk in compressed-tensors format
117
+ save_path = model_name + "-quantized.w4a16
118
+ model.save_pretrained(save_path)
119
+ tokenizer.save_pretrained(save_path)
120
+ print(f"Model and tokenizer saved to: {save_path}")
121
+ ```
122
+
123
+ ## Evaluation
124
+
125
+ The model was evaluated on OpenLLM Leaderboard [V1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard) and [V2](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/), using the following commands:
126
+
127
+ OpenLLM Leaderboard V1:
128
+ ```
129
+ lm_eval \
130
+ --model vllm \
131
+ --model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
132
+ --tasks openllm \
133
+ --write_out \
134
+ --batch_size auto \
135
+ --output_path output_dir \
136
+ --show_config
137
+ ```
138
+
139
+ OpenLLM Leaderboard V2:
140
+ ```
141
+ lm_eval \
142
+ --model vllm \
143
+ --model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
144
+ --apply_chat_template \
145
+ --fewshot_as_multiturn \
146
+ --tasks leaderboard \
147
+ --write_out \
148
+ --batch_size auto \
149
+ --output_path output_dir \
150
+ --show_config
151
+ ```
152
+
153
+ ### Accuracy
154
+
155
+ <table>
156
+ <thead>
157
+ <tr>
158
+ <th>Category</th>
159
+ <th>Metric</th>
160
+ <th>deepseek-ai/DeepSeek-R1-Distill-Qwen-7B</th>
161
+ <th>neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16</th>
162
+ <th>Recovery</th>
163
+ </tr>
164
+ </thead>
165
+ <tbody>
166
+ <tr>
167
+ <td rowspan="7"><b>OpenLLM V1</b></td>
168
+ <td>ARC-Challenge (Acc-Norm, 25-shot)</td>
169
+ <td>50.51</td>
170
+ <td></td>
171
+ <td>%</td>
172
+ </tr>
173
+ <tr>
174
+ <td>GSM8K (Strict-Match, 5-shot)</td>
175
+ <td>78.62</td>
176
+ <td></td>
177
+ <td>%</td>
178
+ </tr>
179
+ <tr>
180
+ <td>HellaSwag (Acc-Norm, 10-shot)</td>
181
+ <td>61.90</td>
182
+ <td></td>
183
+ <td>%</td>
184
+ </tr>
185
+ <tr>
186
+ <td>MMLU (Acc, 5-shot)</td>
187
+ <td>54.19</td>
188
+ <td></td>
189
+ <td>%</td>
190
+ </tr>
191
+ <tr>
192
+ <td>TruthfulQA (MC2, 0-shot)</td>
193
+ <td>45.55</td>
194
+ <td></td>
195
+ <td>%</td>
196
+ </tr>
197
+ <tr>
198
+ <td>Winogrande (Acc, 5-shot)</td>
199
+ <td>61.56</td>
200
+ <td></td>
201
+ <td>%</td>
202
+ </tr>
203
+ <tr>
204
+ <td><b>Average Score</b></td>
205
+ <td><b>58.72</b></td>
206
+ <td><b></b></td>
207
+ <td><b>%</b></td>
208
+ </tr>
209
+ <tr>
210
+ <td rowspan="7"><b>OpenLLM V2</b></td>
211
+ <td>IFEval (Inst Level Strict Acc, 0-shot)</td>
212
+ <td>39.67</td>
213
+ <td></td>
214
+ <td>%</td>
215
+ </tr>
216
+ <tr>
217
+ <td>BBH (Acc-Norm, 3-shot)</td>
218
+ <td>39.60</td>
219
+ <td></td>
220
+ <td>%</td>
221
+ </tr>
222
+ <tr>
223
+ <td>Math-Hard (Exact-Match, 4-shot)</td>
224
+ <td>0.00</td>
225
+ <td>0.00</td>
226
+ <td>---</td>
227
+ </tr>
228
+ <tr>
229
+ <td>GPQA (Acc-Norm, 0-shot)</td>
230
+ <td>25.24</td>
231
+ <td></td>
232
+ <td>%</td>
233
+ </tr>
234
+ <tr>
235
+ <td>MUSR (Acc-Norm, 0-shot)</td>
236
+ <td>38.09</td>
237
+ <td></td>
238
+ <td>%</td>
239
+ </tr>
240
+ <tr>
241
+ <td>MMLU-Pro (Acc, 5-shot)</td>
242
+ <td>19.53</td>
243
+ <td></td>
244
+ <td>%</td>
245
+ </tr>
246
+ <tr>
247
+ <td><b>Average Score</b></td>
248
+ <td><b>27.02</b></td>
249
+ <td><b></b></td>
250
+ <td><b>%</b></td>
251
+ </tr>
252
+ <tr>
253
+ <td rowspan="4"><b>Coding</b></td>
254
+ <td>HumanEval (pass@1)</td>
255
+ <td>40.80</td>
256
+ <td></td>
257
+ <td><b>%</b></td>
258
+ </tr>
259
+ <tr>
260
+ <td>HumanEval (pass@10)</td>
261
+ <td>64.40</td>
262
+ <td></td>
263
+ <td>%</td>
264
+ </tr>
265
+ <tr>
266
+ <td>HumanEval+ (pass@10)</td>
267
+ <td>38.50</td>
268
+ <td></td>
269
+ <td>%</td>
270
+ </tr>
271
+ <tr>
272
+ <td>HumanEval+ (pass@10)</td>
273
+ <td>60.40</td>
274
+ <td></td>
275
+ <td>%</td>
276
+ </tr>
277
+ </tbody>
278
+ </table>