Inferensys

Glossary

DP-SGD

DP-SGD (Differentially Private Stochastic Gradient Descent) is a training algorithm that modifies standard SGD by clipping per-example gradients and adding calibrated Gaussian noise to guarantee differential privacy.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
ALGORITHM

What is DP-SGD?

DP-SGD (Differentially Private Stochastic Gradient Descent) is the foundational algorithm for training machine learning models with formal, mathematical privacy guarantees.

DP-SGD is a modified version of stochastic gradient descent that injects calibrated noise and clips individual gradients to guarantee differential privacy (DP). It ensures a model's output does not reveal whether any single training example was used, providing a rigorous defense against membership inference and reconstruction attacks. This makes it essential for training on sensitive data in federated learning and healthcare.

The algorithm operates by first calculating the gradient for each training example, then clipping its L2 norm to a fixed maximum. These clipped gradients are averaged, and Gaussian noise with a calibrated scale is added before the weight update. The privacy cost is tracked via the Moments Accountant, allowing engineers to precisely bound total privacy loss (ε, δ) over the entire training run.

MECHANISM

Key Characteristics of DP-SGD

Differentially Private Stochastic Gradient Descent (DP-SGD) modifies standard SGD by introducing two core operations—gradient clipping and calibrated noise addition—to provide a rigorous, mathematical privacy guarantee during model training.

01

Per-Example Gradient Clipping

The first critical operation in DP-SGD is per-example gradient clipping. Unlike standard SGD which computes an average gradient over a batch, DP-SGD computes the gradient contribution (∇θ ℓ(x_i, y_i)) for each individual training example (x_i, y_i) in the batch. Each of these per-example gradient vectors is then clipped in L2 norm to a maximum threshold C. This bounds the maximum influence any single data point can have on the model update, which is a prerequisite for the subsequent noise addition to provide a meaningful privacy guarantee. The clipped gradients are then averaged to form the batch update.

  • Purpose: Limits the sensitivity of the gradient computation.
  • Parameter: The clipping norm C is a crucial hyperparameter that balances utility and privacy.
02

Calibrated Gaussian Noise Injection

After clipping, DP-SGD adds calibrated Gaussian noise to the averaged batch gradient. The noise is sampled from a zero-mean Gaussian distribution with a standard deviation (σ) scaled by the clipping norm C. The scale of the noise is calibrated to the desired privacy parameters (ε, δ) and the sampling rate (batch size / dataset size). This noise injection is what formally enforces (ε, δ)-differential privacy. The noisy gradient is then used for the weight update: θ_{t+1} = θ_t - η ( (1/B) Σ clip(∇ℓ_i, C) + N(0, σ²C² I) ).

  • Core Mechanism: The noise obscures the contribution of any individual data point.
  • Trade-off: Higher noise (larger σ) increases privacy but reduces model utility/accuracy.
03

Privacy Accounting with Rényi DP

Tracking the cumulative privacy loss (ε) over the entire training process is essential. DP-SGD uses Rényi Differential Privacy (RDP) for tight privacy accounting. RDP provides a more composable analysis of the privacy cost across multiple training steps compared to the basic Advanced Composition theorem. After each training step (or epoch), the RDP accountant converts the Rényi privacy cost into a final (ε, δ)-DP guarantee. Key parameters fed into the accountant are the noise multiplier σ, the sampling probability q = batch_size / N, and the number of training steps T.

  • Standard Tool: The Moments Accountant (based on RDP) is the de facto method for tracking privacy budget in DP-SGD.
  • Output: Provides a verifiable statement: "This model is (ε=2.0, δ=1e-5)-differentially private."
04

Utility-Privacy Trade-off

DP-SGD introduces a fundamental and quantifiable trade-off between model utility (accuracy) and privacy strength. The primary levers controlling this trade-off are:

  • Noise Multiplier (σ): Increasing σ strengthens privacy (lower ε) but typically lowers final model accuracy.
  • Clipping Norm (C): An improperly tuned C can lead to vanishing or exploding gradients, harming optimization.
  • Number of Training Steps (T): More steps improve utility but consume more privacy budget.
  • Batch Size: Larger batches reduce the sampling rate q, improving privacy for a fixed ε, but affect optimization dynamics. Achieving high utility under strong privacy constraints (e.g., ε < 1.0) often requires larger datasets, careful hyperparameter tuning, and sometimes architectural adjustments.
05

Application in Federated Learning

DP-SGD is a cornerstone for client-side privacy in Cross-Device Federated Learning. In the FedAvg framework, DP-SGD can be applied locally on each client device before updates are sent to the server. This creates a double privacy guarantee: data never leaves the device, and the transmitted updates are themselves differentially private. This combination defends against privacy leakage from the updated model parameters themselves. When combined with Secure Aggregation, which hides individual updates from the server, it provides a robust, multi-layered privacy defense. This pattern is critical for learning from sensitive on-device data, such as typing history or health metrics.

06

Limitations and Practical Considerations

While powerful, DP-SGD has notable limitations that impact its deployment:

  • Reduced Utility: Models trained with DP-SGD often have lower accuracy than their non-private counterparts, especially on complex tasks and under strong privacy bounds.
  • Increased Computation: Per-example gradient clipping requires separate gradient computations for each sample in a batch, which is more computationally expensive than standard batch gradient computation. This can be mitigated with specialized libraries.
  • Hyperparameter Sensitivity: Performance is highly sensitive to the clipping norm C and noise multiplier σ, requiring careful tuning, often via privacy-preserving hyperparameter optimization.
  • Privacy-Accounting Assumptions: The formal guarantee holds under specific assumptions about the data sampling (e.g., Poisson sampling) and requires that the algorithm's state (including randomness) is not publicly revealed beyond the final model.
DP-SGD CONTROLS

The Privacy-Utility Trade-Off: Key Hyperparameters

This table details the primary hyperparameters in DP-SGD that directly control the strength of the differential privacy guarantee (epsilon, δ) and its impact on model utility (accuracy). Adjusting these creates a fundamental trade-off.

HyperparameterPrimary Effect on Privacy (ε)Primary Effect on UtilityTypical Value / RangeGuidance

Noise Multiplier (σ)

Direct Inverse Relationship: Higher σ → Lower ε (stronger privacy).

Direct Negative Impact: Higher σ → Higher gradient noise → Lower accuracy/convergence speed.

0.1 - 10.0

The most critical knob. Start with σ=1.0 for (ε ≈ 1-10) privacy and adjust based on target ε and acceptable accuracy drop.

Clipping Norm (C)

Indirect Relationship: Lower C bounds sensitivity, allowing less noise for same ε. Crucial for privacy accounting.

Critical Impact: Too low → severe underfitting; Too high → requires more noise for same ε, hurting utility.

0.1 - 5.0

Tune carefully on a non-private baseline. Set to a robust estimate of gradient norm (e.g., median). Often ~1.0.

Lot Size (L)

Direct Relationship: Larger L → more examples per lot → less noise per example for fixed ε → can allow lower σ.

Mixed Impact: Larger L reduces stochasticity but increases memory/compute for per-example gradient clipping.

Batch Size ≤ L ≤ 256

Maximize within memory constraints to improve privacy-utility frontier. Must be ≤ total dataset size.

Number of Training Steps (T)

Direct Relationship: More T → more privacy budget consumption → Higher final ε.

Direct Positive Impact (to a point): More T → better convergence → higher accuracy.

Tuned for target ε

Fixed by privacy budget: T ≈ (N / L) * (ε_target / ρ) where ρ is computed from σ, C, L. Do not train beyond allocated ε.

Delta (δ)

Privacy Parameter: Probability of privacy guarantee failure. Must be set ≪ 1/(training dataset size).

No Direct Effect: A probabilistic bound. Lower δ requires slightly more noise for same ε.

< 1e-5 (often 1e-6 or 1/(#training examples))

Set as a cryptographically small number (e.g., 1e-6). Has minor impact on σ calculation compared to ε.

Sampling Rate (q = L / N)

Direct Relationship: Higher q → more privacy cost per step.

Indirect: Affects optimization dynamics similarly to batch size in non-private SGD.

q < 0.05 common for large N

Derived from Lot Size (L) and total dataset size (N). Use Poisson sampling for precise privacy accounting.

Learning Rate (η)

No Direct Effect

Critical for Utility: Must be tuned for noisy gradients. Often lower than non-private SGD. May require scheduling.

0.001 - 0.1

Tune aggressively. Noise makes optimization landscape flatter; often requires lower LR and/or cosine decay.

DP-SGD

Common Applications and Use Cases

DP-SGD's core privacy guarantee makes it a foundational algorithm for training models on sensitive data where individual records must be protected. Its primary applications span industries with strict data governance requirements.

DP-SGD

Frequently Asked Questions

DP-SGD (Differentially Private Stochastic Gradient Descent) is the cornerstone algorithm for training machine learning models with formal privacy guarantees. These FAQs address its core mechanisms, trade-offs, and role in modern private AI systems like federated learning.

DP-SGD (Differentially Private Stochastic Gradient Descent) is a training algorithm that modifies standard SGD by adding calibrated noise and clipping gradients to guarantee differential privacy. It works by processing each training example individually: first, the gradient for that example is computed and its norm is clipped to a maximum threshold C; second, independent Gaussian noise is added to the clipped gradient. These per-example, noised gradients are then averaged into a batch update. This process ensures that the influence of any single data point on the final model is bounded and obscured by noise, providing a mathematical privacy guarantee quantified by parameters (ε, δ).

Key Steps in a Training Iteration:

  1. Per-Example Gradient Computation: Calculate the gradient g_i for each data point (x_i, y_i) in the batch.
  2. Gradient Clipping: Scale g_i to have a maximum L2 norm of C: g_i_clipped = g_i / max(1, ||g_i||_2 / C).
  3. Noise Addition: Generate noise z ~ N(0, σ^2 C^2 I) and add it to the sum of clipped gradients.
  4. Averaging & Update: Average the noised, clipped gradients and perform a parameter update using the learning rate.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.