Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- fp8
|
4 |
+
- vllm
|
5 |
+
license: other
|
6 |
+
license_name: deepseek-license
|
7 |
+
license_link: https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/LICENSE-MODEL
|
8 |
+
---
|
9 |
+
|
10 |
+
# DeepSeek-Coder-V2-Instruct-FP8
|
11 |
+
|
12 |
+
## Model Overview
|
13 |
+
- **Model Architecture:** DeepSeek-Coder-V2-Instruct
|
14 |
+
- **Input:** Text
|
15 |
+
- **Output:** Text
|
16 |
+
- **Model Optimizations:**
|
17 |
+
- **Weight quantization:** FP8
|
18 |
+
- **Activation quantization:** FP8
|
19 |
+
- **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Meta-Llama-3-7B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-7B-Instruct), this models is intended for assistant-like chat.
|
20 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
|
21 |
+
- **Release Date:** 7/22/2024
|
22 |
+
- **Version:** 1.0
|
23 |
+
- **License(s):** [deepseek-license](https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/LICENSE-MODEL)
|
24 |
+
- **Model Developers:** Neural Magic
|
25 |
+
|
26 |
+
Quantized version of [DeepSeek-Coder-V2-Instruct](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct).
|
27 |
+
<!-- It achieves an average score of 73.19 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 73.48. -->
|
28 |
+
It achieves an average score of 88.98 on the [HumanEval+](https://github.com/openai/human-eval?tab=readme-ov-file) benchmark, whereas the unquantized model achieves 87.63.
|
29 |
+
|
30 |
+
### Model Optimizations
|
31 |
+
|
32 |
+
This model was obtained by quantizing the weights and activations of [DeepSeek-Coder-V2-Instruct](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct) to FP8 data type, ready for inference with vLLM >= 0.5.2.
|
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%. In particular, this model can now be loaded and evaluated with only 4xH100 GPUs, as opposed to 8.
|
34 |
+
|
35 |
+
Only the weights and activations of the linear operators within transformers blocks are quantized. Symmetric per-tensor quantization is applied, in which a single linear scaling maps the FP8 representations of the quantized weights and activations.
|
36 |
+
[AutoFP8](https://github.com/neuralmagic/AutoFP8) is used for quantization with 512 sequences of UltraChat.
|
37 |
+
|
38 |
+
## Deployment
|
39 |
+
|
40 |
+
### Use with vLLM
|
41 |
+
|
42 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
43 |
+
|
44 |
+
```python
|
45 |
+
from vllm import LLM, SamplingParams
|
46 |
+
from transformers import AutoTokenizer
|
47 |
+
|
48 |
+
model_id = "neuralmagic/DeepSeek-Coder-V2-Instruct-FP8"
|
49 |
+
|
50 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
|
51 |
+
|
52 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
53 |
+
|
54 |
+
messages = [
|
55 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
56 |
+
{"role": "user", "content": "Who are you?"},
|
57 |
+
]
|
58 |
+
|
59 |
+
prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
60 |
+
|
61 |
+
llm = LLM(model=model_id, trust_remote_code=True, max_model_len=4096)
|
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 aslo 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 applying [AutoFP8 with calibration samples from ultrachat](https://github.com/neuralmagic/AutoFP8/blob/147fa4d9e1a90ef8a93f96fc7d9c33056ddc017a/example_dataset.py) with expert gates kept at original precision, as presented in the code snipet below.
|
74 |
+
Notably, a custom device map had to be used, as the model was being incorrectly loaded otherwise.
|
75 |
+
Although AutoFP8 was used for this particular model, Neural Magic is transitioning to using [llm-compressor](https://github.com/vllm-project/llm-compressor) which supports several quantization schemes and models not supported by AutoFP8.
|
76 |
+
|
77 |
+
```python
|
78 |
+
from datasets import load_dataset
|
79 |
+
from transformers import AutoTokenizer
|
80 |
+
|
81 |
+
from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
|
82 |
+
|
83 |
+
pretrained_model_dir = "deepseek-ai/DeepSeek-Coder-V2-Instruct"
|
84 |
+
quantized_model_dir = "DeepSeek-Coder-V2-Instruct-FP8"
|
85 |
+
|
86 |
+
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=4096)
|
87 |
+
tokenizer.pad_token = tokenizer.eos_token
|
88 |
+
|
89 |
+
ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
|
90 |
+
examples = [tokenizer.apply_chat_template(batch["messages"], tokenize=False) for batch in ds]
|
91 |
+
examples = tokenizer(examples, padding=True, truncation=True, return_tensors="pt").to("cuda")
|
92 |
+
|
93 |
+
quantize_config = BaseQuantizeConfig(
|
94 |
+
quant_method="fp8",
|
95 |
+
activation_scheme="static"
|
96 |
+
ignore_patterns=["re:.*lm_head"],
|
97 |
+
)
|
98 |
+
|
99 |
+
device_map = {
|
100 |
+
"model.embed_tokens": 0,
|
101 |
+
"model.layers.0": 0,
|
102 |
+
}
|
103 |
+
for i in range(1, 60):
|
104 |
+
device_map[f"model.layers.{i}"] = i//8
|
105 |
+
|
106 |
+
device_map["model.norm"] = 7
|
107 |
+
device_map["lm_head"] = 7
|
108 |
+
|
109 |
+
model = AutoFP8ForCausalLM.from_pretrained(
|
110 |
+
pretrained_model_dir, quantize_config=quantize_config, device_map = device_map
|
111 |
+
)
|
112 |
+
model.quantize(examples)
|
113 |
+
model.save_quantized(quantized_model_dir)
|
114 |
+
```
|
115 |
+
|
116 |
+
## Evaluation
|
117 |
+
|
118 |
+
The model was evaluated on the [HumanEval+](https://github.com/openai/human-eval?tab=readme-ov-file) benchmark with the [Neural Magic fork](https://github.com/neuralmagic/evalplus) of the [EvalPlus implementation of HumanEval+](https://github.com/evalplus/evalplus) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
|
119 |
+
```
|
120 |
+
python codegen/generate.py --model neuralmagic/DeepSeek-Coder-V2-Instruct-FP8 --temperature 0.2 --n_samples 50 --resume --root ~ --dataset humaneval
|
121 |
+
python evalplus/sanitize.py ~/humaneval/neuralmagic--DeepSeek-Coder-V2-Instruct-FP8_vllm_temp_0.2
|
122 |
+
evalplus.evaluate --dataset humaneval --samples ~/humaneval/neuralmagic--DeepSeek-Coder-V2-Instruct-FP8_vllm_temp_0.2-sanitized
|
123 |
+
```
|
124 |
+
|
125 |
+
### Accuracy
|
126 |
+
|
127 |
+
#### HumanEval+ evaluation scores
|
128 |
+
<table>
|
129 |
+
<tr>
|
130 |
+
<td><strong>Benchmark</strong>
|
131 |
+
</td>
|
132 |
+
<td><strong>DeepSeek-Coder-V2-Instruct</strong>
|
133 |
+
</td>
|
134 |
+
<td><strong>DeepSeek-Coder-V2-Instruct-FP8(this model)</strong>
|
135 |
+
</td>
|
136 |
+
<td><strong>Recovery</strong>
|
137 |
+
</td>
|
138 |
+
</tr>
|
139 |
+
<tr>
|
140 |
+
<td>base pass@1
|
141 |
+
</td>
|
142 |
+
<td>88.2
|
143 |
+
</td>
|
144 |
+
<td>87.6
|
145 |
+
</td>
|
146 |
+
<td>99.32%
|
147 |
+
</td>
|
148 |
+
</tr>
|
149 |
+
<tr>
|
150 |
+
<td>base pass@10
|
151 |
+
</td>
|
152 |
+
<td>92.3
|
153 |
+
</td>
|
154 |
+
<td>94.7
|
155 |
+
</td>
|
156 |
+
<td>102.60%
|
157 |
+
</td>
|
158 |
+
</tr>
|
159 |
+
<tr>
|
160 |
+
<td>base+extra pass@1
|
161 |
+
</td>
|
162 |
+
<td>83.3
|
163 |
+
</td>
|
164 |
+
<td>83.2
|
165 |
+
</td>
|
166 |
+
<td>99.88%
|
167 |
+
</td>
|
168 |
+
</tr>
|
169 |
+
<tr>
|
170 |
+
<td>base+extra pass@10
|
171 |
+
</td>
|
172 |
+
<td>86.7
|
173 |
+
</td>
|
174 |
+
<td>90.4
|
175 |
+
</td>
|
176 |
+
<td>104.27%
|
177 |
+
</td>
|
178 |
+
</tr>
|
179 |
+
<tr>
|
180 |
+
<td><strong>Average</strong>
|
181 |
+
</td>
|
182 |
+
<td><strong>87.63</strong>
|
183 |
+
</td>
|
184 |
+
<td><strong>88.98</strong>
|
185 |
+
</td>
|
186 |
+
<td><strong>101.5%</strong>
|
187 |
+
</td>
|
188 |
+
</tr>
|
189 |
+
</table>
|