luofuli commited on
Commit
e67c544
1 Parent(s): 00aa52d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +270 -0
README.md ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- markdownlint-disable first-line-h1 -->
2
+ <!-- markdownlint-disable html -->
3
+ <!-- markdownlint-disable no-duplicate-header -->
4
+
5
+ <div align="center">
6
+ <img src="figures/logo.svg" width="60%" alt="DeepSeek LLM" />
7
+ </div>
8
+ <hr>
9
+ <div align="center">
10
+
11
+ <a href="https://www.deepseek.com/" target="_blank">
12
+ <img alt="Homepage" src="figures/badge.svg" />
13
+ </a>
14
+ <a href="https://chat.deepseek.com/" target="_blank">
15
+ <img alt="Chat" src="https://img.shields.io/badge/🤖%20Chat-DeepSeek%20LLM-536af5?color=536af5&logoColor=white" />
16
+ </a>
17
+ <a href="https://huggingface.co/deepseek-ai" target="_blank">
18
+ <img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-DeepSeek%20AI-ffc107?color=ffc107&logoColor=white" />
19
+ </a>
20
+
21
+ </div>
22
+
23
+ <div align="center">
24
+
25
+ <a href="https://discord.gg/Tc7c45Zzu5" target="_blank">
26
+ <img alt="Discord" src="https://img.shields.io/badge/Discord-DeepSeek%20AI-7289da?logo=discord&logoColor=white&color=7289da" />
27
+ </a>
28
+ <a href="figures/qr.jpeg" target="_blank">
29
+ <img alt="Wechat" src="https://img.shields.io/badge/WeChat-DeepSeek%20AI-brightgreen?logo=wechat&logoColor=white" />
30
+ </a>
31
+ <a href="https://twitter.com/deepseek_ai" target="_blank">
32
+ <img alt="Twitter Follow" src="https://img.shields.io/badge/Twitter-deepseek_ai-white?logo=x&logoColor=white" />
33
+ </a>
34
+
35
+ </div>
36
+
37
+ <div align="center">
38
+
39
+ <a href="LICENSE-CODE">
40
+ <img alt="Code License" src="https://img.shields.io/badge/Code_License-MIT-f5de53?&color=f5de53">
41
+ </a>
42
+ <a href="LICENSE-MODEL">
43
+ <img alt="Model License" src="https://img.shields.io/badge/Model_License-Model_Agreement-f5de53?&color=f5de53">
44
+ </a>
45
+ </div>
46
+
47
+
48
+ <p align="center">
49
+ <a href="#2-model-downloads">Model Download</a> |
50
+ <a href="#3-evaluation-results">Evaluation Results</a> |
51
+ <a href="#4-model-architecture">Model Architecture</a> |
52
+ <a href="#6-api-platform">API Platform</a> |
53
+ <a href="#8-license">License</a> |
54
+ <a href="#9-citation">Citation</a>
55
+ </p>
56
+
57
+ <p align="center">
58
+ <a href="paper.pdf"><b>Paper Link</b>👁️</a>
59
+ </p>
60
+
61
+ # DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model
62
+
63
+ ## 1. Introduction
64
+ Today, we’re introducing DeepSeek-V2, a strong Mixture-of-Experts (MoE) language model characterized by economical training and efficient inference. It comprises 236B total parameters, of which 21B are activated for each token. Compared with DeepSeek 67B, DeepSeek-V2 achieves stronger performance, and meanwhile saves 42.5% of training costs, reduces the KV cache by 93.3%, and boosts the maximum generation throughput to 5.76 times.
65
+
66
+ <p align="center">
67
+
68
+ <div style="display: flex; justify-content: center;">
69
+ <img src="figures/activationparameters.png" style="height:300px; width:auto; margin-right:10px">
70
+ <img src="figures/trainingcost.png" style="height:300px; width:auto; margin-left:10px">
71
+ </div>
72
+ </p>
73
+ We pretrained DeepSeek-V2 on a diverse and high-quality corpus comprising 8.1 trillion tokens. This comprehensive pretraining was followed by a process of Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL) to fully unleash the model's capabilities. The evaluation results validate the effectiveness of our approach as DeepSeek-V2 achieves remarkable performance on both standard benchmarks and open-ended generation evaluation.
74
+
75
+ ## 2. Model Downloads
76
+
77
+ <div align="center">
78
+
79
+ | **Model** | **Context Length** | **Download** |
80
+ | :------------: | :------------: | :------------: |
81
+ | DeepSeek-V2 | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-V2) |
82
+ | DeepSeek-V2-Chat(RL) | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat) |
83
+
84
+ </div>
85
+
86
+ Due to the constraints of HuggingFace, the open-source code currently experiences slower performance than our internal codebase when running on GPUs with Huggingface. To facilitate the efficient execution of our model, we offer a dedicated vllm solution that optimizes performance for running our model effectively.
87
+
88
+ ## 3. Evaluation Results
89
+ ### Base Model
90
+ #### Standard Benchmark
91
+
92
+ <div align="center">
93
+
94
+ | **Benchmark** | **Domain** | **LLaMA3 70B** | **Mixtral 8x22B** | **DeepSeek V1 (Dense-67B)** | **DeepSeek V2 (MoE-236B)** |
95
+ |:-----------:|:--------:|:------------:|:---------------:|:-------------------------:|:------------------------:|
96
+ | **MMLU** | English | 78.9 | 77.6 | 71.3 | 78.5 |
97
+ | **BBH** | English | 81.0 | 78.9 | 68.7 | 78.9 |
98
+ | **C-Eval** | Chinese | 67.5 | 58.6 | 66.1 | 81.7 |
99
+ | **CMMLU** | Chinese | 69.3 | 60.0 | 70.8 | 84.0 |
100
+ | **HumanEval** | Code | 52.4 | 39.0 | 42.7 | 40.9 |
101
+ | **MBPP** | Code | 68.6 | 64.2 | 57.4 | 66.6 |
102
+ | **GSM8K** | Math | 83.0 | 80.3 | 63.4 | 79.2 |
103
+ | **Math** | Math | 42.2 | 42.5 | 18.7 | 43.6 |
104
+
105
+ </div>
106
+ For more evaluation details, such as few-shot settings and prompts, please check our paper.
107
+
108
+ #### Context Window
109
+ <p align="center">
110
+ <img width="80%" src="figures/niah.png">
111
+ </p>
112
+
113
+ Evaluation results on the ``Needle In A Haystack`` (NIAH) tests. DeepSeek-V2 performs well across all context window lengths up to **128K**.
114
+
115
+ ### Chat Model
116
+ #### Standard Benchmark
117
+ <div align="center">
118
+
119
+ | Benchmark | Domain | QWen1.5 72B Chat | Mixtral 8x22B | LLaMA3 70B Instruct | DeepSeek V1 Chat (SFT) | DeepSeek V2 Chat(SFT) | DeepSeek V2 Chat(RL) |
120
+ |:-----------:|:----------------:|:------------------:|:---------------:|:---------------------:|:-------------:|:-----------------------:|:----------------------:|
121
+ | **MMLU** | English | 76.2 | 77.8 | 80.3 | 71.1 | 78.4 | 77.8 |
122
+ | **BBH** | English | 65.9 | 78.4 | 78.4 | 71.7 | 81.3 | 79.7 |
123
+ | **C-Eval** | Chinese | 82.2 | 60.0 | 67.9 | 65.2 | 80.9 | 78.0 |
124
+ | **CMMLU** | Chinese | 82.9 | 61.0 | 70.7 | 67.8 | 82.4 | 81.6 |
125
+ | **HumanEval** | Code | 68.9 | 75.0 | 76.2 | 73.8 | 76.8 | 81.1 |
126
+ | **MBPP** | Code | 43.4 | 64.4 | 69.8 | 61.4 | 70.4 | 72.0 |
127
+ | **LiveCodeBench (1201-0401)** | Code | 18.5 | 24.0 | 32.3 | 19.0 | 28.7 | 31.3 |
128
+ | **GSM8K** | Math | 81.9 | 87.9 | 93.2 | 84.1 | 90.8 | 92.2 |
129
+ | **Math** | Math | 40.6 | 49.8 | 48.5 | 32.6 | 52.7 | 53.9 |
130
+
131
+ </div>
132
+
133
+ #### English Open Ended Generation Evaluation
134
+ We evaluate our model on AlpacaEval 2.0 and MTBench, showing the competitive performance of DeepSeek-V2-Chat-RL on English conversation generation.
135
+ <p align="center">
136
+ <img width="50%" src="figures/mtbench.png" />
137
+ </p>
138
+
139
+ #### Chinese Open Ended Generation Evaluation
140
+ **Alignbench** (https://arxiv.org/abs/2311.18743)
141
+ <div align="center">
142
+
143
+ | **模型** | **开源/闭源** | **总分** | **中文推理** | **中文语言** |
144
+ | :---: | :---: | :---: | :---: | :---: |
145
+ | gpt-4-1106-preview | 闭源 | 8.01 | 7.73 | 8.29 |
146
+ | DeepSeek-V2 Chat(RL) | 开源 | 7.91 | 7.45 | 8.35 |
147
+ | erniebot-4.0-202404(文心一言) | 闭源 | 7.89 | 7.61 | 8.17 |
148
+ | DeepSeek-V2 Chat(SFT) | 开源 | 7.74 | 7.30 | 8.17 |
149
+ | gpt-4-0613 | 闭源 | 7.53 | 7.47 | 7.59 |
150
+ | erniebot-4.0-202312(文心一言) | 闭源 | 7.36 | 6.84 | 7.88 |
151
+ | moonshot-v1-32k-202404(月之暗面) | 闭源 | 7.22 | 6.42 | 8.02 |
152
+ | Qwen1.5-72B-Chat(通义千问) | 开源 | 7.19 | 6.45 | 7.93 |
153
+ | DeepSeek-67B-Chat | 开源 | 6.43 | 5.75 | 7.11 |
154
+ | Yi-34B-Chat(零一万物) | 开源 | 6.12 | 4.86 | 7.38 |
155
+ | gpt-3.5-turbo-0613 | 闭源 | 6.08 | 5.35 | 6.71 |
156
+
157
+ </div>
158
+
159
+ #### Coding Benchmarks
160
+ We evaluate our model on LiveCodeBench (0901-0401), a benchmark designed for live coding challenges. As illustrated, DeepSeek-V2 demonstrates considerable proficiency in LiveCodeBench, achieving a Pass@1 score that surpasses several other sophisticated models. This performance highlights the model's effectiveness in tackling live coding tasks.
161
+
162
+ <p align="center">
163
+ <img width="50%" src="figures/code_benchmarks.png">
164
+ </p>
165
+
166
+ ## 4. Model Architecture
167
+ DeepSeek-V2 adopts innovative architectures to guarantee economical training and efficient inference:
168
+ - For attention, we design IEAttn, which utilizes low-rank key-value union compression to eliminate the bottleneck of inference-time key-value cache, thus supporting efficient inference.
169
+ - For Feed-Forward Networks (FFNs), we adopt DeepSeekMoE architecture, a high-performance MoE architecture that enables training stronger models at lower costs.
170
+
171
+ <p align="center">
172
+ <img width="90%" src="figures/architecture.png" />
173
+ </p>
174
+
175
+ ## 5. Chat Website
176
+ You can chat with the DeepSeek-V2 on DeepSeek's official website: [chat.deepseek.com](https://chat.deepseek.com/sign_in)
177
+
178
+ ## 6. API Platform
179
+ We also provide OpenAI-Compatible API at DeepSeek Platform: [platform.deepseek.com](https://platform.deepseek.com/). Sign up for over millions of free tokens. And you can also pay-as-you-go at an unbeatable price.
180
+
181
+
182
+ <p align="center">
183
+ <img width="40%" src="figures/model_price.png">
184
+ </p>
185
+
186
+
187
+ ## 7. How to run locally
188
+ **To utilize DeepSeek-V2 in BF16 format for inference, 80GB*8 GPUs are required.**
189
+ ### Inference with Huggingface's Transformers
190
+ You can directly employ [Huggingface's Transformers](https://github.com/huggingface/transformers) for model inference.
191
+
192
+ ### Text Completion
193
+ ```python
194
+ import torch
195
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
196
+
197
+ model_name = "deepseek-ai/DeepSeek-V2"
198
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
199
+ # `max_memory` should be set based on your devices
200
+ max_memory = {i: "75GB" for i in range(8)}
201
+ model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map="auto", torch_dtype=torch.bfloat16, max_memory=max_memory)
202
+ model.generation_config = GenerationConfig.from_pretrained(model_name)
203
+ model.generation_config.pad_token_id = model.generation_config.eos_token_id
204
+
205
+ text = "An attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors. The output is"
206
+ inputs = tokenizer(text, return_tensors="pt")
207
+ outputs = model.generate(**inputs.to(model.device), max_new_tokens=100)
208
+
209
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
210
+ print(result)
211
+ ```
212
+
213
+ ### Chat Completion
214
+ ```python
215
+ import torch
216
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
217
+
218
+ model_name = "deepseek-ai/DeepSeek-V2-Chat-RL"
219
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
220
+ # `max_memory` should be set based on your devices
221
+ max_memory = {i: "75GB" for i in range(8)}
222
+ model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map="auto", torch_dtype=torch.bfloat16, max_memory=max_memory)
223
+ model.generation_config = GenerationConfig.from_pretrained(model_name)
224
+ model.generation_config.pad_token_id = model.generation_config.eos_token_id
225
+
226
+ messages = [
227
+ {"role": "user", "content": "Write a piece of quicksort code in C++"}
228
+ ]
229
+ input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
230
+ outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
231
+
232
+ result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
233
+ print(result)
234
+ ```
235
+ The complete chat template can be founded within `tokenizer_config.json` located in the huggingface model repository/
236
+ An example of chat template is as belows:
237
+ ```bash
238
+ <|begin▁of▁sentence|>User: {user_message_1}
239
+
240
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
241
+
242
+ Assistant:
243
+ ```
244
+ You can also add an optional system message:
245
+ ```bash
246
+ <|begin▁of▁sentence|>{system_message}
247
+
248
+ User: {user_message_1}
249
+
250
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
251
+
252
+ Assistant:
253
+ ```
254
+
255
+ ## 8. License
256
+ This code repository is licensed under [the MIT License](LICENSE-CODE). The use of DeepSeek-V2 Base/Chat models is subject to [the Model License](LICENSE-MODEL). DeepSeek-V2 series (including Base and Chat) supports commercial use.
257
+
258
+ ## 9. Citation
259
+ ```
260
+ @misc{deepseek-v2,
261
+ author = {DeepSeek-AI},
262
+ title = {DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model},
263
+ year = {2024},
264
+ note = {GitHub repository},
265
+ url = {https://github.com/deepseek-ai/deepseek-v2}
266
+ }
267
+ ```
268
+
269
+ ## 10. Contact
270
+ If you have any questions, please raise an issue or contact us at [[email protected]]([email protected]).