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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- deepseek
|
| 5 |
+
- fp8
|
| 6 |
+
- vllm
|
| 7 |
+
base_model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
|
| 8 |
+
library_name: transformers
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# DeepSeek-R1-Distill-Qwen-7B-FP8-dynamic
|
| 12 |
+
|
| 13 |
+
## Model Overview
|
| 14 |
+
- **Model Architecture:** Qwen2ForCausalLM
|
| 15 |
+
- **Input:** Text
|
| 16 |
+
- **Output:** Text
|
| 17 |
+
- **Model Optimizations:**
|
| 18 |
+
- **Weight quantization:** FP8
|
| 19 |
+
- **Activation quantization:** FP8
|
| 20 |
+
- **Release Date:** 2/5/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 and activations of [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B) 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 = 1
|
| 46 |
+
model_name = "neuralmagic/DeepSeek-R1-Distill-Qwen-7B-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 |
+
import os
|
| 76 |
+
|
| 77 |
+
# Load model
|
| 78 |
+
model_stub = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
|
| 79 |
+
model_name = model_stub.split("/")[-1]
|
| 80 |
+
|
| 81 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 82 |
+
model_stub,
|
| 83 |
+
torch_dtype="auto",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
tokenizer = AutoTokenizer.from_pretrained(model_stub)
|
| 87 |
+
|
| 88 |
+
# Configure the quantization algorithm and scheme
|
| 89 |
+
recipe = QuantizationModifier(
|
| 90 |
+
targets="Linear",
|
| 91 |
+
scheme="FP8_DYNAMIC",
|
| 92 |
+
ignore=["lm_head"],
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
# Apply quantization
|
| 96 |
+
oneshot(
|
| 97 |
+
model=model,
|
| 98 |
+
recipe=recipe,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
# Save to disk in compressed-tensors format
|
| 102 |
+
save_path = model_name + "-FP8-dynamic
|
| 103 |
+
model.save_pretrained(save_path)
|
| 104 |
+
tokenizer.save_pretrained(save_path)
|
| 105 |
+
print(f"Model and tokenizer saved to: {save_path}")
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
## Evaluation
|
| 109 |
+
|
| 110 |
+
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:
|
| 111 |
+
|
| 112 |
+
OpenLLM Leaderboard V1:
|
| 113 |
+
```
|
| 114 |
+
lm_eval \
|
| 115 |
+
--model vllm \
|
| 116 |
+
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-FP8-dynamic",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
|
| 117 |
+
--tasks openllm \
|
| 118 |
+
--write_out \
|
| 119 |
+
--batch_size auto \
|
| 120 |
+
--output_path output_dir \
|
| 121 |
+
--show_config
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
OpenLLM Leaderboard V2:
|
| 125 |
+
```
|
| 126 |
+
lm_eval \
|
| 127 |
+
--model vllm \
|
| 128 |
+
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-FP8-dynamic",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
|
| 129 |
+
--apply_chat_template \
|
| 130 |
+
--fewshot_as_multiturn \
|
| 131 |
+
--tasks leaderboard \
|
| 132 |
+
--write_out \
|
| 133 |
+
--batch_size auto \
|
| 134 |
+
--output_path output_dir \
|
| 135 |
+
--show_config
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
### Accuracy
|
| 139 |
+
|
| 140 |
+
<table>
|
| 141 |
+
<thead>
|
| 142 |
+
<tr>
|
| 143 |
+
<th>Category</th>
|
| 144 |
+
<th>Metric</th>
|
| 145 |
+
<th>deepseek-ai/DeepSeek-R1-Distill-Qwen-7B</th>
|
| 146 |
+
<th>neuralmagic/DeepSeek-R1-Distill-Qwen-7B-FP8-dynamic</th>
|
| 147 |
+
<th>Recovery</th>
|
| 148 |
+
</tr>
|
| 149 |
+
</thead>
|
| 150 |
+
<tbody>
|
| 151 |
+
<tr>
|
| 152 |
+
<td rowspan="7"><b>OpenLLM V1</b></td>
|
| 153 |
+
<td>ARC-Challenge (Acc-Norm, 25-shot)</td>
|
| 154 |
+
<td>50.51</td>
|
| 155 |
+
<td>50.51</td>
|
| 156 |
+
<td>100.0%</td>
|
| 157 |
+
</tr>
|
| 158 |
+
<tr>
|
| 159 |
+
<td>GSM8K (Strict-Match, 5-shot)</td>
|
| 160 |
+
<td>78.62</td>
|
| 161 |
+
<td>79.83</td>
|
| 162 |
+
<td>101.5%</td>
|
| 163 |
+
</tr>
|
| 164 |
+
<tr>
|
| 165 |
+
<td>HellaSwag (Acc-Norm, 10-shot)</td>
|
| 166 |
+
<td>61.90</td>
|
| 167 |
+
<td>61.62</td>
|
| 168 |
+
<td>99.6%</td>
|
| 169 |
+
</tr>
|
| 170 |
+
<tr>
|
| 171 |
+
<td>MMLU (Acc, 5-shot)</td>
|
| 172 |
+
<td>54.19</td>
|
| 173 |
+
<td>53.76</td>
|
| 174 |
+
<td>99.2%</td>
|
| 175 |
+
</tr>
|
| 176 |
+
<tr>
|
| 177 |
+
<td>TruthfulQA (MC2, 0-shot)</td>
|
| 178 |
+
<td>45.55</td>
|
| 179 |
+
<td>46.14</td>
|
| 180 |
+
<td>101.3%</td>
|
| 181 |
+
</tr>
|
| 182 |
+
<tr>
|
| 183 |
+
<td>Winogrande (Acc, 5-shot)</td>
|
| 184 |
+
<td>61.56</td>
|
| 185 |
+
<td>60.54</td>
|
| 186 |
+
<td>98.3%</td>
|
| 187 |
+
</tr>
|
| 188 |
+
<tr>
|
| 189 |
+
<td><b>Average Score</b></td>
|
| 190 |
+
<td><b>58.72</b></td>
|
| 191 |
+
<td><b>58.73</b></td>
|
| 192 |
+
<td><b>100.0%</b></td>
|
| 193 |
+
</tr>
|
| 194 |
+
<tr>
|
| 195 |
+
<td rowspan="7"><b>OpenLLM V2</b></td>
|
| 196 |
+
<td>IFEval (Inst Level Strict Acc, 0-shot)</td>
|
| 197 |
+
<td>39.67</td>
|
| 198 |
+
<td>39.77</td>
|
| 199 |
+
<td>100.2%</td>
|
| 200 |
+
</tr>
|
| 201 |
+
<tr>
|
| 202 |
+
<td>BBH (Acc-Norm, 3-shot)</td>
|
| 203 |
+
<td>39.60</td>
|
| 204 |
+
<td>39.33</td>
|
| 205 |
+
<td>99.3%</td>
|
| 206 |
+
</tr>
|
| 207 |
+
<tr>
|
| 208 |
+
<td>Math-Hard (Exact-Match, 4-shot)</td>
|
| 209 |
+
<td>0.00</td>
|
| 210 |
+
<td>0.00</td>
|
| 211 |
+
<td>---</td>
|
| 212 |
+
</tr>
|
| 213 |
+
<tr>
|
| 214 |
+
<td>GPQA (Acc-Norm, 0-shot)</td>
|
| 215 |
+
<td>25.24</td>
|
| 216 |
+
<td>24.97</td>
|
| 217 |
+
<td>98.6%</td>
|
| 218 |
+
</tr>
|
| 219 |
+
<tr>
|
| 220 |
+
<td>MUSR (Acc-Norm, 0-shot)</td>
|
| 221 |
+
<td>38.09</td>
|
| 222 |
+
<td>37.82</td>
|
| 223 |
+
<td>99.3%</td>
|
| 224 |
+
</tr>
|
| 225 |
+
<tr>
|
| 226 |
+
<td>MMLU-Pro (Acc, 5-shot)</td>
|
| 227 |
+
<td>19.53</td>
|
| 228 |
+
<td>18.53</td>
|
| 229 |
+
<td>94.5%</td>
|
| 230 |
+
</tr>
|
| 231 |
+
<tr>
|
| 232 |
+
<td><b>Average Score</b></td>
|
| 233 |
+
<td><b>27.02</b></td>
|
| 234 |
+
<td><b>26.74</b></td>
|
| 235 |
+
<td><b>99.0%</b></td>
|
| 236 |
+
</tr>
|
| 237 |
+
<tr>
|
| 238 |
+
<td rowspan="4"><b>Coding</b></td>
|
| 239 |
+
<td>HumanEval (pass@1)</td>
|
| 240 |
+
<td>40.80</td>
|
| 241 |
+
<td>39.50</td>
|
| 242 |
+
<td><b>96.8%</b></td>
|
| 243 |
+
</tr>
|
| 244 |
+
<tr>
|
| 245 |
+
<td>HumanEval (pass@10)</td>
|
| 246 |
+
<td>64.40</td>
|
| 247 |
+
<td>62.10</td>
|
| 248 |
+
<td>96.4%</td>
|
| 249 |
+
</tr>
|
| 250 |
+
<tr>
|
| 251 |
+
<td>HumanEval+ (pass@10)</td>
|
| 252 |
+
<td>38.50</td>
|
| 253 |
+
<td>37.20</td>
|
| 254 |
+
<td>96.6%</td>
|
| 255 |
+
</tr>
|
| 256 |
+
<tr>
|
| 257 |
+
<td>HumanEval+ (pass@10)</td>
|
| 258 |
+
<td>60.40</td>
|
| 259 |
+
<td>59.30</td>
|
| 260 |
+
<td>98.2%</td>
|
| 261 |
+
</tr>
|
| 262 |
+
</tbody>
|
| 263 |
+
</table>
|