TL;DR
This paper introduces PrivCode++, a novel approach to differentially private code generation that protects both code snippets and their accompanying natural language prompts. By employing a latent-conditioned framework, PrivCode++ achieves strong privacy guarantees while significantly improving the utility and diversity of generated code, addressing a critical gap in current DP methods.
What Problem Does This Paper Address?
Large language models (LLMs) are increasingly used for code generation, often fine-tuned on instruction-code pairs. However, these models can memorize and leak sensitive information present in their training data. Existing differentially private (DP) methods primarily focus on protecting the code snippets themselves, assuming the natural language prompts are public and safe. This assumption is problematic in real-world scenarios where prompts might contain sensitive context, user intent, or even example code fragments. When prompts are also considered sensitive, current DP approaches struggle, leading to a significant degradation in the quality (utility, diversity, and fidelity) of the generated code. This paper tackles the challenge of achieving robust DP code generation when both prompts and code are treated as sensitive.
Methods
PrivCode++ introduces a two-stage DP framework:
- Privacy-Sanitizing Stage: This stage employs a "Privacy-Free Latent Conditioning" (PrivLC) module. Instead of directly using sensitive prompts, PrivLC learns a continuous latent representation that captures the essence of both prompts and code. This module, along with a junior LLM, is trained using Differentially Private Stochastic Gradient Descent (DP-SGD). The goal is to embed syntactic structure, task-level semantics, and contextual information into this latent space, mitigating the "structure collapse" often seen in prompt-free generation. An auxiliary prompt encoder is used to align prompt-induced latents with code-induced latents, ensuring the latent representation captures task-level information.
- Utility-Boosting Stage: This stage operates after the privacy-sanitizing stage and uses only DP-compliant outputs. It synthesizes new, privacy-free instruction-following data. This is achieved by sampling from the learned latent space and decoding these samples into prefix embeddings. These embeddings then condition the DP-trained junior model to generate high-utility code snippets. These generated code snippets are then summarized into instructions using a public LLM, forming synthetic instruction-code pairs. These synthetic pairs are rigorously filtered for quality and then used to fine-tune a larger, premium LLM without DP constraints. This two-stage approach leverages DP for sensitive training while using post-processing to maximize utility.
Datasets
The paper uses several datasets for training and evaluation:
- Magicoder-OSS-Instruct-75K: Used for fine-tuning the junior LLM in the privacy-sanitizing stage. It's a large dataset of high-quality instruction-code pairs derived from open-source code repositories.
- OSS-Instruct PII Dataset: A manually annotated dataset containing personally identifiable information (PII) in code snippets, used for generating synthetic canaries for privacy evaluation.
- HumanEval, MBPP, EvalPlus (HumanEval+, MBPP+), BigCodeBench, Humaneval-X: Standard benchmarks used for evaluating the utility (functional correctness) of the generated code.
- CanaryLeaks: A benchmark constructed for evaluating private information protection, used to assess memorization and leakage of sensitive data.
Key Insights and Ideas
- Joint Sensitivity is Crucial: The paper highlights that assuming prompts are public is a significant limitation in DP code generation. Realistic scenarios demand protection for both prompts and code.
- Latent Conditioning Bridges the Gap: By learning a latent representation of prompts and code, PrivCode++ effectively conditions generation without direct access to sensitive inputs, mitigating utility degradation.
- Two-Stage DP for Utility: The privacy-sanitizing (DP) and utility-boosting (post-processing) stages work synergistically. DP is applied where it's essential (training), and post-processing maximizes utility without compromising privacy.
- Latent Space Regularization is Key: The use of VAE-like objectives and alignment losses helps create a structured and informative latent space, crucial for generating diverse and coherent code.
- Stronger Privacy, Better Utility: Surprisingly, PrivCode++ often outperforms other joint-sensitive DP methods and even approaches the utility of relaxed-privacy methods, demonstrating that a well-designed DP framework can achieve both.
Key Results
- Utility: PrivCode++ consistently outperforms joint-sensitive DP baselines across multiple benchmarks (HumanEval, MBPP, BigCodeBench), with improvements in Pass@1 scores of up to 8.2 on instruction-following tasks and 19.3 on code completion tasks. It remains competitive with relaxed-privacy baselines.
- Privacy: PrivCode++ achieves 0% leakage in canary experiments across all settings (prompt, code, and joint canaries), a significant improvement over prior methods that show up to 40% leakage. It also demonstrates strong resistance to membership inference attacks.
- Diversity and Fidelity: t-SNE visualizations show that PrivCode++ generates synthetic code distributions that are closely aligned with the original data, exhibiting strong diversity and fidelity, unlike unconditional methods that suffer from collapse.
- Robustness: The method shows robustness across different programming languages (Java, C++, Rust) and is not critically dependent on the size of external LLMs used for auxiliary tasks.
Limitations and Future Work
- Privacy Budget Trade-off: As with all DP methods, there's a trade-off between privacy budget ($\epsilon$) and utility. Smaller $\epsilon$ leads to stronger privacy but lower utility, though PrivCode++ shows a favorable trade-off.
- External Model Dependency: While the paper shows PrivCode++ is not critically dependent on large external LLMs, it still utilizes them for prompt extraction and round-trip filtering. Future work could explore fully self-contained DP solutions.
- Computational Cost: DP-SGD training can be computationally intensive. While LoRA is used to reduce costs, further optimizations might be beneficial.
- Further Exploration of Latent Space: The paper suggests exploring more sophisticated latent space modeling techniques for even better control and generation quality.
Summary updated