casperhansen commited on
Commit
3918bbb
1 Parent(s): 11d47e2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +224 -0
README.md ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: deepseek-license
4
+ license_link: LICENSE
5
+ ---
6
+ <!-- markdownlint-disable html -->
7
+ <!-- markdownlint-disable no-duplicate-header -->
8
+
9
+ # Quantized details
10
+
11
+ This model was quantized on 4x A100 80GB with 1TB system ram. It was quantized using the chosen preferences from the coding dataset of OpenHermes 2.5: https://huggingface.co/datasets/alvarobartt/openhermes-preferences-coding
12
+
13
+ Quantized evaluations:
14
+ - int4 perplexity: 5.325
15
+
16
+ # Original Model Card
17
+
18
+ <br><br><br><br>
19
+
20
+ <div align="center">
21
+ <img src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/logo.svg?raw=true" width="60%" alt="DeepSeek-V2" />
22
+ </div>
23
+ <hr>
24
+ <div align="center" style="line-height: 1;">
25
+ <a href="https://www.deepseek.com/" target="_blank" style="margin: 2px;">
26
+ <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;"/>
27
+ </a>
28
+ <a href="https://chat.deepseek.com/" target="_blank" style="margin: 2px;">
29
+ <img alt="Chat" src="https://img.shields.io/badge/🤖%20Chat-DeepSeek%20V2-536af5?color=536af5&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
30
+ </a>
31
+ <a href="https://huggingface.co/deepseek-ai" target="_blank" style="margin: 2px;">
32
+ <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;"/>
33
+ </a>
34
+ </div>
35
+
36
+ <div align="center" style="line-height: 1;">
37
+ <a href="https://discord.gg/Tc7c45Zzu5" target="_blank" style="margin: 2px;">
38
+ <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;"/>
39
+ </a>
40
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/qr.jpeg?raw=true" target="_blank" style="margin: 2px;">
41
+ <img alt="Wechat" src="https://img.shields.io/badge/WeChat-DeepSeek%20AI-brightgreen?logo=wechat&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
42
+ </a>
43
+ <a href="https://twitter.com/deepseek_ai" target="_blank" style="margin: 2px;">
44
+ <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;"/>
45
+ </a>
46
+ </div>
47
+
48
+ <div align="center" style="line-height: 1;">
49
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-CODE" style="margin: 2px;">
50
+ <img alt="Code License" src="https://img.shields.io/badge/Code_License-MIT-f5de53?&color=f5de53" style="display: inline-block; vertical-align: middle;"/>
51
+ </a>
52
+ <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-MODEL" style="margin: 2px;">
53
+ <img alt="Model License" src="https://img.shields.io/badge/Model_License-Model_Agreement-f5de53?&color=f5de53" style="display: inline-block; vertical-align: middle;"/>
54
+ </a>
55
+ </div>
56
+ <p align="center">
57
+ <a href="#4-api-platform">API Platform</a> |
58
+ <a href="#5-how-to-run-locally">How to Use</a> |
59
+ <a href="#6-license">License</a> |
60
+ </p>
61
+
62
+
63
+ <p align="center">
64
+ <a href="https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/paper.pdf"><b>Paper Link</b>👁️</a>
65
+ </p>
66
+
67
+ # DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligence
68
+
69
+ ## 1. Introduction
70
+ 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.
71
+
72
+ <p align="center">
73
+ <img width="100%" src="https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/figures/performance.png?raw=true">
74
+ </p>
75
+
76
+
77
+ 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).
78
+
79
+ ## 2. Model Downloads
80
+
81
+ 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.
82
+
83
+ <div align="center">
84
+
85
+ | **Model** | **#Total Params** | **#Active Params** | **Context Length** | **Download** |
86
+ | :-----------------------------: | :---------------: | :----------------: | :----------------: | :----------------------------------------------------------: |
87
+ | DeepSeek-Coder-V2-Lite-Base | 16B | 2.4B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Base) |
88
+ | DeepSeek-Coder-V2-Lite-Instruct | 16B | 2.4B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct) |
89
+ | DeepSeek-Coder-V2-Base | 236B | 21B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Base) |
90
+ | DeepSeek-Coder-V2-Instruct | 236B | 21B | 128k | [🤗 HuggingFace](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct) |
91
+
92
+ </div>
93
+
94
+
95
+ ## 3. Chat Website
96
+
97
+ You can chat with the DeepSeek-Coder-V2 on DeepSeek's official website: [coder.deepseek.com](https://coder.deepseek.com/sign_in)
98
+
99
+ ## 4. API Platform
100
+ 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.
101
+ <p align="center">
102
+ <img width="40%" src="https://github.com/deepseek-ai/DeepSeek-Coder-V2/blob/main/figures/model_price.jpg?raw=true">
103
+ </p>
104
+
105
+
106
+ ## 5. How to run locally
107
+ **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.**
108
+
109
+ ### Inference with Huggingface's Transformers
110
+ You can directly employ [Huggingface's Transformers](https://github.com/huggingface/transformers) for model inference.
111
+
112
+ #### Code Completion
113
+ ```python
114
+ from transformers import AutoTokenizer, AutoModelForCausalLM
115
+ import torch
116
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)
117
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
118
+ input_text = "#write a quick sort algorithm"
119
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
120
+ outputs = model.generate(**inputs, max_length=128)
121
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
122
+ ```
123
+
124
+ #### Code Insertion
125
+ ```python
126
+ from transformers import AutoTokenizer, AutoModelForCausalLM
127
+ import torch
128
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)
129
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
130
+ input_text = """<|fim▁begin|>def quick_sort(arr):
131
+ if len(arr) <= 1:
132
+ return arr
133
+ pivot = arr[0]
134
+ left = []
135
+ right = []
136
+ <|fim▁hole|>
137
+ if arr[i] < pivot:
138
+ left.append(arr[i])
139
+ else:
140
+ right.append(arr[i])
141
+ return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"""
142
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
143
+ outputs = model.generate(**inputs, max_length=128)
144
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True)[len(input_text):])
145
+ ```
146
+
147
+ #### Chat Completion
148
+
149
+ ```python
150
+ from transformers import AutoTokenizer, AutoModelForCausalLM
151
+ import torch
152
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True)
153
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
154
+ messages=[
155
+ { 'role': 'user', 'content': "write a quick sort algorithm in python."}
156
+ ]
157
+ inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
158
+ # tokenizer.eos_token_id is the id of <|end▁of▁sentence|> token
159
+ 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)
160
+ print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
161
+ ```
162
+
163
+
164
+
165
+ The complete chat template can be found within `tokenizer_config.json` located in the huggingface model repository.
166
+
167
+ An example of chat template is as belows:
168
+
169
+ ```bash
170
+ <|begin▁of▁sentence|>User: {user_message_1}
171
+
172
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
173
+
174
+ Assistant:
175
+ ```
176
+
177
+ You can also add an optional system message:
178
+
179
+ ```bash
180
+ <|begin▁of▁sentence|>{system_message}
181
+
182
+ User: {user_message_1}
183
+
184
+ Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}
185
+
186
+ Assistant:
187
+ ```
188
+
189
+ ### Inference with vLLM (recommended)
190
+ 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.
191
+
192
+ ```python
193
+ from transformers import AutoTokenizer
194
+ from vllm import LLM, SamplingParams
195
+
196
+ max_model_len, tp_size = 8192, 1
197
+ model_name = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
198
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
199
+ llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)
200
+ sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
201
+
202
+ messages_list = [
203
+ [{"role": "user", "content": "Who are you?"}],
204
+ [{"role": "user", "content": "write a quick sort algorithm in python."}],
205
+ [{"role": "user", "content": "Write a piece of quicksort code in C++."}],
206
+ ]
207
+
208
+ prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
209
+
210
+ outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
211
+
212
+ generated_text = [output.outputs[0].text for output in outputs]
213
+ print(generated_text)
214
+ ```
215
+
216
+
217
+
218
+ ## 6. License
219
+
220
+ 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.
221
+
222
+
223
+ ## 7. Contact
224
+ If you have any questions, please raise an issue or contact us at [[email protected]]([email protected]).