TL;DR
PrivCode is the first differentially private (DP) synthesizer specifically designed for code datasets, overcoming the "utility-privacy" trade-off that usually cripples DP-trained models. By using a two-stage "evolutionary" framework—training a small "junior" model with privacy constraints and then using its synthetic output to fine-tune a larger "premium" model—PrivCode generates high-quality, functional code while providing a theoretical guarantee against the leakage of sensitive information like API keys or PII.
What Problem Does This Paper Address?
Large Language Models (LLMs) are notorious for memorizing their training data. In the context of code, this is a security nightmare: models fine-tuned on proprietary or sensitive repos can inadvertently "leak" private API keys, hardcoded credentials, or Personally Identifiable Information (PII) during inference.
While Differential Privacy (DP), specifically DP-SGD, offers a mathematical solution to bound this leakage, applying it to code generation is exceptionally difficult for two reasons:
- Structural Brittleness: Unlike natural language, code follows strict syntactic and semantic rules. The noise injected by DP-SGD often breaks this structure, resulting in code that simply won't compile.
- The Utility Gap: Large models require significant noise to satisfy DP guarantees, which leads to a massive drop in performance (utility). Fine-tuning a 7B or 33B model under DP often results in a model that is significantly worse than its non-private counterpart.
Methods
PrivCode introduces a two-stage Evolutionary Paradigm:
- Stage 1: Privacy-Sanitizing: The authors train a "Junior LLM" (e.g., Qwen2.5-Coder-1.5B) on the sensitive dataset using DP-SGD. To prevent the noise from destroying code structure, they introduce the PrivSA (Privacy-free Syntax-Aware) module. This module uses an Abstract Syntax Tree (AST) to identify structural tokens and applies a specialized KL-divergence loss to ensure the model maintains the "shape" of valid code.
- Stage 2: Utility-Boosting: The Junior model generates a synthetic, "privacy-cleansed" version of the dataset. This data is put through a rigorous filtering pipeline:
- Execution Validation: Does the code actually run?
- Round-trip Validation: Does a separate LLM's summary of the code match the original prompt? (Measured via BERTScore).
- Final Step: A "Premium LLM" (a larger, more powerful model) is fine-tuned on this high-quality synthetic data. Because of the post-processing property of DP, this second stage of training does not require any additional noise or DP constraints, allowing the larger model to reach near-peak utility.
Datasets
The authors evaluated PrivCode across several rigorous benchmarks:
- Magicoder-OSS-Instruct-75K: Used for general instruction fine-tuning.
- OSS-Instruct PII Dataset: A newly constructed dataset containing PII-like private tokens (Emails, IP addresses, Keys, etc.) to test for privacy leakage.
- Standard Benchmarks: HumanEval, MBPP, EvalPlus (HumanEval+ and MBPP+), and BigCodeBench (Full and Hard splits).
- Multilingual Tasks: Evaluation on Java, C++, and Rust.
Key Insights and Ideas
- Small is Better for DP: A key insight is that smaller models are actually better suited for the initial DP training phase. Because they have fewer parameters, the relative impact of the Gaussian noise required for a specific privacy budget ($\epsilon$) is less destructive than it would be on a massive model.
- AST as a Regularizer: By forcing the model to pay attention to AST-derived structural tokens, the authors effectively "remind" the model how to write code even when the gradient updates are being heavily clipped and noised.
- Post-Processing Loophole: The most clever part of the architecture is leveraging the fact that once data is DP-compliant, you can do whatever you want with it. By moving the "heavy lifting" (training the large model) to a stage where the data is already synthetic, they bypass the utility degradation inherent in DP-SGD for large-scale models.
Key Results
- Superior Utility: Under a privacy budget of $\epsilon=4$, PrivCode outperformed standard DP fine-tuning (DPFT) and DP-Adapters across all benchmarks. It showed improvements of up to 10.1% in code pass rates for instruction following and 14.4% for code completion.
- Zero Leakage: In "canary" tests (where specific sensitive strings are injected into training to see if they can be extracted), PrivCode achieved a 0% leakage rate at $\epsilon=4$, whereas non-DP models leaked canaries nearly 100% of the time at high repetition rates.
- Syntactic Correctness: PrivCode maintained a 100% compile pass rate on HumanEval, matching non-private models and significantly beating other DP methods that frequently produced unparseable code.
Limitations and Future Work
- Computational Overhead: The multi-stage process (training a junior model, generating massive synthetic data, filtering, then training a premium model) is more computationally expensive than a single fine-tuning pass.
- Synthetic Data Quality: The final model's performance is strictly capped by the quality of the synthetic data the junior model can produce. If the junior model fails to capture complex logic, the premium model won't learn it either.
- Future Directions: The authors suggest exploring how this framework could be applied to even larger "frontier" models and investigating more sophisticated ways to generate diverse synthetic code to further close the gap with non-private training.
Summary updated