luofuli commited on
Commit
b9a3eb3
1 Parent(s): c91ca88

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +296 -3
README.md CHANGED
@@ -1,3 +1,296 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- markdownlint-disable first-line-h1 -->
2
+ <!-- markdownlint-disable html -->
3
+ <!-- markdownlint-disable no-duplicate-header -->
4
+
5
+ <div align="center">
6
+ <img src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/logo.svg?raw=true" 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="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/badge.svg?raw=true" style="display: inline-block; vertical-align: middle;"/>
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?raw=true" style="display: inline-block; vertical-align: middle;"/>
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?raw=true" style="display: inline-block; vertical-align: middle;"/>
19
+ </a>
20
+
21
+ <a href="https://discord.gg/Tc7c45Zzu5" target="_blank">
22
+ <img alt="Discord" src="https://img.shields.io/badge/Discord-DeepSeek%20AI-7289da?logo=discord&logoColor=white&color=7289da?raw=true" style="display: inline-block; vertical-align: middle;"/>
23
+ </a>
24
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/qr.jpeg" target="_blank">
25
+ <img alt="Wechat" src="https://img.shields.io/badge/WeChat-DeepSeek%20AI-brightgreen?logo=wechat&logoColor=white?raw=true"style="display: inline-block; vertical-align: middle;" />
26
+ </a>
27
+ <a href="https://twitter.com/deepseek_ai" target="_blank">
28
+ <img alt="Twitter Follow" src="https://img.shields.io/badge/Twitter-deepseek_ai-white?logo=x&logoColor=white?raw=true" style="display: inline-block; vertical-align: middle;"/>
29
+ </a>
30
+ <a href="LICENSE-CODE">
31
+ <img alt="Code License" src="https://img.shields.io/badge/Code_License-MIT-f5de53?&color=f5de53?raw=true"style="display: inline-block; vertical-align: middle;">
32
+ </a>
33
+ <a href="LICENSE-MODEL">
34
+ <img alt="Model License" src="https://img.shields.io/badge/Model_License-Model_Agreement-f5de53?&color=f5de53?raw=true"style="display: inline-block; vertical-align: middle;">
35
+ </a>
36
+ </div>
37
+
38
+
39
+ <p align="center">
40
+ <a href="#2-model-downloads">Model Download</a> |
41
+ <a href="#3-evaluation-results">Evaluation Results</a> |
42
+ <a href="#4-model-architecture">Model Architecture</a> |
43
+ <a href="#6-api-platform">API Platform</a> |
44
+ <a href="#8-license">License</a> |
45
+ <a href="#9-citation">Citation</a>
46
+ </p>
47
+
48
+ <p align="center">
49
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/deepseek-v2-tech-report.pdf"><b>Paper Link</b>👁️</a>
50
+ </p>
51
+
52
+ # DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model
53
+
54
+ ## 1. Introduction
55
+ 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.
56
+
57
+ <p align="center">
58
+
59
+ <div style="display: flex; justify-content: center;">
60
+ <img src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/activationparameters.png?raw=true" style="height:300px; width:auto; margin-right:10px">
61
+ <img src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/trainingcost.png?raw=true" style="height:300px; width:auto; margin-left:10px">
62
+ </div>
63
+ </p>
64
+ 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.
65
+
66
+ ## 2. Model Downloads
67
+
68
+ <div align="center">
69
+
70
+ | **Model** | **Context Length** | **Download** |
71
+ | :------------: | :------------: | :------------: |
72
+ | DeepSeek-V2 | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-V2) |
73
+ | DeepSeek-V2-Chat (RL) | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat) |
74
+
75
+ </div>
76
+
77
+ 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.
78
+
79
+ ## 3. Evaluation Results
80
+ ### Base Model
81
+ #### Standard Benchmark
82
+
83
+ <div align="center">
84
+
85
+ | **Benchmark** | **Domain** | **LLaMA3 70B** | **Mixtral 8x22B** | **DeepSeek-V1 (Dense-67B)** | **DeepSeek-V2 (MoE-236B)** |
86
+ |:-----------:|:--------:|:------------:|:---------------:|:-------------------------:|:------------------------:|
87
+ | **MMLU** | English | 78.9 | 77.6 | 71.3 | 78.5 |
88
+ | **BBH** | English | 81.0 | 78.9 | 68.7 | 78.9 |
89
+ | **C-Eval** | Chinese | 67.5 | 58.6 | 66.1 | 81.7 |
90
+ | **CMMLU** | Chinese | 69.3 | 60.0 | 70.8 | 84.0 |
91
+ | **HumanEval** | Code | 48.2 | 53.1 | 45.1 | 48.8 |
92
+ | **MBPP** | Code | 68.6 | 64.2 | 57.4 | 66.6 |
93
+ | **GSM8K** | Math | 83.0 | 80.3 | 63.4 | 79.2 |
94
+ | **Math** | Math | 42.2 | 42.5 | 18.7 | 43.6 |
95
+
96
+ </div>
97
+ For more evaluation details, such as few-shot settings and prompts, please check our paper.
98
+
99
+ #### Context Window
100
+ <p align="center">
101
+ <img width="80%" src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/niah.png?raw=true">
102
+ </p>
103
+
104
+ Evaluation results on the ``Needle In A Haystack`` (NIAH) tests. DeepSeek-V2 performs well across all context window lengths up to **128K**.
105
+
106
+ ### Chat Model
107
+ #### Standard Benchmark
108
+ <div align="center">
109
+
110
+ | Benchmark | Domain | QWen1.5 72B Chat | Mixtral 8x22B | LLaMA3 70B Instruct | DeepSeek-V1 Chat (SFT) | DeepSeek-V2 Chat (SFT) | DeepSeek-V2 Chat (RL) |
111
+ |:-----------:|:----------------:|:------------------:|:---------------:|:---------------------:|:-------------:|:-----------------------:|:----------------------:|
112
+ | **MMLU** | English | 76.2 | 77.8 | 80.3 | 71.1 | 78.4 | 77.8 |
113
+ | **BBH** | English | 65.9 | 78.4 | 80.1 | 71.7 | 81.3 | 79.7 |
114
+ | **C-Eval** | Chinese | 82.2 | 60.0 | 67.9 | 65.2 | 80.9 | 78.0 |
115
+ | **CMMLU** | Chinese | 82.9 | 61.0 | 70.7 | 67.8 | 82.4 | 81.6 |
116
+ | **HumanEval** | Code | 68.9 | 75.0 | 76.2 | 73.8 | 76.8 | 81.1 |
117
+ | **MBPP** | Code | 52.2 | 64.4 | 69.8 | 61.4 | 70.4 | 72.0 |
118
+ | **LiveCodeBench (0901-0401)** | Code | 18.8 | 25.0 | 30.5 | 18.3 | 28.7 | 32.5 |
119
+ | **GSM8K** | Math | 81.9 | 87.9 | 93.2 | 84.1 | 90.8 | 92.2 |
120
+ | **Math** | Math | 40.6 | 49.8 | 48.5 | 32.6 | 52.7 | 53.9 |
121
+
122
+ </div>
123
+
124
+ #### English Open Ended Generation Evaluation
125
+ We evaluate our model on AlpacaEval 2.0 and MTBench, showing the competitive performance of DeepSeek-V2-Chat-RL on English conversation generation.
126
+ <p align="center">
127
+ <img width="50%" src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/mtbench.png?raw=true" />
128
+ </p>
129
+
130
+ #### Chinese Open Ended Generation Evaluation
131
+ **Alignbench** (https://arxiv.org/abs/2311.18743)
132
+ <div align="center">
133
+
134
+ | **模型** | **开源/闭源** | **总分** | **中文推理** | **中文语言** |
135
+ | :---: | :---: | :---: | :---: | :---: |
136
+ | gpt-4-1106-preview | 闭源 | 8.01 | 7.73 | 8.29 |
137
+ | DeepSeek-V2 Chat (RL) | 开源 | 7.91 | 7.45 | 8.35 |
138
+ | erniebot-4.0-202404 (文心一言) | 闭源 | 7.89 | 7.61 | 8.17 |
139
+ | DeepSeek-V2 Chat (SFT) | 开源 | 7.74 | 7.30 | 8.17 |
140
+ | gpt-4-0613 | 闭源 | 7.53 | 7.47 | 7.59 |
141
+ | erniebot-4.0-202312 (文心一言) | 闭源 | 7.36 | 6.84 | 7.88 |
142
+ | moonshot-v1-32k-202404 (月之暗面) | 闭源 | 7.22 | 6.42 | 8.02 |
143
+ | Qwen1.5-72B-Chat (通义千问) | 开源 | 7.19 | 6.45 | 7.93 |
144
+ | DeepSeek-67B-Chat | 开源 | 6.43 | 5.75 | 7.11 |
145
+ | Yi-34B-Chat (零一万物) | 开源 | 6.12 | 4.86 | 7.38 |
146
+ | gpt-3.5-turbo-0613 | 闭源 | 6.08 | 5.35 | 6.71 |
147
+
148
+ </div>
149
+
150
+ #### Coding Benchmarks
151
+ 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.
152
+
153
+ <p align="center">
154
+ <img width="50%" src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/code_benchmarks.png?raw=true">
155
+ </p>
156
+
157
+ ## 4. Model Architecture
158
+ DeepSeek-V2 adopts innovative architectures to guarantee economical training and efficient inference:
159
+ - For attention, we design MLA (Multi-head Latent Attention), which utilizes low-rank key-value union compression to eliminate the bottleneck of inference-time key-value cache, thus supporting efficient inference.
160
+ - For Feed-Forward Networks (FFNs), we adopt DeepSeekMoE architecture, a high-performance MoE architecture that enables training stronger models at lower costs.
161
+
162
+ <p align="center">
163
+ <img width="90%" src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/architecture.png?raw=true" />
164
+ </p>
165
+
166
+ ## 5. Chat Website
167
+ You can chat with the DeepSeek-V2 on DeepSeek's official website: [chat.deepseek.com](https://chat.deepseek.com/sign_in)
168
+
169
+ ## 6. API Platform
170
+ 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.
171
+
172
+
173
+ <p align="center">
174
+ <img width="40%" src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/model_price.png?raw=true">
175
+ </p>
176
+
177
+
178
+ ## 7. How to run locally
179
+ **To utilize DeepSeek-V2 in BF16 format for inference, 80GB*8 GPUs are required.**
180
+ ### Inference with Huggingface's Transformers
181
+ You can directly employ [Huggingface's Transformers](https://github.com/huggingface/transformers) for model inference.
182
+
183
+ #### Text Completion
184
+ ```python
185
+ import torch
186
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
187
+
188
+ model_name = "deepseek-ai/DeepSeek-V2"
189
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
190
+ # `max_memory` should be set based on your devices
191
+ max_memory = {i: "75GB" for i in range(8)}
192
+ # `device_map` cannot be set to `auto`
193
+ model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="sequential", torch_dtype=torch.bfloat16, max_memory=max_memory, attn_implementation="eager")
194
+ model.generation_config = GenerationConfig.from_pretrained(model_name)
195
+ model.generation_config.pad_token_id = model.generation_config.eos_token_id
196
+
197
+ 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"
198
+ inputs = tokenizer(text, return_tensors="pt")
199
+ outputs = model.generate(**inputs.to(model.device), max_new_tokens=100)
200
+
201
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
202
+ print(result)
203
+ ```
204
+
205
+ #### Chat Completion
206
+ ```python
207
+ import torch
208
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
209
+
210
+ model_name = "deepseek-ai/DeepSeek-V2-Chat"
211
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
212
+ # `max_memory` should be set based on your devices
213
+ max_memory = {i: "75GB" for i in range(8)}
214
+ # `device_map` cannot be set to `auto`
215
+ model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="sequential", torch_dtype=torch.bfloat16, max_memory=max_memory, attn_implementation="eager")
216
+ model.generation_config = GenerationConfig.from_pretrained(model_name)
217
+ model.generation_config.pad_token_id = model.generation_config.eos_token_id
218
+
219
+ messages = [
220
+ {"role": "user", "content": "Write a piece of quicksort code in C++"}
221
+ ]
222
+ input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
223
+ outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
224
+
225
+ result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
226
+ print(result)
227
+ ```
228
+
229
+ The complete chat template can be found within `tokenizer_config.json` located in the huggingface model repository.
230
+
231
+ An example of chat template is as belows:
232
+
233
+ ```bash
234
+ <|begin▁of▁sentence|>User: {user_message_1}
235
+
236
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
237
+
238
+ Assistant:
239
+ ```
240
+
241
+ You can also add an optional system message:
242
+
243
+ ```bash
244
+ <|begin▁of▁sentence|>{system_message}
245
+
246
+ User: {user_message_1}
247
+
248
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
249
+
250
+ Assistant:
251
+ ```
252
+
253
+ ### Inference with vLLM (recommended)
254
+ To utilize [vLLM](https://github.com/vllm-project/vllm) for model inference, please merge this Pull Request into your vLLM codebase: https://github.com/vllm-project/vllm/pull/4650.
255
+
256
+ ```python
257
+ from transformers import AutoTokenizer
258
+ from vllm import LLM, SamplingParams
259
+
260
+ max_model_len, tp_size = 8192, 8
261
+ model_name = "deepseek-ai/DeepSeek-V2-Chat"
262
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
263
+ llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)
264
+ sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
265
+
266
+ messages_list = [
267
+ [{"role": "user", "content": "Who are you?"}],
268
+ [{"role": "user", "content": "Translate the following content into Chinese directly: DeepSeek-V2 adopts innovative architectures to guarantee economical training and efficient inference."}],
269
+ [{"role": "user", "content": "Write a piece of quicksort code in C++."}],
270
+ ]
271
+
272
+ prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
273
+
274
+ outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
275
+
276
+ generated_text = [output.outputs[0].text for output in outputs]
277
+ print(generated_text)
278
+ ```
279
+
280
+ ## 8. License
281
+ 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.
282
+
283
+ ## 9. Citation
284
+ ```
285
+ @misc{deepseekv2,
286
+ title={DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model},
287
+ author={DeepSeek-AI},
288
+ year={2024},
289
+ eprint={2405.04434},
290
+ archivePrefix={arXiv},
291
+ primaryClass={cs.CL}
292
+ }
293
+ ```
294
+
295
+ ## 10. Contact
296
+ If you have any questions, please raise an issue or contact us at [service@deepseek.com](service@deepseek.com).