[Paper Review] RepoFusion: Training Code Models to Understand Your Repository
RepoFusion is a training framework that enables code models to leverage multiple repository-level contexts—such as imported files, sibling files, and parent classes—by using a Fusion-in-Decoder architecture to jointly attend to encoded context snippets, resulting in significantly improved single-line code completion performance. Despite being only 220M parameters, it outperforms much larger models like CodeGen-16B-multi (73× larger) and matches the performance of the 15.5B-parameter StarCoderBase model.
Despite the huge success of Large Language Models (LLMs) in coding assistants like GitHub Copilot, these models struggle to understand the context present in the repository (e.g., imports, parent classes, files with similar names, etc.), thereby producing inaccurate code completions. This effect is more pronounced when using these assistants for repositories that the model has not seen during training, such as proprietary software or work-in-progress code projects. Recent work has shown the promise of using context from the repository during inference. In this work, we extend this idea and propose RepoFusion, a framework to train models to incorporate relevant repository context. Experiments on single-line code completion show that our models trained with repository context significantly outperform much larger code models as CodeGen-16B-multi ($\sim73 imes$ larger) and closely match the performance of the $\sim 70 imes$ larger StarCoderBase model that was trained with the Fill-in-the-Middle objective. We find these results to be a novel and compelling demonstration of the gains that training with repository context can bring. We carry out extensive ablation studies to investigate the impact of design choices such as context type, number of contexts, context length, and initialization within our framework. Lastly, we release Stack-Repo, a dataset of 200 Java repositories with permissive licenses and near-deduplicated files that are augmented with three types of repository contexts. Additionally, we are making available the code and trained checkpoints for our work. Our released resources can be found at \url{https://huggingface.co/RepoFusion}.
Motivation & Objective
- To address the limitation of existing code LLMs in understanding repository-level context, such as imports, parent classes, and file relationships, which leads to inaccurate code completions.
- To improve code completion accuracy by training models to integrate multiple relevant code snippets from across a repository during inference.
- To demonstrate that smaller models can surpass larger models when trained with repository context, challenging the assumption that model scale alone determines performance.
- To release a new dataset, Stack-Repo, with 200 permissively licensed Java repositories and three types of repository context to support future research.
- To provide a reusable framework that is independent of retrieval mechanisms and can be applied to various code generation tasks.
Proposed method
- RepoFusion uses the Fusion-in-Decoder (FiD) architecture to combine multiple repository contexts by separately encoding each context with its surrounding context (excluding the target hole) and then jointly attending to them in the decoder.
- Each repository context is retrieved from relevant files (e.g., imported, sibling, or parent files) and augmented with a fixed-length window of surrounding code to preserve syntactic and semantic context.
- The model is fine-tuned on a next-token prediction objective using a combination of target holes and their corresponding multi-source repository contexts.
- The framework supports multiple context types (e.g., imports, siblings, parent classes), and the number and length of contexts are hyperparameters tuned via ablation studies.
- RepoFusion is trained end-to-end and is designed to be agnostic to the underlying retrieval mechanism, enabling integration with various retrieval strategies.
- The method enables the model to learn to prioritize and fuse diverse contextual signals from the repository, improving prediction accuracy.
Experimental results
Research questions
- RQ1Can training a small code model with repository-level context significantly improve code completion performance compared to larger models without such context?
- RQ2How do different types of repository contexts (e.g., imported files, sibling files) contribute to model performance?
- RQ3What is the optimal number and length of repository contexts for maximizing model performance?
- RQ4How does the initialization strategy and training objective affect the model’s ability to fuse multi-source context?
- RQ5Can a smaller model trained with repository context match or exceed the performance of much larger models trained without such context?
Key findings
- RepoFusion, a 220M-parameter model, outperforms the 16B-parameter CodeGen-16B-multi model on single-line code completion, despite being 73× smaller.
- RepoFusion closely matches the performance of the 15.5B-parameter StarCoderBase model, which was trained with the more complex Fill-in-the-Middle objective.
- Ablation studies show that leveraging information from diverse sources within the repository—such as imports and sibling files—is essential for performance gains.
- The number and length of repository contexts significantly impact performance, with optimal configurations found through systematic ablation.
- The model’s effectiveness is not solely due to context length or number of contexts, but rather the quality and diversity of the contextual signals it learns to fuse.
- The release of Stack-Repo, a dataset of 200 permissively-licensed Java repositories with three types of repository context, enables reproducibility and future research in retrieval-augmented code models.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.