Add README
Browse files
README.md
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
tags:
|
6 |
+
- deepseek
|
7 |
+
- fp8
|
8 |
+
- vllm
|
9 |
+
base_model: deepseek-ai/DeepSeek-R1-Distill-Llama-70B
|
10 |
+
library_name: transformers
|
11 |
+
---
|
12 |
+
|
13 |
+
# DeepSeek-R1-Distill-Llama-70B-FP8-Dynamic
|
14 |
+
|
15 |
+
## Model Overview
|
16 |
+
- **Model Architecture:** DeepSeek-R1-Distill-Llama-70B
|
17 |
+
- **Input:** Text
|
18 |
+
- **Output:** Text
|
19 |
+
- **Model Optimizations:**
|
20 |
+
- **Weight quantization:** FP8
|
21 |
+
- **Activation quantization:** FP8
|
22 |
+
- **Release Date:** 3/1/2025
|
23 |
+
- **Version:** 1.0
|
24 |
+
- **Model Developers:** Neural Magic
|
25 |
+
|
26 |
+
Quantized version of [DeepSeek-R1-Distill-Llama-70B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-70B).
|
27 |
+
It achieves an average score of 76.52 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 76.49.
|
28 |
+
|
29 |
+
### Model Optimizations
|
30 |
+
|
31 |
+
This model was obtained by quantizing the weights and activations to FP8 data type, ready for inference with vLLM.
|
32 |
+
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%. Only the weights and activations of the linear operators within transformers blocks are quantized.
|
33 |
+
|
34 |
+
## Deployment
|
35 |
+
|
36 |
+
### Use with vLLM
|
37 |
+
|
38 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
39 |
+
|
40 |
+
```python
|
41 |
+
from transformers import AutoTokenizer
|
42 |
+
from vllm import LLM, SamplingParams
|
43 |
+
|
44 |
+
max_model_len, tp_size = 4096, 1
|
45 |
+
model_name = "nm-testing/DeepSeek-R1-Distill-Llama-70B-FP8-Dynamic"
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
47 |
+
llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True)
|
48 |
+
sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
|
49 |
+
|
50 |
+
messages_list = [
|
51 |
+
[{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
|
52 |
+
]
|
53 |
+
|
54 |
+
prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
|
55 |
+
|
56 |
+
outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
|
57 |
+
|
58 |
+
generated_text = [output.outputs[0].text for output in outputs]
|
59 |
+
print(generated_text)
|
60 |
+
```
|
61 |
+
|
62 |
+
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
63 |
+
|
64 |
+
## Creation
|
65 |
+
|
66 |
+
This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.
|
67 |
+
|
68 |
+
|
69 |
+
```python
|
70 |
+
import argparse
|
71 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
72 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
73 |
+
from llmcompressor.transformers import oneshot
|
74 |
+
import os
|
75 |
+
|
76 |
+
def main():
|
77 |
+
parser = argparse.ArgumentParser(description='Quantize a transformer model to FP8')
|
78 |
+
parser.add_argument('--model_id', type=str, required=True,
|
79 |
+
help='The model ID from HuggingFace (e.g., "meta-llama/Meta-Llama-3-8B-Instruct")')
|
80 |
+
parser.add_argument('--save_path', type=str, default='.',
|
81 |
+
help='Custom path to save the quantized model. If not provided, will use model_name-FP8-dynamic')
|
82 |
+
args = parser.parse_args()
|
83 |
+
|
84 |
+
# Load model
|
85 |
+
model = AutoModelForCausalLM.from_pretrained(
|
86 |
+
args.model_id, device_map="auto", torch_dtype="auto", trust_remote_code=True,
|
87 |
+
)
|
88 |
+
tokenizer = AutoTokenizer.from_pretrained(args.model_id)
|
89 |
+
|
90 |
+
# Configure the quantization algorithm and scheme
|
91 |
+
recipe = QuantizationModifier(
|
92 |
+
targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"]
|
93 |
+
)
|
94 |
+
|
95 |
+
# Apply quantization
|
96 |
+
oneshot(model=model, recipe=recipe)
|
97 |
+
|
98 |
+
save_path = os.path.join(args.save_path, args.model_id.split("/")[1] + "-FP8-dynamic")
|
99 |
+
os.makedirs(save_path, exist_ok=True)
|
100 |
+
|
101 |
+
# Save to disk in compressed-tensors format
|
102 |
+
model.save_pretrained(save_path)
|
103 |
+
tokenizer.save_pretrained(save_path)
|
104 |
+
print(f"Model and tokenizer saved to: {save_path}")
|
105 |
+
|
106 |
+
if __name__ == "__main__":
|
107 |
+
main()
|
108 |
+
```
|
109 |
+
|
110 |
+
## Evaluation
|
111 |
+
|
112 |
+
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:
|
113 |
+
|
114 |
+
OpenLLM Leaderboard V1:
|
115 |
+
```
|
116 |
+
lm_eval \
|
117 |
+
--model vllm \
|
118 |
+
--model_args pretrained="nm-testing/DeepSeek-R1-Distill-Llama-70B-FP8-Dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
|
119 |
+
--tasks openllm \
|
120 |
+
--write_out \
|
121 |
+
--batch_size auto \
|
122 |
+
--output_path output_dir \
|
123 |
+
--show_config
|
124 |
+
```
|
125 |
+
|
126 |
+
OpenLLM Leaderboard V2:
|
127 |
+
```
|
128 |
+
lm_eval \
|
129 |
+
--model vllm \
|
130 |
+
--model_args pretrained="nm-testing/DeepSeek-R1-Distill-Llama-70B-FP8-Dynamic",dtype=auto,add_bos_token=False,max_model_len=4096,tensor_parallel_size=2,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
|
131 |
+
--apply_chat_template \
|
132 |
+
--fewshot_as_multiturn \
|
133 |
+
--tasks leaderboard \
|
134 |
+
--write_out \
|
135 |
+
--batch_size auto \
|
136 |
+
--output_path output_dir \
|
137 |
+
--show_config
|
138 |
+
|
139 |
+
```
|
140 |
+
|
141 |
+
### Accuracy
|
142 |
+
|
143 |
+
#### OpenLLM Leaderboard V1 evaluation scores
|
144 |
+
|
145 |
+
| Metric | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | nm-testing/DeepSeek-R1-Distill-Llama-70B-FP8-Dynamic |
|
146 |
+
|-----------------------------------------|:---------------------------------:|:-------------------------------------------:|
|
147 |
+
| ARC-Challenge (Acc-Norm, 25-shot) | 66.38 | 66.38 |
|
148 |
+
| GSM8K (Strict-Match, 5-shot) | 92.87 | 93.25 |
|
149 |
+
| HellaSwag (Acc-Norm, 10-shot) | 85.41 | 85.40 |
|
150 |
+
| MMLU (Acc, 5-shot) | 79.02 | 78.84 |
|
151 |
+
| TruthfulQA (MC2, 0-shot) | 57.24 | 57.54 |
|
152 |
+
| Winogrande (Acc, 5-shot) | 78.06 | 77.74 |
|
153 |
+
| **Average Score** | **76.49** | **76.52** |
|
154 |
+
| **Recovery (%)** | **100.00** | **100.03** |
|
155 |
+
|
156 |
+
#### OpenLLM Leaderboard V2 evaluation scores
|
157 |
+
|
158 |
+
|
159 |
+
| Metric | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | nm-testing/DeepSeek-R1-Distill-Llama-70B-FP8-Dynamic |
|
160 |
+
|---------------------------------------------------------|:---------------------------------:|:-------------------------------------------:|
|
161 |
+
| IFEval (Inst-and-Prompt Level Strict Acc, 0-shot) | 43.51 | 42.47 |
|
162 |
+
| BBH (Acc-Norm, 3-shot) | 35.30 | 33.66 |
|
163 |
+
| MMLU-Pro (Acc, 5-shot) | 41.35 | 41.05 |
|
164 |
+
| **Average Score** | **40.05** | **39.06** |
|
165 |
+
| **Recovery (%)** | **100.00** | **97.53** |
|
166 |
+
| Math-Hard (Exact-Match, 4-shot) | 5.55 | 9.03 |
|
167 |
+
| GPQA (Acc-Norm, 0-shot) | 1.64 | 1.58 |
|
168 |
+
| MUSR (Acc-Norm, 0-shot) | 13.28 | 13.80 |
|
169 |
+
|
170 |
+
Results on Math-Hard, GPQA, and MUSR are not considred for accuracy recovery calculation because the unquantized model has close to random prediction accuracy which doesn't provide a reliable baseline for recovery calculation.
|