UnitCoder: Scalable Code Synthesis from Pre-training Corpora

Ye Ma, Yunfan Shao, Peiji Li, Demin Song, Qipeng Guo, Linyang Li, Xipeng Qiu, Kai Chen2025

Abstract

UnitCoder is a scalable framework designed to bridge the gap between diverse but noisy pre-training code and high-quality synthetic instruction data. By leveraging automated unit test generation and an iterative "fix and refine" loop, UnitCoder transforms raw code snippets into a verified dataset of over 500,000 programs. This approach preserves the "long-tail" diversity of real-world programming while ensuring functional correctness. Experimental results demonstrate significant performance gains on complex coding benchmarks like BigCodeBench, with models like Llama 3.1-8B and InternLM2.5-7B seeing improvements of over 10 percentage points.

Introduction

Large Language Models (LLMs) thrive on high-quality data, but for code, such data is surprisingly scarce. Current sources generally fall into two categories: massive pre-training corpora (e.g., "The Stack"), which are diverse but riddled with bugs and incomplete logic, and instruction-based synthetic data (e.g., OSS-Instruct), which are high-quality but limited by a small set of human-written "seed" instructions. UnitCoder addresses this trade-off by automatically verifying and repairing raw code from pre-training corpora, enabling high-quality post-training without sacrificing diversity.

Methodology

The UnitCoder pipeline consists of three main stages designed to transform noisy raw code into high-quality training samples.

The UnitCoder pipeline overview, illustrating the three stages: Unit Test Initialization, Iterative Improvement, and Post-Training.
  1. Data Preparation & Test Generation: Syntactically valid functions are extracted from raw corpora using Abstract Syntax Tree (AST) parsing. A specialized Unit Test Generator (a fine-tuned Llama3-70B) then writes comprehensive test suites for these functions, targeting complex API calls and edge cases.
  2. Iterative Fix and Refine: Code and tests are executed in a secure sandbox. A Bug-fix Agent analyzes error traces to iteratively modify failing code until it passes. Once successful, a Refine Agent standardizes the style and adds explanatory docstrings to ensure readability.
  3. Post-Training: The resulting "cleaned" dataset (D_Unit) is used to fine-tune base models, ensuring they learn from code that is guaranteed to be functional.

Data and Evaluation

The researchers utilized The Stack pre-training dataset as a source, performing heavy deduplication to produce over 500,000 verifiable programs covering more than 370 unique Python API calls. Models were evaluated on standard benchmarks like HumanEval and MBPP for basic logic, as well as BigCodeBench (BCB) for complex, library-heavy tasks.

Results and Discussion

UnitCoder-synthesized data provides a substantial performance boost to base models, particularly on complex tasks. On the BigCodeBench benchmark, InternLM2.5-7B improved its score from 27.9% to 39.3%, while Llama3.1-8B increased from 31.0% to 40.4%.

Performance comparison on BigCodeBench (BCB) and BCB-Hard benchmarks, showing the impact of UnitCoder compared to other synthetic data methods.

Key insights from the study include:

  • Direct Supervision vs. Instruction Synthesis: By repairing existing code rather than generating it from scratch, UnitCoder preserves niche library usages and "long-tail" API patterns that LLMs might not generate independently.
  • The Power of the Loop: Iterative repair is more effective than simple filtering, as it retains the inherent diversity of the corpus.
  • Readability as a Feature: The refinement stage was found to be vital for zero-shot performance, helping models learn the structure and documentation of high-quality code.

Conclusion

While currently limited to Python, UnitCoder demonstrates the potential of using automated verification to scale high-quality code data. Future work includes extending the framework to other languages like C++, Java, or Rust, improving test oracle quality, and exploring more advanced reasoning models for the bug-fix agents.

Summary updated

BibTeX
@misc{ma2025unitcoder,
  author = {Ye Ma and Yunfan Shao and Peiji Li and Demin Song and Qipeng Guo and Linyang Li and Xipeng Qiu and Kai Chen},
  title = {{UnitCoder: Scalable Code Synthesis from Pre-training Corpora}},
  year = {2025},
  doi = {10.18653/v1/2025.emnlp-main.286},
}
Figure