Scaling up Differentially Private Deep Learning with Fast Per-Example Gradient Clipping

Jaewoo Lee, Daniel Kifer

Abstract

Differentially Private Stochastic Gradient Descent (DP-SGD) is the gold standard for training privacy-preserving machine learning models. However, its practical adoption has been hindered by a massive computational "privacy tax"—often making training 10 to 100 times slower than non-private methods. This paper introduces a highly efficient method for per-example gradient clipping, a mandatory but computationally expensive step in DP-SGD. By mathematically decomposing gradient computations and employing a "loss reweighting" trick, the authors achieve training speedups of up to 94x over naive implementations, making DP training for modern architectures like Transformers and ResNets finally practical.

The Privacy Bottleneck in DP-SGD

To train a model with Differential Privacy (DP), we typically use DP-SGD. Unlike standard SGD, which calculates the average gradient for a batch of data, DP-SGD requires three distinct steps:

  1. Individual Gradient Calculation: Calculate the gradient for each individual example in the batch.
  2. Clipping: Clip the $L_2$ norm of each individual gradient to a maximum threshold $C$.
  3. Aggregation: Average these clipped gradients and add Gaussian noise.

Modern deep learning frameworks (like PyTorch and TensorFlow) and hardware (GPUs) are optimized for batch processing. Calculating gradients one by one—the "naive" approach—destroys this parallelism. This bottleneck makes it prohibitively expensive for researchers to experiment with large-scale datasets or complex architectures.

The ReweightGP Method

The authors propose ReweightGP, a method that avoids explicitly materializing the full gradient for every single example. The core insight is that we do not need the per-example gradients themselves; we only need their norms to calculate clipping weights.

Gradient Decomposition

For most standard layers, such as the fully connected layer shown below, the gradient of the weights is an outer product of the layer's input and the gradient of its pre-activation.

Figure 1: Gradient decomposition in a fully connected layer where z = Wx + b.

The authors demonstrate that the norm of each example's gradient can be computed efficiently using only the norms of the inputs $\mathbf{x}$ and the pre-activation gradients. This is computationally much cheaper than calculating the full gradient matrix for every instance in a batch.

The Reweighting Trick

Once the per-example norms are known, the authors calculate a clipping weight $\nu_i$ for each example $i$ (where $\nu_i = \min(1, C / \|\nabla L_i\|)$). They then re-weight the individual losses by these values and perform a single standard backpropagation pass. This restores the efficiency of batch processing while strictly adhering to DP requirements.

Architectural Extensions

While previous work focused on simple linear layers, this paper derives the specific equations needed to apply this trick to more complex structures, including 2D/3D Convolutions, RNNs/LSTMs, and Multi-head Attention (Transformers).

Figure 2: Tensor dimensions and mapping for a convolutional layer, illustrating the complexity of applying per-example clipping to modern vision architectures.

For convolutional layers, the method utilizes im2col transformations to maintain efficiency. The results show that for many architectures, the "speed tax" for privacy can be reduced from 100x to nearly 1x relative to non-private training, especially as batch sizes increase.

Key Results and Impact

The authors evaluated ReweightGP across diverse benchmarks, including MNIST, CIFAR10, and the LSUN scene dataset, as well as NLP tasks using Transformers on IMDB reviews.

  • Massive Speedups: On an MLP with a batch size of 128, the method was 94x faster than the naive approach. For CNNs, the speedup reached approximately 54x.
  • Scalability: The speedup factor increases with batch size. Because the method utilizes GPU parallelism effectively, larger batches—which often improve DP accuracy—become significantly more efficient.
  • Transformer Performance: This is one of the first papers to demonstrate efficient DP training for Transformers. On the IMDB dataset, ReweightGP was nearly as fast as non-private training.

Limitations and Practical Considerations

Despite its efficiency, the method has some constraints. It is incompatible with standard Batch Normalization because Batch Norm leaks information across examples, violating DP principles; the authors recommend Layer Normalization or Group Normalization as alternatives. Additionally, storing intermediate "pre-activation" values for the reweighting trick introduces a memory overhead (roughly 25% for large images). Finally, some black-box kernels (like NVIDIA’s cuDNN LSTM) do not expose the internal values required, necessitating the use of "vanilla" layer versions to enable fast clipping.

Summary updated

BibTeX
@article{lee2021scaling,
  author = {Jaewoo Lee and Daniel Kifer},
  title = {{Scaling up Differentially Private Deep Learning with Fast Per-Example Gradient Clipping}},
  journal = {Proc. Priv. Enhancing Technol.},
  year = {2021},
  doi = {10.2478/popets-2021-0008},
}
Figure