migtissera commited on
Commit
d34ba92
1 Parent(s): 486909d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +214 -0
README.md ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/blob/main/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 an intermediate checkpoint of DeepSeek-V2 with additional 6 trillion tokens. Through this continued pre-training, DeepSeek-Coder-V2 substantially enhances the coding and mathematical reasoning capabilities of DeepSeek-V2, while maintaining comparable performance in general language tasks. Compared to DeepSeek-Coder-33B, 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
+ <p align="center">
63
+ <img width="100%" src="https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/figures/performance.png?raw=true">
64
+ </p>
65
+
66
+
67
+ 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 [here](https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/supported_langs.txt).
68
+
69
+ ## 2. Model Downloads
70
+
71
+ 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.
72
+
73
+ <div align="center">
74
+
75
+ | **Model** | **#Total Params** | **#Active Params** | **Context Length** | **Download** |
76
+ | :-----------------------------: | :---------------: | :----------------: | :----------------: | :----------------------------------------------------------: |
77
+ | DeepSeek-Coder-V2-Lite-Base | 16B | 2.4B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Base) |
78
+ | DeepSeek-Coder-V2-Lite-Instruct | 16B | 2.4B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct) |
79
+ | DeepSeek-Coder-V2-Base | 236B | 21B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Base) |
80
+ | DeepSeek-Coder-V2-Instruct | 236B | 21B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct) |
81
+
82
+ </div>
83
+
84
+
85
+ ## 3. Chat Website
86
+
87
+ You can chat with the DeepSeek-Coder-V2 on DeepSeek's official website: [coder.deepseek.com](https://coder.deepseek.com/sign_in)
88
+
89
+ ## 4. API Platform
90
+ We also provide OpenAI-Compatible API at DeepSeek Platform: [platform.deepseek.com](https://platform.deepseek.com/), and you can also pay-as-you-go at an unbeatable price.
91
+ <p align="center">
92
+ <img width="40%" src="https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/figures/model_price.jpg?raw=true">
93
+ </p>
94
+
95
+
96
+ ## 5. How to run locally
97
+ **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.**
98
+
99
+ ### Inference with Huggingface's Transformers
100
+ You can directly employ [Huggingface's Transformers](https://github.com/huggingface/transformers) for model inference.
101
+
102
+ #### Code Completion
103
+ ```python
104
+ from transformers import AutoTokenizer, AutoModelForCausalLM
105
+ import torch
106
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)
107
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
108
+ input_text = "#write a quick sort algorithm"
109
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
110
+ outputs = model.generate(**inputs, max_length=128)
111
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
112
+ ```
113
+
114
+ #### Code Insertion
115
+ ```python
116
+ from transformers import AutoTokenizer, AutoModelForCausalLM
117
+ import torch
118
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)
119
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
120
+ input_text = """<|fim▁begin|>def quick_sort(arr):
121
+ if len(arr) <= 1:
122
+ return arr
123
+ pivot = arr[0]
124
+ left = []
125
+ right = []
126
+ <|fim▁hole|>
127
+ if arr[i] < pivot:
128
+ left.append(arr[i])
129
+ else:
130
+ right.append(arr[i])
131
+ return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"""
132
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
133
+ outputs = model.generate(**inputs, max_length=128)
134
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True)[len(input_text):])
135
+ ```
136
+
137
+ #### Chat Completion
138
+
139
+ ```python
140
+ from transformers import AutoTokenizer, AutoModelForCausalLM
141
+ import torch
142
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True)
143
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
144
+ messages=[
145
+ { 'role': 'user', 'content': "write a quick sort algorithm in python."}
146
+ ]
147
+ inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
148
+ # tokenizer.eos_token_id is the id of <|end▁of▁sentence|> token
149
+ 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)
150
+ print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
151
+ ```
152
+
153
+
154
+
155
+ The complete chat template can be found within `tokenizer_config.json` located in the huggingface model repository.
156
+
157
+ An example of chat template is as belows:
158
+
159
+ ```bash
160
+ <|begin▁of▁sentence|>User: {user_message_1}
161
+
162
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
163
+
164
+ Assistant:
165
+ ```
166
+
167
+ You can also add an optional system message:
168
+
169
+ ```bash
170
+ <|begin▁of▁sentence|>{system_message}
171
+
172
+ User: {user_message_1}
173
+
174
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
175
+
176
+ Assistant:
177
+ ```
178
+
179
+ ### Inference with vLLM (recommended)
180
+ 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.
181
+
182
+ ```python
183
+ from transformers import AutoTokenizer
184
+ from vllm import LLM, SamplingParams
185
+
186
+ max_model_len, tp_size = 8192, 1
187
+ model_name = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
188
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
189
+ llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)
190
+ sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
191
+
192
+ messages_list = [
193
+ [{"role": "user", "content": "Who are you?"}],
194
+ [{"role": "user", "content": "write a quick sort algorithm in python."}],
195
+ [{"role": "user", "content": "Write a piece of quicksort code in C++."}],
196
+ ]
197
+
198
+ prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
199
+
200
+ outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
201
+
202
+ generated_text = [output.outputs[0].text for output in outputs]
203
+ print(generated_text)
204
+ ```
205
+
206
+
207
+
208
+ ## 6. License
209
+
210
+ 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.
211
+
212
+
213
+ ## 7. Contact
214
+ If you have any questions, please raise an issue or contact us at [[email protected]]([email protected]).