Abstract
Traditional Large Language Models (LLMs) synthesize code in a single, monolithic autoregressive pass, a process that diverges significantly from the iterative, refinement-based workflow of human software engineers. We present LintSeq, a method that trains models to generate code through a sequence of syntactically valid edits. By leveraging a linter to procedurally deconstruct existing programs into logical building blocks, LintSeq enables models to learn the step-by-step evolution of code. Our results demonstrate that this approach significantly enhances performance on major benchmarks, improves output diversity, and allows models to scale more effectively with increased test-time compute.
Introduction
Most current code synthesis models are trained to predict programs from the first character to the last in one go. This "single-pass" approach suffers from two primary drawbacks: structural fragility, where a single early error can derail the entire program, and a lack of high-quality data capturing the fine-grained reasoning involved in program construction. While GitHub commits provide some history, they are often too coarse-grained or noisy for effective training. LintSeq addresses these issues by creating a synthetic "edit history" for any existing codebase.
Methodology: The LintSeq Algorithm
The core of LintSeq is a two-phase synthetic data generation process that refactors standard code datasets into sequences of "edit chunks."
- Phase I: Backward Sampling: The algorithm starts with a completed, functional program. It randomly selects a line for deletion and then employs a linter (e.g.,
pylint) to identify all other lines that are syntactically or logically dependent on that line. The entire dependent block is removed, ensuring the remaining code remains a valid, error-free intermediate state. - Phase II: Forward Edit Computation: Once the program is reduced to an empty state, the sequence is reversed. The standard Unix
difftool is used to calculate the precise insertions required to transition between the valid intermediate states identified in Phase I.
Models are fine-tuned to predict these diff blocks sequentially, utilizing special tokens to demarcate the start and end of specific edits. This forces the model to learn meaningful, linter-verified chunks of code rather than arbitrary token sequences.
Experimental Results and Scaling
We evaluated LintSeq using a suite of models, including our own "TinyCodeLM" (150M and 400M parameters) and larger off-the-shelf models like Phi-3 (3.8B) and Llama 3.1 (8B). Testing across benchmarks such as HumanEval and MBPP(+) revealed several key insights:
- Significant Performance Gains: The 150M parameter TinyCodeLM saw a 41% improvement in its HumanEval pass@1 score (from 9.1 to 12.8) simply by adopting the LintSeq training paradigm. Larger models consistently saw absolute gains of +2.3 to +4.3 points.
- Enhanced Diversity: Training on edit sequences encourages the model to explore multiple valid paths to a solution. This increased diversity makes repeated sampling strategies far more effective.
- Superior Scaling Laws: LintSeq models exhibit a better compute-to-performance trade-off. As test-time compute (FLOPs) increases through repeated sampling, LintSeq models outperform traditional baseline models of equivalent size.
Conclusion
LintSeq demonstrates that teaching language models to "write and refine" rather than just "write" leads to more robust and capable code synthesis. By using a linter to ground synthetic data in syntactic reality, we bridge the gap between autoregressive generation and human-like iterative development. Future work will look to expand this method to include deletions and complex refactoring, as well as extending the approach to languages beyond Python.
Summary updated