TL;DR
This paper introduces RepoMark, a novel framework for auditing whether code Large Language Models (LLMs) were trained on specific code repositories. RepoMark embeds imperceptible "marks" into code files, allowing authors to later verify if their code was used, achieving over 90% detection accuracy on small repositories with a strict 5% false detection rate.
What Problem Does This Paper Address?
The explosion of code LLMs, trained on vast amounts of open-source code, has brought efficiency but also significant ethical and legal concerns. Developers worry their code might be used for training without proper authorization or adherence to open-source licenses. The lack of transparency in how these models are trained makes it incredibly difficult for code authors to verify if their work was included, leading to potential copyright infringement and undermining the open-source community. Existing auditing methods either lack transparency, are inefficient for small codebases, or don't offer guarantees against falsely accusing model trainers.
Methods
RepoMark employs a contrastive marking approach. The core idea is to create multiple semantically identical versions of a code file, each with a subtle difference (a renamed local variable). The code author then publishes one version and keeps the others private. When an auditor wants to check if a specific code LLM was trained on this code, they feed all versions of the code to the LLM and observe its "loss" (how well it predicts the next token).
The key innovation lies in how RepoMark uses the ranks of these losses. If the LLM wasn't trained on the code, the loss ranks of the different versions will be uniformly distributed. However, if it was trained, the loss for the original (or a very similar) version will likely be lower, resulting in a biased rank. RepoMark aggregates these rank differences across multiple files in a repository using a hypothesis test to make a detection decision. This method is designed to be:
- Semantically Preserving: Changes are minimal and don't alter the code's functionality.
- Imperceptible: The modifications are hard for model trainers to detect and remove.
- Data Efficient: Works well even with a small number of code files.
- FDR Guaranteed: Provides a theoretical upper bound on the probability of falsely accusing a model trainer.
Datasets
The paper uses three common code datasets for evaluation:
- CodeParrot: Contains a large number of repositories.
- CodeSearchNet: Another widely used dataset for code-related tasks.
- CodeNet: A comprehensive dataset for AI for code.
The experiments focus on Python code but suggest the method is applicable to other languages.
Key Insights and Ideas
- Ranks over Raw Losses: Using the rank of the loss for different code variants, rather than the raw loss values, provides a more robust theoretical guarantee for auditing, especially when dealing with the complex and often unknown loss distributions of LLMs.
- Variable Renaming as a Subtle Mark: Renaming local variables is a clever way to introduce variations that are semantically equivalent but can still be detected by observing the LLM's behavior. It's subtle enough to be imperceptible to human reviewers or simple automated checks.
- Leveraging "Surprising" Variables: The method prioritizes renaming variables whose names are less predictable by an "oracle" LLM. This counter-intuitive approach actually allows for a larger set of semantically similar alternatives, improving the effectiveness of the marking.
- Scalability through Multiple Marks: For longer code files, RepoMark can inject multiple marks (by renaming multiple variables), significantly improving data efficiency and detection accuracy.
Key Results
- High Detection Accuracy: RepoMark achieves a detection success rate (DSR) of over 90% on small code repositories (10-50 files) with a strict 5% FDR guarantee.
- Outperforms Baselines: Existing methods, including membership inference and other data marking techniques, achieve significantly lower DSRs (below 55%) under identical settings.
- Good Imperceptibility: Marked code shows minimal impact on quality metrics like CodeBLEU and edit distance, with an average of only 3.61 tokens modified per 100 lines of code. The perplexity of marked code is also very close to unmarked code.
- Negligible Impact on Training: Training LLMs on RepoMark-marked datasets shows negligible impact on model performance (e.g., HumanEval Pass@k scores).
- Robustness: RepoMark demonstrates strong performance across different LLM architectures and datasets, and is robust to some basic countermeasures like variable renaming by model trainers.
Limitations and Future Work
- Oracle LLM Dependency: The effectiveness of the marking relies on the quality of the "oracle" LLM used to generate semantically equivalent variable names. The paper acknowledges that aggressive renaming by a model trainer can be a countermeasure, though it's difficult to do effectively without knowing the specific oracle used.
- Computational Cost: While practical, the detection process involves running inference on multiple code variants, which can be computationally intensive for very large repositories. The paper estimates costs for large projects to be under $120 USD per audit.
- Future Work: The authors suggest exploring more sophisticated countermeasures and further optimizing the detection process for even greater efficiency. They also highlight the potential for RepoMark to be integrated into broader data governance and copyright protection frameworks for AI development.
Summary updated