[Paper Review] Efficient Per-Example Gradient Computations in Convolutional Neural Networks
This paper proposes an efficient method for computing per-example gradients in convolutional neural networks (CNNs) using a chain-rule-based approach (crb) that extends Goodfellow's technique to convolutions. It demonstrates that crb outperforms naive and multi methods in terms of speed for smaller, shallower networks and certain architectural configurations, making differentially private training of CNNs more practical by enabling efficient gradient clipping per example.
Deep learning frameworks leverage GPUs to perform massively-parallel computations over batches of many training examples efficiently. However, for certain tasks, one may be interested in performing per-example computations, for instance using per-example gradients to evaluate a quantity of interest unique to each example. One notable application comes from the field of differential privacy, where per-example gradients must be norm-bounded in order to limit the impact of each example on the aggregated batch gradient. In this work, we discuss how per-example gradients can be efficiently computed in convolutional neural networks (CNNs). We compare existing strategies by performing a few steps of differentially-private training on CNNs of varying sizes. We also introduce a new strategy for per-example gradient calculation, which is shown to be advantageous depending on the model architecture and how the model is trained. This is a first step in making differentially-private training of CNNs practical.
Motivation & Objective
- To address the challenge of efficiently computing per-example gradients in CNNs, a critical need for differentially private training.
- To compare existing strategies—naive (batch size 1), multi-model (multiple copies), and chain-rule-based (crb)—for per-example gradient computation.
- To extend Goodfellow's method for fully connected layers to convolutional layers using PyTorch's group convolution functionality.
- To empirically evaluate performance across varying network depth, width, kernel size, and batch size.
- To provide a practical, GPU-optimized solution for per-example gradient computation to support privacy-preserving machine learning.
Proposed method
- The crb method computes per-example gradients by modifying backpropagation using intermediate activation and gradient hooks, applying the chain rule to decompose the gradient computation across individual examples.
- It leverages PyTorch’s group convolution operation to efficiently compute per-example gradients by treating each example as a separate group in the convolutional layer.
- The method avoids model duplication and instead computes gradients for each example by reusing the forward pass and applying gradient accumulation with per-example scaling.
- It is implemented as an extension to PyTorch’s nn.Module, allowing seamless integration into existing training pipelines.
- The approach is compared against the naive method (batch size 1) and the multi-model method (multiple parameter-shared models per example) in terms of runtime and GPU memory usage.
- Experiments are conducted on custom CNNs and real-world architectures (AlexNet, VGG16) with varying depth, channel ratios, kernel sizes, and batch sizes.
Experimental results
Research questions
- RQ1Which method—naive, multi-model, or chain-rule-based (crb)—is most efficient for computing per-example gradients in CNNs across different network architectures?
- RQ2How do architectural factors such as depth, width, kernel size, and batch size affect the performance of per-example gradient computation methods?
- RQ3Can the chain-rule-based method be effectively extended from fully connected to convolutional layers using PyTorch’s native operations?
- RQ4Under what conditions does the crb method outperform the multi-model approach in terms of speed and memory efficiency?
- RQ5How do the methods scale with increasing model complexity and batch size in realistic CNNs like AlexNet and VGG16?
Key findings
- For shallow networks (2–4 layers) with increasing channel ratios, the crb method is faster than multi, especially when kernel size is increased to 5.
- As network depth increases, the multi-model method becomes more competitive, with both methods showing similar performance on 4-layer networks.
- In AlexNet (smaller network), crb is up to 15 times faster than the naive method and slightly faster than multi, with a runtime of 2.03 seconds vs. 3.08 seconds for batch size 16.
- In VGG16 (larger network), crb becomes slightly slower than multi, with a runtime of 5.59 seconds vs. 4.63 seconds, indicating a performance shift with model size.
- The crb method exhibits piecewise linear scaling with batch size, suggesting better GPU utilization at larger batch sizes, while multi and naive show strictly linear scaling.
- The crb method is more memory-efficient than multi when model parameters are shared, and both methods use similar GPU memory, making them viable for large-scale training.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.