nm-research commited on
Commit
8ea8712
·
verified ·
1 Parent(s): fb1e555

Create README.md

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