Introduction
Code Language Models (CLMs), such as GitHub Copilot and Qwen2.5-Coder, have revolutionized software development by training on vast repositories of public code. However, these datasets often contain "secrets"—hardcoded API keys, private emails, and credentials. During training, models frequently exhibit verbatim memorization, allowing attackers or curious users to prompt the model to reveal these sensitive strings. This creates a significant privacy and security liability for model providers.
The Problem: The High Cost of Forgetting
Traditionally, addressing leaked secrets requires data scrubbing followed by full-model retraining. This process is prohibitively expensive, often costing hundreds of thousands of dollars and requiring between 900 to 1800 A100 GPU days. While techniques like Differential Privacy (DP) or data de-duplication can mitigate risks, they must be implemented during the initial training phase. Once a model is deployed, a more efficient solution is needed to handle "Right to Be Forgotten" (RTBF) requests.
Methodology: Introducing CodeEraser
Researchers have developed CodeEraser, a surgical machine unlearning method designed to remove specific sensitive data without destroying the model's general coding utility. The authors compared three primary approaches:
- Vanilla Gradient Ascent (GA): Reverses the learning process for a sample, but often degrades the model's overall performance.
- Constraint-Based Unlearning (CU): Uses KL-divergence to keep the unlearned model close to the original, though it can still be too broad.
- CodeEraser (Selective Unlearning): This novel approach applies Gradient Ascent specifically to sensitive segments (the "secrets") while using Gradient Descent on the surrounding non-sensitive "context" to preserve structural understanding. A targeted KL-divergence constraint ensures the secrets become unpredictable rather than simply noisy.
Data and Insights
The study utilized a new Sensitive Memorization Dataset consisting of 50,000 high-risk samples confirmed to be memorized by models like CodeParrot and Qwen2.5-Coder. These samples include emails, IP addresses, and API keys identified via the detect-secrets tool.
One key insight is the 7% Rule: approximately 7% of training samples containing sensitive data are "high-risk" and easily extractable. Interestingly, the authors found that unlearning unique strings like API keys—which act as "noise" outliers—can actually improve model performance by allowing it to focus on representative code patterns.
Key Results
CodeEraser was evaluated on model families up to 7B parameters with impressive results:
- Effectiveness: It reduced memorization in the Qwen2.5-Coder-7B model by 93.89%.
- Utility Retention: The model maintained 99.99% of its original performance on benchmarks like HumanEval and MBPP. In contrast, vanilla unlearning methods often saw performance drops of nearly 30%.
- Efficiency: CodeEraser processes a request in approximately 47 seconds per sample, a massive improvement over the months required for retraining.
Limitations and Future Work
While highly effective for individual or small-batch requests, CodeEraser's utility begins to decline when unlearning thousands of samples simultaneously. Additionally, the method's success is dependent on the accuracy of secret detection tools. Future research will focus on scaling to "mass unlearning" and testing on models exceeding 70B parameters.
Summary updated