Differentially private (DP) contrastive learning aims to learn general-purpose representations from sensitive data, alleviating privacy leakage concerns associated with embedding models trained on private user content. However, standard contrastive objectives compare each sample with all other samples in the batch, so a single record affects the gradient of every sample in the batch. These inter-sample dependencies make it difficult to bound each record's influence while retaining useful training signals under DP. We propose DP-GCL, a DP contrastive learning framework that jointly localizes contrastive dependencies and bounds the resulting gradients. Its core module, Bounding Group-level Contribution (BGC), partitions each batch into disjoint groups, restricts comparisons to within-group samples, and clips each group's gradient separately before aggregation. This design confines each record's influence to one group while allowing signals from multiple groups to accumulate under a sensitivity bound independent of the number of groups. Because grouping reduces the available negatives, we further introduce intra-group sample augmentation to enrich local negative views without additional privacy cost. Across eight datasets, DP-GCL improves image classification and image-text retrieval accuracy over the strongest baseline by an average of 5.6 and 20.0 percentage points, respectively. Further ablation studies indicate that these improvements arise primarily from the joint design of group-local contrastive objectives and group-level gradient clipping. Moreover, DP-GCL exhibits favorable batch-size scaling and remains compatible with diverse network architectures and parameter-efficient fine-tuning strategies such as LoRA.
Zheng Liu, Chen Gong, Terry Yue Zhuo, Kecen Li, Weichen Yu, Matt Fredrikson, Tianhao Wang
原文摘要
Large language models (LLMs) have presented outstanding performance in code generation and completion. However, fine-tuning these models on private datasets can raise privacy and proprietary concerns, such as the leakage of sensitive personal information. Differentially private (DP) code generation provides theoretical guarantees for protecting sensitive code by generating synthetic datasets that preserve statistical properties while reducing privacy leakage concerns. However, DP code generation faces significant challenges due to the strict syntactic dependencies and the privacy-utility trade-off. We propose PrivCode, the first DP synthesizer specifically designed for code datasets. It incorporates a two-stage framework to improve both privacy and utility. In the first stage, termed "privacy-sanitizing", PrivCode generates DP-compliant synthetic code by training models using DP-SGD while introducing syntactic information to preserve code structure. The second stage, termed "utility-boosting", fine-tunes a larger pre-trained LLM on the synthetic privacy-free code to mitigate the utility loss caused by DP, enhancing the utility of the generated code. Extensive experiments on four LLMs show that PrivCode generates higher-utility code across various testing tasks under four benchmarks. The experiments also confirm its ability to protect sensitive data under varying privacy budgets. We provide the replication package at the code repository: https://github.com/Liuzzyg/PrivCode.