Abstract
Modern code completion models primarily rely on the Fill-in-the-Middle (FIM) paradigm to predict code segments based on surrounding context. However, these models often struggle when the developer's intent is underspecified. While instruction tuning has revolutionized conversational AI, applying it to code infilling often leads to performance degradation or "hallucinations." This paper presents Instruction-aware Fill-in-the-Middle (IFIM), a novel training paradigm that enables models to follow natural language directives within an infilling context. By introducing a dedicated instruction token and optimizing its placement, IFIM achieves significant gains in accuracy and intent alignment across multiple benchmarks.
Introduction
Current coding assistants like GitHub Copilot utilize FIM to predict code between a prefix and a suffix. A significant limitation arises when the surrounding code does not provide enough information to determine the specific logic required—for instance, whether a list should be filtered for null values or negative numbers.
Standard FIM models often fail to treat developer comments as explicit instructions. Conversely, standard instruction-tuning (SFT) can break the core infilling ability, causing models to repeat suffixes or generate irrelevant boilerplate. IFIM addresses this by providing a structured way for models to ingest intent alongside code context.
Methodology
The authors propose the IFIM paradigm, which extends the traditional FIM objective (<PRE> prefix <SUF> suffix <MID>) by incorporating a dedicated instruction component.
The "I-before-M" Paradigm
The core innovation of IFIM is the structural placement of the instruction. Through ablation studies, the researchers identified that the most effective configuration, termed "I-before-M," places the instruction immediately before the middle segment:
<PRE> prefix <SUF> suffix <INS> instruction <MID>
This positioning ensures the model "keeps the intent in mind" just before generating the target code.
Training and Data Synthesis
To train models in this paradigm, the authors constructed a dataset of 122.9k multi-language samples. They utilized GPT-4o to synthesize concise functional descriptions for existing code segments, creating a ground-truth mapping between instructions and code.
The training process involves fine-tuning FIM-pretrained models (such as DeepSeek-Coder and Qwen2.5-Coder) using this new format. To prevent knowledge forgetting, they repurposed low-frequency tokens from the existing vocabulary to serve as the <INS> delimiter.
Evaluation and Results
The researchers introduced two new benchmarks: IHumanEval (instruction-enhanced HumanEval) and IRepoMasterEval (IRME) (real-world repository-level code).
Performance Gains
IFIM demonstrated substantial improvements over base models:
- Instruction Following: On IHumanEval, DeepSeek-Coder (6.7B) saw its Pass@1 score rise from 84.6% to 93.6%.
- Real-World Complexity: On the IRME benchmark, performance nearly doubled, increasing from 10.9% to 21.1%.
- Backward Compatibility: Crucially, IFIM-trained models maintained or improved their performance even when no instructions were provided, outperforming base versions on standard infilling tasks.
Conflict Resolution
In experiments where instructions contradicted the surrounding code logic, IFIM-trained models followed the instruction 80.9% of the time, compared to only 54.4% for base models. This indicates a much stronger alignment with explicit developer intent.
Discussion and Conclusion
IFIM successfully bridges the gap between conversational instruction-following and structural code completion. Key insights include the necessity of structural separation (using the <INS> token) rather than relying on inline comments, and the critical importance of instruction positioning.
While the current work focuses on models in the 7B parameter range and is Python-heavy (70%), it provides a robust framework for future scaling. Future research will explore larger models, broader language support, and the integration of "wild" data such as commit messages and real-world developer comments to further refine the paradigm.
Summary updated