guoday commited on
Commit
b409514
1 Parent(s): e346937

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +210 -0
README.md ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: deepseek-license
4
+ license_link: LICENSE
5
+ ---
6
+ <!-- markdownlint-disable first-line-h1 -->
7
+ <!-- markdownlint-disable html -->
8
+ <!-- markdownlint-disable no-duplicate-header -->
9
+
10
+ <div align="center">
11
+ <img src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/logo.svg?raw=true" width="60%" alt="DeepSeek-V2" />
12
+ </div>
13
+ <hr>
14
+ <div align="center" style="line-height: 1;">
15
+ <a href="https://www.deepseek.com/" target="_blank" style="margin: 2px;">
16
+ <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;"/>
17
+ </a>
18
+ <a href="https://chat.deepseek.com/" target="_blank" style="margin: 2px;">
19
+ <img alt="Chat" src="https://img.shields.io/badge/🤖%20Chat-DeepSeek%20V2-536af5?color=536af5&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
20
+ </a>
21
+ <a href="https://huggingface.co/deepseek-ai" target="_blank" style="margin: 2px;">
22
+ <img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-DeepSeek%20AI-ffc107?color=ffc107&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
23
+ </a>
24
+ </div>
25
+
26
+ <div align="center" style="line-height: 1;">
27
+ <a href="https://discord.gg/Tc7c45Zzu5" target="_blank" style="margin: 2px;">
28
+ <img alt="Discord" src="https://img.shields.io/badge/Discord-DeepSeek%20AI-7289da?logo=discord&logoColor=white&color=7289da" style="display: inline-block; vertical-align: middle;"/>
29
+ </a>
30
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/qr.jpeg?raw=true" target="_blank" style="margin: 2px;">
31
+ <img alt="Wechat" src="https://img.shields.io/badge/WeChat-DeepSeek%20AI-brightgreen?logo=wechat&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
32
+ </a>
33
+ <a href="https://twitter.com/deepseek_ai" target="_blank" style="margin: 2px;">
34
+ <img alt="Twitter Follow" src="https://img.shields.io/badge/Twitter-deepseek_ai-white?logo=x&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
35
+ </a>
36
+ </div>
37
+
38
+ <div align="center" style="line-height: 1;">
39
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-CODE" style="margin: 2px;">
40
+ <img alt="Code License" src="https://img.shields.io/badge/Code_License-MIT-f5de53?&color=f5de53" style="display: inline-block; vertical-align: middle;"/>
41
+ </a>
42
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-MODEL" style="margin: 2px;">
43
+ <img alt="Model License" src="https://img.shields.io/badge/Model_License-Model_Agreement-f5de53?&color=f5de53" style="display: inline-block; vertical-align: middle;"/>
44
+ </a>
45
+ </div>
46
+ <p align="center">
47
+ <a href="#4-api-platform">API Platform</a> |
48
+ <a href="#5-how-to-run-locally">How to Use</a> |
49
+ <a href="#6-license">License</a> |
50
+ </p>
51
+
52
+
53
+ <p align="center">
54
+ <a href="https://github.com/deepseek-ai/DeepSeek-Coder-V2/paper.pdf"><b>Paper Link</b>👁️</a>
55
+ </p>
56
+
57
+ # DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligence
58
+
59
+ ## 1. Introduction
60
+ We present DeepSeek-Coder-V2, an open-source Mixture-of-Experts (MoE) code language model that achieves performance comparable to GPT4-Turbo in code-specific tasks. Specifically, DeepSeek-Coder-V2 is further pre-trained from DeepSeek-Coder-V2-Base with 6 trillion tokens sourced from a high-quality and multi-source corpus. Through this continued pre-training, DeepSeek-Coder-V2 substantially enhances the coding and mathematical reasoning capabilities of DeepSeek-Coder-V2-Base, while maintaining comparable performance in general language tasks. Compared to DeepSeek-Coder, DeepSeek-Coder-V2 demonstrates significant advancements in various aspects of code-related tasks, as well as reasoning and general capabilities. Additionally, DeepSeek-Coder-V2 expands its support for programming languages from 86 to 338, while extending the context length from 16K to 128K.
61
+
62
+ In standard benchmark evaluations, DeepSeek-Coder-V2 achieves superior performance compared to closed-source models such as GPT4-Turbo, Claude 3 Opus, and Gemini 1.5 Pro in coding and math benchmarks. The list of supported programming languages can be found in the paper.
63
+
64
+ ## 2. Model Downloads
65
+
66
+ We release the DeepSeek-Coder-V2 with 16B and 236B parameters based on the [DeepSeekMoE](https://arxiv.org/pdf/2401.06066) framework, which has actived parameters of only 2.4B and 21B , including base and instruct models, to the public.
67
+
68
+ <div align="center">
69
+
70
+ | **Model** | **#Total Params** | **#Active Params** | **Context Length** | **Download** |
71
+ | :-----------------------------: | :---------------: | :----------------: | :----------------: | :----------------------------------------------------------: |
72
+ | DeepSeek-Coder-V2-Lite-Base | 16B | 2.4B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Base) |
73
+ | DeepSeek-Coder-V2-Lite-Instruct | 16B | 2.4B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct) |
74
+ | DeepSeek-Coder-V2-Base | 236B | 21B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Base) |
75
+ | DeepSeek-Coder-V2-Instruct | 236B | 21B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct) |
76
+
77
+ </div>
78
+
79
+
80
+ ## 3. Chat Website
81
+
82
+ You can chat with the DeepSeek-Coder-V2 on DeepSeek's official website: [chat.deepseek.com](https://chat.deepseek.com/sign_in)
83
+
84
+ ## 4. API Platform
85
+ 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.
86
+
87
+ <p align="center">
88
+ <img width="40%" src="https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/figures/model_price.jpg?raw=true">
89
+ </p>
90
+
91
+
92
+ ## 5. How to run locally
93
+ **Here, we provide some examples of how to use DeepSeek-Coder-V2-Lite model. If you want to utilize DeepSeek-Coder-V2 in BF16 format for inference, 80GB*8 GPUs are required.**
94
+
95
+ ### Inference with Huggingface's Transformers
96
+ You can directly employ [Huggingface's Transformers](https://github.com/huggingface/transformers) for model inference.
97
+
98
+ #### Code Completion
99
+ ```python
100
+ from transformers import AutoTokenizer, AutoModelForCausalLM
101
+ import torch
102
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)
103
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
104
+ input_text = "#write a quick sort algorithm"
105
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
106
+ outputs = model.generate(**inputs, max_length=128)
107
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
108
+ ```
109
+
110
+ #### Code Insertion
111
+ ```python
112
+ from transformers import AutoTokenizer, AutoModelForCausalLM
113
+ import torch
114
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)
115
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
116
+ input_text = """<|fim▁begin|>def quick_sort(arr):
117
+ if len(arr) <= 1:
118
+ return arr
119
+ pivot = arr[0]
120
+ left = []
121
+ right = []
122
+ <|fim▁hole|>
123
+ if arr[i] < pivot:
124
+ left.append(arr[i])
125
+ else:
126
+ right.append(arr[i])
127
+ return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"""
128
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
129
+ outputs = model.generate(**inputs, max_length=128)
130
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True)[len(input_text):])
131
+ ```
132
+
133
+ #### Chat Completion
134
+
135
+ ```python
136
+ from transformers import AutoTokenizer, AutoModelForCausalLM
137
+ import torch
138
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True)
139
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
140
+ messages=[
141
+ { 'role': 'user', 'content': "write a quick sort algorithm in python."}
142
+ ]
143
+ inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
144
+ # tokenizer.eos_token_id is the id of <|EOT|> token
145
+ outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
146
+ print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
147
+ ```
148
+
149
+
150
+
151
+ The complete chat template can be found within `tokenizer_config.json` located in the huggingface model repository.
152
+
153
+ An example of chat template is as belows:
154
+
155
+ ```bash
156
+ <|begin▁of▁sentence|>User: {user_message_1}
157
+
158
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
159
+
160
+ Assistant:
161
+ ```
162
+
163
+ You can also add an optional system message:
164
+
165
+ ```bash
166
+ <|begin▁of▁sentence|>{system_message}
167
+
168
+ User: {user_message_1}
169
+
170
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
171
+
172
+ Assistant:
173
+ ```
174
+
175
+ ### Inference with vLLM (recommended)
176
+ 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.
177
+
178
+ ```python
179
+ from transformers import AutoTokenizer
180
+ from vllm import LLM, SamplingParams
181
+
182
+ max_model_len, tp_size = 8192, 1
183
+ model_name = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
184
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
185
+ llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)
186
+ sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
187
+
188
+ messages_list = [
189
+ [{"role": "user", "content": "Who are you?"}],
190
+ [{"role": "user", "content": "write a quick sort algorithm in python."}],
191
+ [{"role": "user", "content": "Write a piece of quicksort code in C++."}],
192
+ ]
193
+
194
+ prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
195
+
196
+ outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
197
+
198
+ generated_text = [output.outputs[0].text for output in outputs]
199
+ print(generated_text)
200
+ ```
201
+
202
+
203
+
204
+ ## 6. License
205
+
206
+ This code repository is licensed under [the MIT License](https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/LICENSE-CODE). The use of DeepSeek-Coder-V2 Base/Instruct models is subject to [the Model License](https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/LICENSE-MODEL). DeepSeek-Coder-V2 series (including Base and Instruct) supports commercial use.
207
+
208
+
209
+ ## 7. Contact
210
+ If you have any questions, please raise an issue or contact us at [[email protected]]([email protected]).