# Qwen2.5-Coder Technical Report

Qwen2.5-Coder trains a code model family on a large code-heavy corpus

Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang and 18 more · arXiv · 2024-9-18

- **Problem** Open code models still trail proprietary systems such as Claude-3.5-Sonnet and GPT-4o, even though many open code families already score well on coding evaluations.
- **Method** Qwen2.5-Coder inherits the Qwen2.5 architecture and continues pretraining on a code-heavy mix of over 5.5 trillion tokens, then instruction-tunes with SFT and offline DPO.
- **Results** Qwen2.5-Coder-7B-Instruct reaches 51.9% PASS@1 on the Aider code editing benchmark, and the abstract reports state-of-the-art results on more than 10 benchmarks.

## The gap this series targets

The report starts from a gap between open code models and the strongest proprietary systems, Claude-3.5-Sonnet and GPT-4o. Code families such as StarCoder, CodeLlama, DeepSeek-Coder, CodeQwen1.5 and CodeStral already score well on coding evaluations, yet the authors argue that code models still fall behind, whether open or proprietary.

The proposed answer is Qwen2.5-Coder, which inherits the Qwen2.5 architecture and tokenizer and is trained further on code-specific data and carefully curated instruction sets. Six sizes are released, from 0.5B to 32B, so a developer can choose the size that fits the hardware at hand. The 32B instruct model is presented as the strongest open-source code model and as matching GPT-4o on coding; the benchmark sections below are where that reading can be checked.

The report frames the series around three goals: strong coding ability with reasonable general and math skill, a range of sizes, and practical use in code assistants and Artifacts. The technical story therefore has three parts: a large code-centric pretraining corpus, a staged training and instruction pipeline, and an evaluation covering base and instruct models.

## Architecture and tokenizer inherited from Qwen2.5

Qwen2.5-Coder takes its architecture from Qwen2.5 and varies only the scale, so the six models form one design at different sizes. Across all sizes the head size is 128, while the hidden size, layer count, numbers of query and key-value heads and intermediate size mostly grow with the model. The exceptions are the 1.5B model, whose intermediate size is larger than the other small models', and the 3B model, which has more layers than the 1.5B model.

The 7B and 32B models show the scale effect most clearly: hidden size 3,584 against 5,120, 28 query heads with 4 key-value heads against 40 with 8, and intermediate size 18,944 against 27,648. Smaller models use embedding tying and larger ones do not, and every size uses a vocabulary of 151,646 tokens and 5.5T trained tokens.

The tokenizer is inherited, but special tokens are added so that the model handles code structure explicitly. The end-of-text token, the three FIM markers, the padding token and the repository and file separator tokens have fixed IDs from 151643 to 151664. The FIM markers let the model see the code before and after a gap and generate the missing middle, while the repository tokens mark repository names and file boundaries for repo-level training.

## Building and mixing the pretraining corpus

The pretraining corpus, Qwen2.5-Coder-Data, has five data types: source code, text-code grounding data, synthetic data, math data and general text. Source code comes from GitHub repositories created before February 2024 across 92 programming languages, and the authors also draw on pull requests, commits, Jupyter notebooks and Kaggle datasets.

Rule-based filtering follows StarCoder2 and DS-Coder, and the same cleaning is applied to the non-file sources.

Text-code grounding data comes from Common Crawl and is filtered in a coarse-to-fine hierarchy, where each filter level is built from small models such as fastText. The authors report that larger filter models gave no clear benefit and suggest that small models attend more to surface-level features. Applying the filter in four iterations raised the average HumanEval and MBPP score of Qwen2.5-Coder-1.5B from 41.6% to 46.8% over the baseline.

Synthetic data was generated with CodeQwen1.5, and an executor kept only code that runs.

Math data comes from the Qwen2.5-Math pretraining corpus, and general text comes from the Qwen2.5 pretraining corpus with all code segments removed to keep the sources separate. The ratio sweep trained Qwen2.5-Coder-7B on three code, text and math mixtures; the 70:20:10 mixture averages 55.0, against 48.9 for the 85:15:5 mixture and 31.3 for the code-only 100:0:0 mixture.

The authors adopt 70% code, 20% text and 10% math, which the text also writes as 7:2:1, for a training set of 5.2 trillion tokens. The authors hypothesize that math and text data help code performance only once their share passes a certain threshold; the ratio sweep does not test this directly.

The corpus is described as over 5.5 trillion tokens in total, while the final training set is 5.2 trillion tokens, and the two figures are given side by side.

## Two pretraining stages: files, then repositories

File-level pretraining trains on individual code files with a maximum sequence length of 8,192 tokens, using next-token prediction together with FIM. Each FIM example is laid out as prefix, suffix and middle markers followed by the end-of-text token, so the middle span is the target the model learns to produce.

Repo-level pretraining extends the context from 8,192 to 32,768 tokens and raises the RoPE base frequency from 10,000 to 1,000,000. YARN is then applied so the model can handle sequences up to 131,072 tokens, beyond the 32,768-token training context.

Repo-level FIM packs a repository name, several file paths with their contents and a final file with the FIM markers into one sequence, following the format the authors take from StarCoder2. The overall pipeline runs file-level pretraining on 5.2T tokens, then repo-level pretraining on 300B tokens, then alignment into the instruct model.

## Instruction data and preference alignment

Instruction data starts with language identification: a CodeBERT-based classifier sorts samples into nearly 100 programming languages, and samples in long-tail languages are randomly thinned. Samples with little or no code are mostly removed, because the authors state that too many code-free samples hurt code generation on MultiPL-E, McEval and MdEval.

Further instruction pairs come from GitHub snippets: an LLM writes an instruction for a snippet of up to 1024 tokens, the code model writes the answer, and an LLM scorer filters weak pairs. Open McEval-Instruct data joins this seed set.

A multilingual multi-agent framework assigns one agent to each programming language, seeds each agent with language-specific instruction data and lets agents discuss in a structured way to write new instructions and solutions. The description adds a per-agent memory of past generations to avoid repeats, a cross-lingual knowledge exchange, a synergy metric and adaptive instruction generation for knowledge gaps.

Each instruction pair is scored on consistency, relevance, difficulty, code presence, correctness, style, clarity, comments and educational value, and the scores are combined with pre-defined weights. Code is first parsed into an abstract syntax tree, and snippets with parse errors are dropped; the multilingual sandbox then generates unit tests for self-contained snippets and runs them in isolated environments.

The sandbox has five parts: a language support module, a sample code repository, a unit test generator, a code execution engine and a result analyzer.

Supervised fine-tuning runs in two stages: tens of millions of lower-quality but diverse samples first, then millions of higher-quality samples chosen by rejection sampling, with an LLM scoring the best of several candidates. To keep long context, many instruction pairs are put in FIM form: tree-sitter parses the code, and basic logic blocks are extracted from the syntax tree as the middle span to infill.

After SFT the model is aligned with offline DPO, using test-case execution feedback for algorithm-like and self-contained snippets and an LLM judge for other snippets; the code preference data is combined with general data. Decontamination removes any training example with a 10-gram word-level overlap with the test data, and the removed datasets include HumanEval, MBPP, GSM8K and MATH.

## Base models on generation and reasoning

HumanEval has 164 hand-written Python tasks, and MBPP has 974 crowdsourced problems; EvalPlus extends HumanEval to HumanEval+ with 80 times more unique test cases. The authors also report MBPP 3-shot, which they use to monitor convergence because it reduces early metric swings. Qwen2.5-Coder-7B reached 61.6 on HumanEval and 53.0 on HumanEval+, against 54.9 and 47.6 for DS-Coder-33B-Base.

The text says the 7B model beats DS-Coder-33B on all five metrics, but in the extracted Table 5 the 7B row is lower on the BigCodeBench full column, 45.8 against 49.1, so that statement does not hold for every column.

BigCodeBench targets tool use and complex instruction following, and the base models are scored in completion mode on its full and hard subsets. The 32B base model reached 53.6 on the full subset and 26.4 on the hard subset, which the authors read as generalization beyond HumanEval and MBPP.

## Completion and multilingual code results

MultiPL-E covers eight languages: Python, C++, Java, PHP, TypeScript, C#, Bash and JavaScript, and the Qwen2.5-Coder base models score over 60% on five of them. The completion evaluation uses HumanEval-FIM, CrossCodeEval, CrossCodeLongEval, RepoEval and SAFIM, and the base models are trained with the FIM strategy for this purpose.

For cross-file completion, the cross-file context is truncated to 2048 tokens and built with BM25 search, and results are scored by Exact Match and Edit Similarity. The text ties these RepoEval gains to an average improvement of 7.9% EM and 4.2% ES over DS-Coder-33B-Base, and notes that function completion gives low EM for all models.

SAFIM is a syntax-aware fill-in-the-middle benchmark with 17,720 examples from 8,590 code files created after April 2022, and it is scored by pass@1 for algorithmic and control-flow blocks and by EM for API completion.

## Code reasoning, math and long context in base models

CRUXEval has 800 Python functions with input and output prediction tasks, and the base models use chain-of-thought prompting for simulated execution. Qwen2.5-Coder-7B reached 56.5 on CRUXEval-I and 56.0 on CRUXEval-O, and the 32B base model reached 62.5 and 69.4 on the same two settings. The authors credit this to the executable quality of the training code after cleaning.

On math, the 7B base model reached 46.6 on MATH and 83.9 on GSM8K, and the 32B model reached 57.2 and 91.1. The authors attribute the math strength to the Qwen2.5 foundation and to the mixing of code and math data during training. General language is checked with MMLU, MMLU-Redux, ARC-Challenge, TruthfulQA, WinoGrande and HellaSwag, and the authors say the general-language gains follow the same mixing logic.

Needle in the Code inserts a simple custom function at various positions in a repository and asks the model to reproduce it at the end. The authors report that Qwen2.5-Coder completes this task successfully within context lengths up to 128k.

## Instruct models on generation, editing and reasoning

On instruct-format MultiPL-E the 7B instruct model averages 76.5 and the 32B instruct model averages 79.4. The authors report that the 32B instruct model matches GPT-4o on coding; on this benchmark GPT-4o-2024-08-06 averages 79.1 and DS-Coder-V2-Instruct averages 79.9.

McEval covers 40 programming languages with 16,000 test cases, and the 32B instruct model is compared with open models of similar size. MdEval covers 18 languages with 1.2K buggy-code samples that include example tests; the 32B model is compared with larger models on it. CodeArena, an internal set of nearly 400 human-curated samples, is judged by GPT-4o, and the 32B model's win, tie and loss shares are 68.9%, 15.6% and 15.5% in Figure 9.

The 32B instruct model reached 75.2% and 83.4% on the two settings, and DS-Coder-V2-Instruct reached 70.0 and 75.1.

Aider uses 133 Python exercises from Exercism and checks whether generated edits pass unit tests. The 7B instruct model reached 51.9% PASS@1, which the authors report as above CodeStral-22B and DS-Coder-33B-Instruct.

## Limitations

The data-ratio sweep uses a single 7B model and three mixtures, so its conclusion about the ratio is limited to that setting. The hypothesis that math and text data help code only past a threshold is stated as future work, not tested.

The multi-agent framework, its memory bank, cross-lingual exchange and synergy metric are described, but no ablation or measured effect for them appears in the text. The Text-to-SQL section names Spider and BIRD as benchmarks, and the prose gives no scores, so no claim about Text-to-SQL results is made here.

The 'all five metrics' statement about the 7B base model against DS-Coder-33B does not hold for every column of Table 5 as extracted. On instruct-format MultiPL-E the 32B instruct model averages 79.4, slightly below DS-Coder-V2-Instruct at 79.9.

Needle in the Code is a synthetic task, and the reported success covers context lengths up to 128k only. Function completion gives low EM for all models, and the authors attribute this to the difficulty of matching multi-line snippets exactly.

## Paper info

- **Authors**: Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Keming Lu, Kai Dang, Yang Fan, Yichang Zhang, An Yang, Rui Men, Fei Huang, Bo Zheng, Yibo Miao, Shanghaoran Quan, Yunlong Feng, Xingzhang Ren, Xuancheng Ren, Jingren Zhou, Junyang Lin
- **Venue**: arXiv · Preprint
- **First published**: 2024-9-18
- **Added**: 2026-11-12
- **Updated**: 2024-11-12
- **Version**: v3
- **arXiv**: 2409.12186
- **Category**: cs.CL
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2409.12186v3) · [PDF ↗](https://arxiv.org/pdf/2409.12186v3)

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

Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Keming Lu, Kai Dang, Yang Fan, Yichang Zhang, An Yang, Rui Men, Fei Huang, Bo Zheng, Yibo Miao, Shanghaoran Quan, Yunlong Feng et al. (2024). Qwen2.5-Coder Technical Report. arXiv:2409.12186v3. https://arxiv.org/abs/2409.12186v3

**BibTeX**

```
@misc{hui2024qwen2,
  title = {{Qwen2.5-Coder Technical Report}},
  author = {Binyuan Hui and Jian Yang and Zeyu Cui and Jiaxi Yang and Dayiheng Liu and Lei Zhang and Tianyu Liu and Jiajun Zhang and Bowen Yu and Keming Lu and Kai Dang and Yang Fan and Yichang Zhang and An Yang and Rui Men and Fei Huang and Bo Zheng and Yibo Miao and Shanghaoran Quan and Yunlong Feng and Xingzhang Ren and Xuancheng Ren and Jingren Zhou and Junyang Lin},
  year = {2024},
  eprint = {2409.12186},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.12186v3}
}
```

## Other paper commentary

- [Language Models (Mostly) Know What They Know](https://refivu.com/en/papers/ffe245df-5662-4bfb-8c0b-899a38b87412-language-models-mostly-know-what-they-know.md)
- [Fine-Tuning Language Models from Human Preferences](https://refivu.com/en/papers/34e4ce82-039f-4763-a09e-5d0786987b71-fine-tuning-language-models-from-human-preferences.md)
- [Don't Stop Pretraining: Adapt Language Models to Domains and Tasks](https://refivu.com/en/papers/0864e409-68d0-4d61-98fd-5ab02360285a-don-t-stop-pretraining-adapt-language-models-to.md)
- [A Comprehensive Overview of Large Language Models](https://refivu.com/en/papers/4e2425c0-8669-49f7-80be-dd35ce0a70b2-a-comprehensive-overview-of-large-language-models.md)
- [The Curious Case of Neural Text Degeneration](https://refivu.com/en/papers/71a193c3-9d38-4eb3-b0de-39d943c746b0-the-curious-case-of-neural-text-degeneration.md)
- [A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT](https://refivu.com/en/papers/188edd2a-83fb-45cc-adcf-4ddabef4e43b-a-prompt-pattern-catalog-to-enhance-prompt-engineering.md)
- [Generating Sentences from a Continuous Space](https://refivu.com/en/papers/921b1922-5f2e-49a8-80cd-9df917da7fe7-generating-sentences-from-a-continuous-space.md)
- [EMNIST: an extension of MNIST to handwritten letters](https://refivu.com/en/papers/c0f15d57-13ab-41d2-b5f0-6b120e9504c7-emnist-an-extension-of-mnist-to-handwritten-letters.md)
- [PV-RCNN: Point-Voxel Feature Set Abstraction for 3D Object Detection](https://refivu.com/en/papers/698bbbfa-a9d9-4163-aa75-907d42df6ab3-pv-rcnn-point-voxel-feature-set-abstraction-for.md)
- [PoseCNN: A Convolutional Neural Network for 6D Object Pose Estimation in Cluttered Scenes](https://refivu.com/en/papers/66e8eadd-21d7-4e03-a7bb-1fbeda963ac8-posecnn-a-convolutional-neural-network-for-6d-object.md)
- [Aligning Books and Movies: Towards Story-like Visual Explanations by Watching Movies and Reading Books](https://refivu.com/en/papers/323226d2-ee36-4f99-996b-0fa1ffc4b7d8-aligning-books-and-movies-towards-story-like-visual.md)
- [Deep Learning based Recommender System: A Survey and New Perspectives](https://refivu.com/en/papers/a0b4c642-cc6f-408f-8e70-b8aaebc9c4da-deep-learning-based-recommender-system-a-survey-and.md)

## Terms in this paper

- [HumanEval](https://refivu.com/en/terms/3c3dbcadfdda-humaneval)
- [exact match](https://refivu.com/en/terms/f6e0295e5c92-exact-match)
- [MBPP](https://refivu.com/en/terms/717e657dd0b2-mbpp)
- [pass@1](https://refivu.com/en/terms/0b5f8fd75383-pass-1)
- [Direct Preference Optimization](https://refivu.com/en/terms/81ed2010f707-direct-preference-optimization)
- [Qwen2.5](https://refivu.com/en/terms/17e05888e36f-qwen2-5)
- [text-to-SQL](https://refivu.com/en/terms/9588cd33a188-text-to-sql)
- [Direct Preference Optimization (DPO)](https://refivu.com/en/terms/4314fe503882-direct-preference-optimization-dpo)
- [Edit Similarity](https://refivu.com/en/terms/33d882cc5d5a-edit-similarity)
- [Exact Match (EM)](https://refivu.com/en/terms/dbbdbf078db9-exact-match-em)
- [Fill-in-the-Middle (FIM)](https://refivu.com/en/terms/6ee1d6059d23-fill-in-the-middle-fim)
- [YARN](https://refivu.com/en/terms/3110363f5fbc-yarn)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/8282ea88-f013-4a5f-832a-687a740c2ff3-qwen2-5-coder-technical-report)
