DP-SGD, short for differentially private stochastic gradient descent, is a training algorithm that modifies ordinary gradient descent so that the resulting model satisfies differential privacy: the presence or absence of any single training example changes the model’s behavior only within a mathematically bounded amount. In AI privacy, it is the most widely used method for giving a neural network a formal, provable privacy guarantee rather than an informal promise.
The algorithm achieves this with two changes to each training step: it clips every per-example gradient to a fixed norm and adds calibrated Gaussian noise to the aggregated update. A separate privacy accountant tracks how much privacy budget the whole training run consumes, expressed as the parameters epsilon and delta.
How DP-SGD modifies each training step
DP-SGD bounds the influence of every individual record by limiting and then masking its contribution to the gradient. Standard stochastic gradient descent averages the gradients of a mini-batch, so one unusual example can push the weights strongly; DP-SGD removes that possibility in three steps per iteration.
- Per-example gradient computation: the gradient is computed separately for each example in a randomly sampled batch, instead of only for the batch as a whole.
- Gradient clipping: each per-example gradient is scaled down so its L2 norm does not exceed a clipping bound C, which caps the maximum influence of any single record.
- Noise addition: the clipped gradients are summed, Gaussian noise with standard deviation sigma times C is added, and the result is averaged and applied as the update.
The random sampling of batches is part of the guarantee, not just an efficiency trick. Because each record appears in a given step only with probability q, an effect called privacy amplification by subsampling makes every step cheaper in privacy terms than it would be on the full dataset.
Key parameters and their effects
Every DP-SGD run is controlled by a small set of hyperparameters that jointly determine both the privacy guarantee and the model accuracy. The table summarizes them with typical ranges reported in practice; exact values depend heavily on the dataset size and architecture.
| Parameter | Role | Typical range | Effect of increasing it |
|---|---|---|---|
| Clipping bound C | Caps each example’s gradient norm | 0.1 to 10 | Less bias from clipping, more absolute noise |
| Noise multiplier sigma | Scales Gaussian noise relative to C | 0.5 to 2 | Stronger privacy, lower accuracy |
| Sampling rate q | Batch size divided by dataset size | 0.001 to 0.1 | Better signal per step, higher privacy cost per step |
| Number of steps T | Length of training | Thousands to hundreds of thousands | Better convergence, larger total epsilon |
| Delta | Probability of guarantee failure | Below 1/N, often 1e-5 | Weaker guarantee if set too high |
The resulting epsilon summarizes the privacy loss: lower values mean stronger protection. Values between 1 and 10 are common in published deployments; values near 1 offer strong protection, while values above 10 provide guarantees that many researchers consider weak in a worst-case sense, although they still blunt practical attacks considerably.
Privacy accounting across many training steps
A privacy accountant computes the total epsilon after T noisy steps by applying composition theorems that are much tighter than simply adding up the per-step costs. The original DP-SGD work introduced the moments accountant, which was later generalized as accounting based on Rényi differential privacy (RDP).
| Method | Principle | Tightness |
|---|---|---|
| Basic composition | Adds epsilon of every step | Very loose, rarely used |
| Advanced composition | Grows roughly with the square root of steps | Moderate |
| Moments or RDP accountant | Tracks Rényi divergence of the noisy updates | Tight, standard in libraries |
| PRV and numerical accountants | Computes the privacy loss distribution numerically | Tightest current practice |
Accounting choice matters because a looser method reports a larger epsilon for the same training run. Open-source libraries such as Opacus for PyTorch and TensorFlow Privacy implement the clipping, noise and accountant together, which reduces the risk of implementation errors that silently void the guarantee.
DP-SGD compared with other AI privacy techniques
DP-SGD protects what the trained model reveals about its training data, which distinguishes it from techniques that protect data during collection or computation. It is often combined with them rather than replacing them.
| Technique | What it protects | Formal guarantee | Relation to DP-SGD |
|---|---|---|---|
| DP-SGD | Individual records against inference from the model | Yes, epsilon and delta | Reference method |
| Federated learning | Raw data stays on devices | No, updates can still leak | Often paired with DP noise on client updates |
| PII redaction | Obvious identifiers in text | No | Removes names but not rare patterns |
| Machine unlearning | Removal of specific records after training | Depends on method | DP-SGD reduces the need for unlearning |
| Confidential computing | Data during processing on servers | Hardware based, not statistical | Complementary, protects a different stage |
The guarantee directly limits the success of membership inference attacks, which try to tell whether a record was in the training set, and it reduces model memorization of rare strings such as phone numbers. Attribute and model inversion attacks that exploit population-level patterns are not prevented, because differential privacy deliberately allows the model to learn general statistics.
Limitations and common mistakes
The central cost of DP-SGD is a privacy-utility trade-off: noise and clipping reduce accuracy, sometimes by several percentage points on image benchmarks and more on small datasets. Training is also slower and more memory intensive because per-example gradients must be materialized.
- Unit of privacy confusion: the guarantee covers one training example, so a user who contributes hundreds of records is protected only if training uses user-level differential privacy.
- Hyperparameter tuning on private data consumes privacy budget that is often left out of the reported epsilon.
- Disparate impact: clipping hurts underrepresented groups more, because their gradients are larger and more often truncated.
- Non-private pretraining data is not protected; DP-SGD fine-tuning on top of a public model covers only the fine-tuning set.
- Reporting epsilon without delta, sampling method or accountant makes the stated guarantee impossible to verify.
A widely effective practical pattern is to pretrain on public data and apply DP-SGD only during fine-tuning on sensitive data, with very large batches. This combination narrows the accuracy gap substantially and is the approach behind most recent production deployments of differentially private language and vision models.
In everyday language
DP-SGD is a way of teaching an AI model from many people’s data without letting it remember any one person. During training, every person’s influence is capped so nobody can push the model too hard, and a little random static is mixed into each lesson.
Imagine a teacher who learns about a class only through anonymous, slightly blurred surveys. The teacher still learns what the class as a whole likes, but cannot work out what any single student wrote. The price is that the teacher’s picture is a bit less sharp than it would be with perfect, unblurred answers.
Seen in the real world
A hospital network wants a model that predicts sepsis risk from electronic health records of about 200,000 patients. Its privacy officer requires that the model must not let anyone infer whether a specific patient was in the dataset, because inclusion alone would reveal a hospital stay.
The data science team starts from a model pretrained on public clinical text, then fine-tunes it with DP-SGD using a clipping bound of 1.0, a noise multiplier of 1.1, batches of 4,096 records and an RDP accountant with delta set to 1e-6. The final run reports epsilon of about 3. Accuracy measured as AUROC drops from 0.86 to 0.83, which clinicians accept, and an internal membership inference test performs barely better than random guessing on the private model.