TL;DR
Large Language Models (LLMs) are great at generating code, but they often fail when libraries update, a common occurrence in real-world software development. This paper introduces VersiCode, a new dataset and evaluation framework to specifically test LLMs' ability to generate code that works with different library versions, revealing that even top models struggle with this crucial aspect.
What Problem Does This Paper Address?
Software development is a dynamic process. Libraries, the building blocks of most software, are constantly updated to fix bugs, add features, or improve performance. These updates often involve changes to how developers interact with the library's functions (its API). Current LLMs used for code generation are typically evaluated on static code tasks, ignoring this crucial versioning aspect. This means LLMs might generate code that was correct for an older library version but breaks with a newer one, or they might fail to adapt code when a library is updated. This gap significantly hinders the practical deployment of LLMs in real-world software engineering scenarios where managing library versions is a daily task.
Methods
The authors tackle this problem by introducing two new tasks and a novel evaluation metric:
- Version-Specific Code Completion (VSCC): This task involves masking parts of a code snippet that are sensitive to specific library versions (like function names or parameters) and asking the LLM to fill them in, given the library name and version.
- Version-Aware Code Migration (VACM): This task requires LLMs to take existing code written for one library version and adapt it to work with a different version of the same library. This mimics the real-world scenario of updating codebases when libraries are upgraded.
- Critical Diff Check (CDC@k): A new evaluation metric designed to go beyond simple code similarity. CDC@k checks for syntactic validity, correct API usage, parameter matching, and the proper use of constructs like
withstatements and keyword arguments, specifically focusing on differences between the generated code and the reference.
Datasets
The core contribution is the introduction of VersiCode, a large-scale, comprehensive dataset designed for version-controllable code generation.
- VersiCode: This dataset spans 9 years, covers over 300 Python libraries, and includes more than 2,000 versions. It's constructed from three main sources:
- Library Source Code: Official API examples from docstrings.
- Downstream Application Code: Code from top-tier research papers over the last decade.
- Stack Overflow: Q&A data explicitly mentioning library versions.
- Existing Benchmarks: The paper also compares performance against established code generation benchmarks like HumanEval and MBPP, highlighting VersiCode's unique focus on versioning.
Key Insights and Ideas
- LLMs struggle with temporal knowledge: Despite advancements, LLMs seem to have "outdated" programming knowledge, performing worse on code related to more recent library versions. This is counter-intuitive and suggests a need for models to better adapt to evolving codebases.
- Static metrics are insufficient: Traditional code similarity metrics fail to capture the nuances of version-specific code generation. The new CDC metric offers a more granular and reliable way to assess code quality in the context of evolving libraries.
- Context matters, but has limits: While providing version information and import statements generally helps LLMs, the benefit diminishes at line and block levels. For code migration, the context of code from another version can be helpful but sometimes even hinders performance for top models.
- Data source influences performance: Models perform better on Stack Overflow data, possibly due to its prevalence in pre-training data, suggesting potential data leakage issues.
Key Results
- Significant performance gap: Even state-of-the-art LLMs like GPT-4o and LLaMA3-70B perform significantly worse on VersiCode tasks compared to traditional benchmarks like HumanEval and MBPP, with a gap of at least 15 points.
- Version-specific challenges: LLMs struggle to generate code compatible with specific library versions and adapt code for API changes across versions.
- CDC metric shows promise: The CDC@1 metric demonstrates a strong correlation with dynamic analysis metrics (Pass@1), making it a reliable proxy for evaluating version-controllable code generation.
Limitations and Future Work
- Outdated knowledge: The paper highlights that LLMs' programming knowledge, particularly regarding newer libraries and APIs, appears outdated.
- Limited sensitivity to version instructions: LLMs don't always prioritize or heavily rely on version-specific instructions, especially at higher code granularities.
- Future Work: The authors suggest several directions:
- Enhancing pre-training with more recent codebases and version-tagged data.
- Utilizing continual learning and retrieval-augmented generation (RAG) for better adaptation.
- Developing more robust evaluation methods beyond static analysis.
- Creating a live, continuously updated version of VersiCode.
Summary updated