Paper commentary
DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence
Open-source code models trained from scratch rival closed-source models on coding benchmarks
- Problem Strong code models have mostly stayed closed, so many researchers and developers cannot study or adapt them. Closed models block extensive open research.
- Method DeepSeek-Coder is a series of 1.3B to 33B code models trained from scratch on 2 trillion tokens. Instead of single files, it orders each repository's files by dependency and uses fill-in-the-middle training.
- Results DeepSeek-Coder-Base 33B reaches 50.3% average on multilingual HumanEval and 66.0% on MBPP. It leads the open-source comparisons on these benchmarks.
The open-model gap the series targets
Strong code models have mostly stayed closed, which keeps many researchers and developers from studying or adapting them. Every model in that family was trained from scratch on 2 trillion tokens covering 87 programming languages, rather than being adapted from a general checkpoint.
Three design choices distinguish the series: repository-organized pre-training data, a fill-in-the-middle objective trained alongside next-token prediction, and a context window extended to 16K. On the benchmarks the authors run, the base 33B model leads the open-source comparisons, and the instruct 33B model beats GPT-3.5 Turbo on most of them.
A later continued pre-training from a general 7B model, covered near the end of the article, targets natural language and math as well as code.
How the repository-level training corpus is built
The training mixture is 87% source code, 10% English code-related natural language and 3% Chinese natural language unrelated to code. Public GitHub repositories created before February 2023 were crawled and limited to 87 languages, and StarCoder-style rules then reduced the data to 32.8% of its original size. Those rules drop files whose average line length exceeds 100 characters or whose maximum line length exceeds 1000, and they apply separate checks to HTML, JSON and YAML files.
Earlier code models were trained on single files, so they never see how files in one project depend on each other. The authors extract invocation relations with regular expressions, covering import in Python, using in C# and include in C, and order the files so that each file's dependencies come earlier in the sample. Real repositories contain cycles, so Algorithm 1 uses a modified topological sort: within each disconnected subgraph it picks the file with minimal in-degree rather than requiring zero in-degree, then lowers the in-degree of that file's neighbours.
The ordered files are concatenated into one training sample, with a comment giving each file's path at its start so the path information survives.
Deduplication runs on whole repositories instead of individual files, because removing single files could break a repository's structure. The same near-deduplication algorithm is applied to the concatenated repository text as a single sample. Quality screening adds a compiler check and a quality model, and decontamination removes code that matches HumanEval, MBPP, GSM8K or MATH test strings on a 10-gram basis, or on exact 3-gram matches for shorter test strings.
The cleaned corpus totals 798 GB and 603 million files.
Fill-in-the-middle training and the PSM rate choice
Next-token prediction packs concatenated files into fixed-length entries, which teaches left-to-right generation but not filling a gap that is given text on both sides. FIM splits a document into three parts, shuffles them and joins them with special sentinel tokens, so the model learns to generate the missing middle from the prefix and suffix.
Two arrangements are used: PSM puts the prefix, then the suffix, then the middle, and SPM puts the suffix first.
The ablation uses DeepSeek-Coder-Base 1.3B on a Python subset of the training data and scores on HumanEval-FIM, a single-line task in which one line of a HumanEval solution is hidden. Four PSM settings are compared: a 0% FIM rate, a 50% FIM rate, a 100% FIM rate and a 50% MSP rate, where MSP is the masked span prediction strategy from T5.
The 100% FIM rate gave the highest HumanEval-FIM score but also the weakest ordinary code completion, which the authors read as a trade-off between the two abilities. At a 50% PSM rate the model outperformed MSP, so the authors kept PSM at a 0.5 FIM rate, applied at document level before packing. The ablation covers one model size on one language subset, so the chosen rate rests on that setting.
Architecture, optimizer and long-context extension
Each model is a decoder-only Transformer with Rotary Position Embedding, built on the DeepSeek LLM framework. The 33B model uses Grouped-Query-Attention with a group size of 8, and FlashAttention v2 speeds up the attention computation. Table 2 gives the 33B model a hidden size of 7168 and 62 hidden layers, against 2048 and 24 for the 1.3B model.
Training uses AdamW with beta values of 0.9 and 0.95, and batch sizes and learning rates are scaled with the laws reported for DeepSeek LLM. The schedule has 2000 warm-up steps and ends at a learning rate of 10% of the initial value, with each stage's rate scaled down from the previous stage's.
For long context, the authors apply a linear scaling strategy to RoPE, raising the scaling factor from 1 to 4 and the base frequency from 10000 to 100000. They train for 1000 further steps with batch size 512 and sequence length 16K, keeping the final pre-training learning rate. The modification is expected in theory to reach 64K tokens, but the authors observe the most reliable output within 16K.
Instruction tuning of the base models
Instruction tuning starts from the base model and uses helpful, impartial human instructions structured in the Alpaca format. A dedicated end-of-turn token marks the end of each dialogue turn in the training data. Training uses a cosine schedule with 100 warm-up steps, an initial learning rate of 1e-5, a batch of 4M tokens and 2B tokens in total.
The example shows multi-turn code generation working in practice, but it is one illustration and not a measured result.
Code generation on HumanEval, MBPP and DS-1000
HumanEval has 164 hand-written Python problems checked with test cases in a zero-shot setting, and MBPP has 500 problems in a few-shot setting. The authors extend HumanEval to seven further languages: C++, Java, PHP, TypeScript, C#, Bash and JavaScript. All models are decoded greedily, and baseline results are re-run in the same script and environment.
DeepSeek-Coder-Base 33B averages 50.3% on the multilingual HumanEval and 66.0% on MBPP. Against CodeLlama 34B, the authors report accuracy gains of 9% and 11%, and the 6.7B base model averages 44.7% on HumanEval against 41.0% for CodeLlama 34B.
DeepSeek-Coder-Instruct 33B averages 69.2% on multilingual HumanEval, above GPT-3.5-Turbo at 64.9%. On MBPP the same instruct model scores 70.0%, below GPT-3.5-Turbo at 70.8%, so the instruct comparison favours the model on HumanEval but not on MBPP.
DS-1000 contains 1,000 practical data science workflows across seven libraries, and generated code is executed against test cases. Base models are scored in the code completion setting, and DeepSeek-Coder-Base 33B averages 40.2%, against 34.3% for CodeLlama-Base 34B. The 1.3B base model averages 16.2% and the 6.7B base model 30.5%, so the averages rise with size.
Post-cutoff LeetCode contest problems
The LeetCode Contest benchmark uses 180 problems collected from July 2023 to January 2024, each with 100 test cases. The problems were taken from recent contests so that neither the problems nor their solutions were likely in pre-training data. Prompts put the problem description above a code template and ask the model to complete the code.
DeepSeek-Coder-Instruct 6.7B reaches Pass@1 of 19.4% and the 33B model 27.8%. The authors describe the 33B model as the only open-source model that beats GPT-3.5-Turbo here, which scores 23.3% overall. A substantial gap remains to GPT-4-Turbo at 40.6%.
Adding a directive to write a step-by-step outline before the code raises the 33B instruct model from 27.8% to 28.9% overall, and the 6.7B model from 19.4% to 21.1%. The 1.3B model stays at 7.2% with and without this prompt, and the authors attribute the benefit to first describing the code in detail, which helps with logic and dependencies.
Single-line infilling results
The single-line infilling benchmark covers Python, Java and JavaScript and uses line exact match accuracy. DeepSeek-Coder-Base 33B reaches a mean of 81.2% and the 7B row reaches 80.7%, against 69.0% for SantaCoder and 75.5% for CodeLlama-Base 13B. The smallest DeepSeek-Coder-Base row is labelled 1B in the table, while the text describes it as 1.3 billion parameters; its mean of 70.4% is above StarCoder and CodeLlama-Base 7B, both at 69.7%.
The authors recommend DeepSeek-Coder-Base 6.7B for completion tools, although Table 6 prints that row as 7B.
Cross-file completion and repository-level pre-training
Cross-file completion requires context from other files in the same repository, and CrossCodeEval covers Python, Java, TypeScript and C#. Its repositories were created from March to June 2023, after the February 2023 cutoff of the pre-training data. The evaluation caps the sequence at 2048 tokens and the output at 50 tokens, and adds up to 512 tokens of BM25-retrieved cross-file context.
With retrieval, DeepSeek-Coder-Base 6.7B reaches an exact match of 16.14% on Python, against 13.02% for CodeLlama-Base 7B with retrieval. Removing repository-level pre-training lowers exact match on Java (16.64% against 17.72%), TypeScript (13.23% against 14.03%) and C# (14.48% against 16.23%). Python is nearly level in that comparison, at 16.02% without repository-level pre-training against 16.14% with it.
The comparison involves 7B-scale models and one retrieval setup, so the effect is measured only under those conditions.
Program-aided math reasoning
Program-Aided Math Reasoning alternates a natural-language description of a step with code that executes it. Seven benchmarks are used: GSM8K, MATH, GSM-Hard, SVAMP, TabMWP, ASDiv and MAWPS. DeepSeek-Coder-Base 33B averages 65.8% across the seven, and the 6.7B base model averages 54.7%. CodeLlama-Base 34B averages 62.0% in the same table, so the 33B model is ahead on average.
Continued pre-training into DeepSeek-Coder-v1.5
DeepSeek-Coder-v1.5 continues pre-training from DeepSeek-LLM-7B Base with only the next-token objective and a 4K context. Its data mixture is 70% source code, with 10% Markdown and StackExchange, 7% code-related natural language, 7% math-related natural language and 6% bilingual Chinese-English text. Section 5 gives 2 trillion tokens for this continued pre-training, while the conclusion gives 2 billion tokens; both values are reported as printed.
Against the 6.7B base model, the v1.5 model drops slightly on HumanEval, 43.2% against 44.7%, and on MBPP, 60.4% against 60.6%. It gains on GSM8K, 62.4% against 43.2%, and on MMLU, 49.1% against 36.6%. The authors take this as evidence that a code model built on a strong general model keeps its coding ability while improving natural language understanding.
Limitations
The authors state that data contamination in the LeetCode Contest benchmark cannot be ruled out, since GPT-4-Turbo and DeepSeek-Coder scored higher on the July and August contests. The LeetCode set is small, at 180 problems, with 45 easy, 91 medium and 44 hard.
The 64K expectation for the long-context setting is theoretical, and the authors report reliable output only within 16K. The FIM rate choice rests on one 1.3B model trained on a Python subset and on single-line infilling. The v1.5 model trades a small coding drop for language gains, and the cross-file comparison covers only 7B-scale models.
Paper info
- Authors
- Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Y. Wu, Y. K. Li, Fuli Luo, Yingfei Xiong, Wenfeng Liang
- Venue
- arXiv · Preprint
- First published
- 2024-1-25
- Added
- 2026-11-12
- Updated
- 2024-1-26
- Version
- v2
- arXiv
- 2401.14196
- Category
- cs.SE · cs.CL · cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Y. Wu, Y. K. Li, Fuli Luo, Yingfei Xiong, Wenfeng Liang (2024). DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence. arXiv:2401.14196v2. https://arxiv.org/abs/2401.14196v2
BibTeX
@misc{guo2024deepseek,
title = {{DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence}},
author = {Daya Guo and Qihao Zhu and Dejian Yang and Zhenda Xie and Kai Dong and Wentao Zhang and Guanting Chen and Xiao Bi and Y. Wu and Y. K. Li and Fuli Luo and Yingfei Xiong and Wenfeng Liang},
year = {2024},
eprint = {2401.14196},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.14196v2}
}