arXiv:2512.11482cs.SEcs.AI2025-12

用差分隐私保护代码大模型,防止训练数据泄露。

Towards Privacy-Preserving Code Generation: Differentially Private Code Language Models

  • 对代码模型训练加入差分隐私噪声,抑制记忆风险。
  • 显著降低各类代码片段的记忆倾向,同时保持生成能力。
  • 隐私保护效果好且不影响训练效率,适合实际部署。

专用于代码的大语言模型(CodeLLMs)在生成代码片段、文档和测试用例方面表现出色,但可能无意中记忆并复现训练数据中的内容,带来隐私泄露和知识产权风险,限制其在敏感领域的应用。为缓解此问题,本文首次系统性研究差分隐私(DP)在CodeLLMs中的应用。通过在训练过程中添加校准噪声,保护个体数据点的同时保留模型学习能力。实验表明,DP能显著降低所有类型代码片段的内存化现象,尤其对最易记忆的片段效果最佳。尽管略增加困惑度,但模型生成能力基本保持甚至提升。此外,DP对训练时间和能耗影响微小,具备实际可行性。

原文摘要 · Abstract (English)

Large language models specialized for code (CodeLLMs) have demonstrated remarkable capabilities in generating code snippets, documentation, and test cases. However, despite their promising capabilities, CodeLLMs can inadvertently memorize and reproduce snippets from their training data, which poses risks of privacy breaches and intellectual property violations. These risks restrict the deployment of CodeLLMs in sensitive domains and limit their training datasets to publicly available sources. To mitigate the memorization risk without compromising their task performance, we apply Differential Privacy (DP) to CodeLLMs. To the best of our knowledge, this is the first comprehensive study that systematically evaluates the effectiveness of DP in CodeLLMs. DP adds calibrated noise to the training process to protect individual data points while still allowing the model to learn useful patterns. To this end, we first identify and understand the driving reasons of the memorization behaviour of the CodeLLMs during their fine-tuning. Then, to address this issue, we empirically evaluate the effect of DP on mitigating memorization while preserving code generation capabilities. Our findings show that DP substantially reduces memorization in CodeLLMs across all the tested snippet types. The snippet types most prone to memorization are also the most effectively mitigated by DP. Furthermore, we observe that DP slightly increases perplexity but preserves, and can even enhance, the code generation capabilities of CodeLLMs, which makes it feasible to apply DP in practice without significantly compromising model utility. Finally, we analyze the impact of DP on training efficiency and energy consumption, finding that DP does not significantly affect training time or energy usage, making it a practical choice for privacy-preserving CodeLLMs training.

代码生成差分隐私模型安全

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。