Skip to main content
QUICK REVIEW

[Paper Review] Opacus: User-Friendly Differential Privacy Library in PyTorch

Ashkan Yousefpour, Igor Shilov|arXiv (Cornell University)|Sep 25, 2021
Privacy-Preserving Technologies in DataComputer Science13 references23 citations
TL;DR

Opacus is a user-friendly, high-performance PyTorch library that enables training deep learning models with differential privacy using a minimal code change—just two lines. It achieves this by efficiently computing per-sample gradients via vectorized operations, avoiding the performance overhead of micro-batching, and outperforms existing frameworks in speed and memory efficiency while supporting a wide range of layers including attention and RNNs.

ABSTRACT

We introduce Opacus, a free, open-source PyTorch library for training deep learning models with differential privacy (hosted at opacus.ai). Opacus is designed for simplicity, flexibility, and speed. It provides a simple and user-friendly API, and enables machine learning practitioners to make a training pipeline private by adding as little as two lines to their code. It supports a wide variety of layers, including multi-head attention, convolution, LSTM, GRU (and generic RNN), and embedding, right out of the box and provides the means for supporting other user-defined layers. Opacus computes batched per-sample gradients, providing higher efficiency compared to the traditional "micro batch" approach. In this paper we present Opacus, detail the principles that drove its implementation and unique features, and benchmark it against other frameworks for training models with differential privacy as well as standard PyTorch.

Motivation & Objective

  • To simplify the integration of differential privacy into PyTorch-based machine learning pipelines.
  • To eliminate the performance bottleneck of traditional micro-batching in DP-SGD by enabling vectorized per-sample gradient computation.
  • To provide a flexible, extensible, and efficient framework that supports a broad range of deep learning layers out of the box.
  • To enable real-time privacy budget tracking and early stopping through built-in Rényi differential privacy accounting.
  • To outperform existing DP training frameworks in speed and memory efficiency while maintaining compatibility with standard PyTorch workflows.

Proposed method

  • Introduces the PrivacyEngine class, which wraps PyTorch model, optimizer, and data loader to enable DP training with a single method call.
  • Employs GradSampleModule to compute per-sample gradients efficiently by extending PyTorch’s autograd engine with sample-level gradient tracking.
  • Uses vectorized computation instead of micro-batching to maintain hardware utilization and improve training throughput.
  • Implements noise injection and gradient clipping in the optimizer wrapper, ensuring DP guarantees at the parameter update level.
  • Supports privacy accounting via Rényi Differential Privacy (RDP) with automatic budget tracking and early stopping.
  • Provides extensibility for custom layers and accountants through well-defined interfaces, enabling integration with advanced ML workflows.

Experimental results

Research questions

  • RQ1Can differential privacy be integrated into PyTorch training with minimal code changes while maintaining high performance?
  • RQ2How does vectorized per-sample gradient computation compare to micro-batching in terms of speed and memory efficiency for DP-SGD?
  • RQ3To what extent can Opacus support complex deep learning architectures, including attention and RNN layers, under differential privacy?
  • RQ4How does Opacus’s performance compare to other existing DP training frameworks like TensorFlow Privacy and BackPACK?
  • RQ5Can Opacus achieve competitive throughput and memory efficiency compared to custom-compiled DP-SGD implementations?

Key findings

  • Opacus reduces training overhead by avoiding micro-batching, achieving higher throughput than micro-batch-based implementations.
  • For standard models, Opacus achieves 56.5% ± 8.7% of peak CUDA memory usage in non-DP mode and 57.5% ± 14.9% in DP mode, indicating minimal memory bloat.
  • For convolutional layers, Opacus uses only 6.15% ± 0.03% of peak allocated memory in DP mode, significantly lower than non-DP, due to optimized memory handling.
  • Opacus outperforms existing frameworks like TensorFlow Privacy and BackPACK in training speed and memory efficiency across multiple models and datasets.
  • Opacus achieves competitive performance with custom JIT-compiled DP-SGD implementations, especially in throughput and memory efficiency.
  • The library supports a wide range of layers—including multi-head attention, LSTM, GRU, and embedding layers—out of the box, enabling broad applicability.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.