JetbrainsKatie FraserAnnouncement
Differential Privacy for Hugging Face Trainers – Without Rewriting Your Training Loop
Summary
Training large language models on sensitive data risks memorization and membership inference attacks, yet standard high-level transformer tools lack native differential privacy capabilities. JetBrains Research created and open-sourced DPTrainer, a library that integrates PyTorch's Opacus framework with the Hugging Face Trainer ecosystem. The library provides differential privacy through differentially private stochastic gradient descent without requiring manual training loops or source code modifications. DPTrainer extends base training arguments with a PrivacyArguments dataclass, managing per-sample gradient calculation, gradient clipping, noise injection, and Poisson-sampled data loading. A dynamic patching mechanism injects differential privacy into specialized subclasses like DPOTrainer and SFTTrainer, while built-in privacy accountants track the cumulative privacy budget across training steps and checkpoints.
Context
Training LLMs on sensitive user data risks training data memorization, leakage through adversarial prompting, and membership inference attacks. While Opacus enables differentially private stochastic gradient descent (DP-SGD) in PyTorch, it requires manual training loops that do not integrate cleanly with Hugging Face Trainer or TRL workflows.
Approach / What changed
JetBrains Research built and open-sourced DPTrainer to integrate Opacus with Hugging Face Trainer. It wraps models with Opacus's GradSampleModule, wraps optimizers with DPOptimizer, provides DPDataLoader with Poisson sub-sampling, tracks privacy budgets with DPCallback, and offers privatize_trainer to patch classes like DPOTrainer and SFTTrainer dynamically.
Takeaways
DPTrainer automates DP-SGD mechanics including per-sample gradient clipping, Gaussian noise addition, and automated noise calibration from a target epsilon.
The privatize_trainer function patches specialized Trainer subclasses at runtime, enabling DP-SGD without modifying task-specific loss or generation logic.
Privacy accounting state is saved during checkpointing, and training automatically halts via early stopping once the defined privacy budget is exhausted.
Source and freshness
- Source
- blog.jetbrains.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.