DP-SGD

Also known as: Differentially private stochastic gradient descent

On this page 7

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.

  1. 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.
  2. 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.
  3. 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.

ParameterRoleTypical rangeEffect of increasing it
Clipping bound CCaps each example’s gradient norm0.1 to 10Less bias from clipping, more absolute noise
Noise multiplier sigmaScales Gaussian noise relative to C0.5 to 2Stronger privacy, lower accuracy
Sampling rate qBatch size divided by dataset size0.001 to 0.1Better signal per step, higher privacy cost per step
Number of steps TLength of trainingThousands to hundreds of thousandsBetter convergence, larger total epsilon
DeltaProbability of guarantee failureBelow 1/N, often 1e-5Weaker guarantee if set too high
Main DP-SGD hyperparameters

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).

MethodPrincipleTightness
Basic compositionAdds epsilon of every stepVery loose, rarely used
Advanced compositionGrows roughly with the square root of stepsModerate
Moments or RDP accountantTracks Rényi divergence of the noisy updatesTight, standard in libraries
PRV and numerical accountantsComputes the privacy loss distribution numericallyTightest current practice
Accounting methods used with DP-SGD

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.

TechniqueWhat it protectsFormal guaranteeRelation to DP-SGD
DP-SGDIndividual records against inference from the modelYes, epsilon and deltaReference method
Federated learningRaw data stays on devicesNo, updates can still leakOften paired with DP noise on client updates
PII redactionObvious identifiers in textNoRemoves names but not rare patterns
Machine unlearningRemoval of specific records after trainingDepends on methodDP-SGD reduces the need for unlearning
Confidential computingData during processing on serversHardware based, not statisticalComplementary, protects a different stage
How DP-SGD relates to neighboring techniques

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.