Archive of AI

Source Snapshot / 2024-06-17-deepseek-coder-v2-open-source-2

GitHub - deepseek-ai/DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligence · GitHub

Linked event: 2024-06-17 · DeepSeek Open-Sources 236B MoE Coding Model DeepSeek-Coder-V2, Matching Proprietary Flagships in Coding and Math

Publisher
DeepSeek / GitHub
Archived
2026-11-23
Capture Method
Direct page capture
HTTP / SHA-256
200 / 044070c4622c80ac
Original URL
Open source ↗
Wayback Backup
Wayback archive ↗
This page preserves a plain-text static snapshot against link rot. When citing figures, tables, or full legal terms, verify against the original URL and Wayback Machine archive.

[来源关键摘录] Official repository for DeepSeek-Coder-V2 open-source models (16B Lite and 236B MoE).

[正文前段节选] Skip to content

Navigation Menu

Appearance settings

You signed in with another tab or window. Reload to refresh your session.

You signed out in another tab or window. Reload to refresh your session.

You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Repository navigation

DeepSeek-Coder-V2

NotificationsYou must be signed in to change notification settings

Fork1.1k (1.1k)

Star7k (7k)You must be signed in to star a repository

DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligence

MIT, License licenses found

Custom properties

Report repository

BranchesTags

Open more actions menu

Latest commit

Folders and files

Last commit message

Last commit date

LICENSE-CODE

LICENSE-MODEL

supported_langs.txt

View all files

Repository files navigation

Model Download |

Evaluation Results |

API Platform |

How to Use |

Paper Link👁️

1. Introduction

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.

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.

2. Model Downloads

We release the DeepSeek-Coder-V2 with 16B and 236B parameters based on the DeepSeekMoE framework, which has actived parameters of only 2.4B and 21B , including base and instruct models, to the public.

#Total Params

#Active Params

Context Length

DeepSeek-Coder-V2-Lite-Base

🤗 HuggingFace

DeepSeek-Coder-V2-Lite-Instruct

DeepSeek-Coder-V2-Base

DeepSeek-Coder-V2-Instruct

3. Evaluation Results

3.1 Code Generation

LiveCodeBench

Closed-Source Models

Gemini-1.5-Pro

Claude-3-Opus

GPT-4-Turbo-1106

GPT-4-Turbo-0409

Open-Source Models

DeepSeek-Coder-Instruct

Llama3-Instruct

3.2 Code Completion

RepoBench (Python)

RepoBench (Java)

HumanEval FIM

DeepSeek-Coder-Base

3.3 Code Fixing

3.4 Mathematical Reasoning

Math Odyssey

3.5 General Natural Language

DeepSeek-V2-Lite Chat

DeepSeek-Coder-V2-Lite Instruct

DeepSeek-V2 Chat

DeepSeek-Coder-V2 Instruct

ARC-Challenge

NaturalQuestions

AlpaceEval 2.0

3.6 Context Window

Evaluation results on the Needle In A Haystack (NIAH) tests. DeepSeek-Coder-V2 performs well across all context window lengths up to 128K.

4. Chat Website

You can chat with the DeepSeek-Coder-V2 on DeepSeek's official website: chat.deepseek.com

5. API Platform

We also provide OpenAI-Compatible API at DeepSeek Platform: platform.deepseek.com, and you can also pay-as-you-go at an unbeatable price.

6. How to run locally

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.

Inference with Huggingface's Transformers

You can directly employ Huggingface's Transformers for model inference.

Code Completion

from transformers import AutoTokenizer, AutoModelForCausalLM

import torch

tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True)

model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()

input_text = "#write a quick sort algorithm"

inputs = tokenizer(input_text, return_tensors="pt").to(model.device)

outputs = model.generate(**inputs, max_length=128)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Code Insertion

input_text = """<|fim▁begin|>def quick_sort(arr):

if len(arr) <= 1:

pivot = arr[0]

<|fim▁hole|>

if arr[i] < pivot:

left.append(arr[i])

right.append(arr[i])

return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"""

print(tokenizer.decode(outputs[0], skip_special_tokens=True)[len(input_text):])

Chat Completion

tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True)

model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()

{ 'role': 'user', 'content': "write a quick sort algorithm in python."}

inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)

# tokenizer.eos_token_id is the id of <|end▁of▁sentence|> token

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)

print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))

The complete chat template can be found within tokenizer_config.json located in the huggingface model repository.

An example of chat template is as belows:

<|begin▁of▁sentence|>User: {user_message_1}

Assistant: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2}

You can also add an optional system message:

<|begin▁of▁sentence|>{system_message}

User: {user_message_1}

In the last round of dialogue, note that "Assistant:" has no space after the colon. Adding a space might cause the following issues on the 16B-Lite model:

English questions receiving Chinese responses.

Responses containing garbled text.

Responses repeating excessively.

Older versions of Ollama had this bug (see #12), but it has been fixed in the latest version.

Inference with SGLang (recommended)

SGLang currently supports MLA optimizations, FP8 (W8A8), FP8 KV Cache, and Torch Compile, offering the best latency and throughput among open-source frameworks. Here are some example commands to launch an OpenAI API-compatible server:

# BF16, tensor parallelism = 8

python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-Coder-V2-Instruct --tp 8 --trust-remote-code

# BF16, w/ torch.compile (The compilation can take several minutes)

python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct --trust-remote-code --enable-torch-compile

# FP8, tensor parallelism = 8, FP8 KV cache

python3 -m sglang.launch_server --model neuralmagic/DeepSeek-Coder-V2-Instruct-FP8 --tp 8 --trust-remote-code --kv-cache-dtype fp8_e5m2

After launching the server, you can query it with OpenAI API

import openai

client = openai.Client(

base_url="http://127.0.0.1:30000/v1", api_key="EMPTY")

# Chat completion

response = client.chat.completions.create(

model="default",

{"role": "system", "content": "You are a helpful AI assistant"},

{"role": "user", "content": "List 3 countries and their capitals."},

temperature=0,

max_tokens=64,

print(response)

Inference with vLLM (recommended)

To utilize vLLM for model inference, please merge this Pull Request into your vLLM codebase: vllm-project/vllm#4650.

from transformers import AutoTokenizer

from vllm import LLM, SamplingParams

max_model_len, tp_size = 8192, 1

model_name = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_name)

llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)

[...内容已截断,完整版请查看原文或 Wayback 快照]