Abstract
CodeLLMs are widely used for code generation, yet their ability to handle repository-level dependencies remains underexplored. We introduce RepoExec, a benchmark for evaluating repository-level code generation, focusing on executability, functional correctness, and dependency utilization. Our study evaluates 18 models, revealing that retaining full dependency context yields the best performance, while smaller context sizes can be misleading. Pretrained LLMs excel in correctness but often reimplement dependencies, while instruction-tuned models better utilize dependencies but sometimes introduce unnecessary complexity. We propose an instruction-tuning dataset that improves dependency handling and introduce a new metric, Dependency Invocation Rate (DIR), to measure context utilization. Experiments show that instruction-tuned models improve DIR by over 10%, and multi-round debugging further enhances both correctness and dependency use. RepoExec provides a comprehensive framework to advance CodeLLMs for real-world applications.
Introduction
While Large Language Models for Code (CodeLLMs) have shown remarkable success on standalone function generation benchmarks like HumanEval, real-world software engineering is rarely isolated. Developers work within complex repositories where new code must seamlessly integrate with existing functions, classes, and variables. Existing repository-level benchmarks often suffer from a lack of executability, poor test quality, and a failure to penalize "code smells"—specifically the reimplementation of existing logic, which violates the "Don't Repeat Yourself" (DRY) principle.
The RepoExec Framework
To address these gaps, we introduce RepoExec, an executable benchmark designed to evaluate how well models utilize repository context. RepoExec consists of 355 complex problems derived from real-world repositories, accompanied by high-coverage unit tests (averaging 96.25% line coverage).
The framework utilizes a custom tool, pydepcall, to extract call graphs and dependencies. A critical innovation of RepoExec is the Dependency Invocation Rate (DIR) metric. DIR measures the ratio of provided dependencies actually invoked in the generated code, allowing us to distinguish between code that is merely "correct" and code that is "repository-aware."
Evaluating Contextual Impacts
A central question in repository-level generation is how much context is necessary. We evaluated models across three distinct context levels:
- Full Context: Includes entire function bodies and docstrings for dependencies.
- Medium Context: Includes only signatures and docstrings.
- Small Context: Includes only function signatures.
Our experiments revealed a surprising "reimplementation trap." Pretrained LLMs often pass functional tests by reimplementing logic already present in the context. Furthermore, we found that "Small" context often outperformed "Medium" context. We hypothesize that docstrings in the Medium setting can act as noise, misleading models into treating dependencies as examples to be copied rather than tools to be called.
Enhancing Model Performance
To improve dependency utilization, we developed a large-scale instruction-tuning dataset containing over 154,000 functions from highly-starred GitHub repositories. Fine-tuning models on this data led to a significant increase in DIR—for instance, Phi-2's DIR improved from 48.22% to 61.66%.
Additionally, we explored multi-round self-debugging. By providing models with error logs and allowing them to refine their code over three iterations, we observed substantial gains in functional correctness. For GPT-3.5, the Pass@1 score jumped from 27.04% to 41.97% through this iterative process.
Conclusion
RepoExec highlights the critical need for models to not only generate correct code but to do so by effectively leveraging existing repository infrastructure. Our findings suggest that while full context is ideal, the quality of context (e.g., avoiding noisy docstrings) and targeted instruction tuning are vital for reducing technical debt and improving the real-world utility of CodeLLMs. Future work will expand these evaluations to deeper dependency chains and a broader range of programming languages.
Summary updated