d3p - A Python Package for Differentially-Private Probabilistic Programming

Lukas Prediger, Niki Andreas Lopi, Samuel Kaski, Antti Honkela

Introduction

Probabilistic Programming Languages (PPLs) such as Stan, Pyro, and PyMC3 have transformed statistical modeling by decoupling model definition from inference logic. However, these frameworks typically lack native support for Differential Privacy (DP), a mathematical standard for ensuring that individual data points remain confidential during analysis. When handling sensitive datasets—such as medical records or financial transactions—researchers often face a difficult trade-off between sophisticated Bayesian modeling and robust privacy guarantees.

To bridge this gap, we introduce d3p, an open-source Python package designed for "private-by-design" Bayesian modeling. Built on JAX and NumPyro, d3p implements Differentially-Private Doubly Stochastic Variational Inference (DP-VI), offering significant performance gains and a user-friendly API.

Design Requirements

The development of d3p was guided by several key requirements spanning usability and performance. The package aims to integrate seamlessly with existing PPL ecosystems while automating the complex parameters associated with DP inference.

Table 1: Design requirements for the d3p package, categorized by usability and performance.

As shown in the requirements table, d3p prioritizes efficient per-instance gradient computation and state-of-the-art privacy accounting, ensuring that researchers can focus on model architecture rather than the intricacies of privacy math.

Technical Implementation

The core of d3p leverages the JAX ecosystem to overcome the traditional computational bottlenecks of DP.

  • JAX and Vectorization: DP requires computing and clipping gradients for every individual data point. While this is computationally expensive in standard frameworks, d3p utilizes JAX’s vmap for efficient vectorization, enabling parallel gradient processing on GPUs.
  • Fourier Accountant: To track the privacy budget ($\epsilon, \delta$), d3p employs the Fourier accountant. This method provides tighter privacy bounds than traditional moments accountants, allowing for higher model utility under the same privacy constraints.
  • GPU-Optimized Sampling: A critical requirement for DP is independent minibatch sampling. d3p implements a modified "CUDA-Shuffle" algorithm using a Feistel network, allowing for truly random sampling directly on the GPU without sacrificing speed.

Hierarchical Modeling and Utility

One of the primary advantages of using a PPL for private inference is the ability to incorporate prior knowledge. By structuring models to reflect data hierarchies, researchers can achieve high accuracy even with strict privacy budgets.

Figure 1: Plate notation for a hierarchical model supported by d3p, showing dependencies between global parameters (M) and group-level weights (w_l).

In experiments involving hierarchical logistic regression (illustrated above), d3p demonstrated that structured models could significantly outperform non-private baselines, even at low privacy budgets ($\epsilon = 2$). The framework allows the model to learn general structures without "wasting" the privacy budget on noise inherent in individual records.

Performance and Results

Evaluation across standard benchmarks (MNIST, Fashion-MNIST, CIFAR-10) and synthetic datasets revealed several key findings:

  1. Speed: d3p achieved approximately a 10x speedup compared to TensorFlow Privacy implementations on modern GPU hardware.
  2. Robust Convergence: Contrary to simple intuition, the authors found that DP-VI is remarkably robust; model utility often remained stable or improved even as training iterations increased, despite the cumulative noise addition required by DP.
  3. Ease of Use: d3p serves as a near drop-in replacement for NumPyro’s standard inference classes, requiring minimal code changes to transition from a standard model to a private one.

Limitations and Future Work

While d3p provides a powerful tool for research, it is currently positioned as a research-oriented package. Future development will focus on addressing "side-channel" privacy leaks related to finite-precision floating-point arithmetic and implementing cryptographically secure random number generation. Additionally, while the current focus is on tabular data, future iterations may explore the Discrete Gaussian mechanism to further refine noise addition.

Summary updated

BibTeX
@article{prediger2022d,
  author = {Lukas Prediger and Niki Andreas Lopi and Samuel Kaski and Antti Honkela},
  title = {{d3p - A Python Package for Differentially-Private Probabilistic Programming}},
  journal = {Proc. Priv. Enhancing Technol.},
  year = {2022},
  doi = {10.2478/popets-2022-0052},
}
Figure