|
1 | 1 | # DP Accelerator |
2 | 2 |
|
3 | | -Universal High-Performance Differential Privacy Accounting Engine |
| 3 | +Rust-accelerated differential privacy accounting for machine learning. |
4 | 4 |
|
5 | 5 | [](https://pypi.org/project/dp-accelerator/) |
6 | 6 | [](https://opensource.org/licenses/Apache-2.0) |
7 | 7 |
|
8 | | -A framework-agnostic Rust-accelerated library for computing differential privacy guarantees with **3000x+ speedup** over pure Python implementations. |
| 8 | +DP Accelerator is a framework-agnostic library for computing differential |
| 9 | +privacy guarantees. The core accounting routines are implemented in Rust and |
| 10 | +exposed to Python via PyO3, delivering over 3000x speedup compared to |
| 11 | +pure-Python baselines while producing numerically identical results. |
9 | 12 |
|
10 | 13 | ## Features |
11 | 14 |
|
12 | | -- 🚀 **3000x faster** than pure Python DP accounting |
13 | | -- 🔧 **Framework-agnostic**: Works with JAX, PyTorch, TensorFlow |
14 | | -- 🦀 **Rust-powered**: Zero-cost abstractions with memory safety |
15 | | -- 📦 **Easy installation**: `pip install dp-accelerator` |
16 | | -- 🎯 **Drop-in replacement**: Compatible APIs for existing libraries |
| 15 | +- **Renyi DP (RDP) accounting** with Poisson subsampling, sampling without |
| 16 | + replacement, Laplace, randomized response, zCDP, tree aggregation, and |
| 17 | + repeat-and-select mechanisms |
| 18 | +- **Analytical Gaussian mechanism** calibration (Balle and Wang, 2018) |
| 19 | +- **Privacy Loss Distribution (PLD)** accounting with FFT-based composition |
| 20 | +- **DpEvent algebra** for composing heterogeneous mechanism sequences |
| 21 | +- **Mechanism calibration** search for optimal noise parameters |
| 22 | +- **Framework-agnostic**: works with JAX, PyTorch, TensorFlow, or standalone |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +```bash |
| 27 | +pip install dp-accelerator |
| 28 | +``` |
| 29 | + |
| 30 | +Building from source requires a Rust toolchain (1.70+) and |
| 31 | +[maturin](https://github.com/PyO3/maturin): |
| 32 | + |
| 33 | +```bash |
| 34 | +git clone https://github.com/AxiomaticLabs/dp-accelerator.git |
| 35 | +cd dp-accelerator |
| 36 | +pip install maturin |
| 37 | +maturin develop --release |
| 38 | +``` |
17 | 39 |
|
18 | 40 | ## Quick Start |
19 | 41 |
|
| 42 | +### DP-SGD accounting |
| 43 | + |
20 | 44 | ```python |
21 | 45 | from dp_accelerator import DPSGDAccountant |
22 | 46 |
|
23 | | -# Initialize accountant |
24 | 47 | accountant = DPSGDAccountant( |
25 | 48 | noise_multiplier=1.0, |
26 | 49 | batch_size=600, |
27 | | - dataset_size=60000 |
| 50 | + dataset_size=60000, |
28 | 51 | ) |
29 | 52 |
|
30 | | -# Compute privacy guarantee |
31 | 53 | epsilon = accountant.get_epsilon(steps=10000, delta=1e-5) |
32 | | -print(f"Privacy guarantee: ε = {epsilon:.2f}") |
| 54 | +print(f"epsilon = {epsilon:.2f}") |
| 55 | +``` |
| 56 | + |
| 57 | +### RDP primitives |
| 58 | + |
| 59 | +```python |
| 60 | +from dp_accelerator import ( |
| 61 | + RdpAccountant, |
| 62 | + GaussianDpEvent, |
| 63 | + PoissonSampledDpEvent, |
| 64 | +) |
| 65 | + |
| 66 | +accountant = RdpAccountant() |
| 67 | +event = PoissonSampledDpEvent( |
| 68 | + sampling_probability=0.01, |
| 69 | + event=GaussianDpEvent(noise_multiplier=1.0), |
| 70 | +) |
| 71 | +accountant.compose(event, count=1000) |
| 72 | +epsilon = accountant.get_epsilon(target_delta=1e-5) |
| 73 | +``` |
| 74 | + |
| 75 | +### Gaussian mechanism calibration |
| 76 | + |
| 77 | +```python |
| 78 | +from dp_accelerator import get_sigma_gaussian, get_epsilon_gaussian |
| 79 | + |
| 80 | +sigma = get_sigma_gaussian(epsilon=1.0, delta=1e-5) |
| 81 | +eps = get_epsilon_gaussian(sigma=sigma, delta=1e-5) |
33 | 82 | ``` |
34 | 83 |
|
35 | | -## Framework Adapters |
| 84 | +### Vectorized batch computation |
36 | 85 |
|
37 | | -### JAX Privacy |
38 | 86 | ```python |
39 | | -from dp_accelerator.jax_adapter import compute_dpsgd_epsilon |
| 87 | +from dp_accelerator import compute_epsilon_batch |
40 | 88 |
|
41 | | -epsilon = compute_dpsgd_epsilon( |
| 89 | +epsilons = compute_epsilon_batch( |
| 90 | + q=0.01, |
42 | 91 | noise_multiplier=1.0, |
43 | | - batch_size=600, |
44 | | - dataset_size=60000, |
45 | | - num_steps=10000, |
46 | | - delta=1e-5 |
| 92 | + steps_list=[1000, 5000, 10000, 50000], |
| 93 | + orders=[1.5, 2, 5, 10, 25, 50, 100], |
| 94 | + delta=1e-5, |
47 | 95 | ) |
48 | 96 | ``` |
49 | 97 |
|
50 | 98 | ## Performance |
51 | 99 |
|
52 | | -| Implementation | Time | Speedup | |
53 | | -|----------------|------|---------| |
54 | | -| Pure Python | 0.613s | 1x | |
55 | | -| **DP Accelerator** | **0.0002s** | **3000x** | |
| 100 | +Benchmarks measured on a single core, comparing `dp_accelerator` against |
| 101 | +Google's `dp_accounting` library (v0.4) on identical RDP order sets. |
56 | 102 |
|
57 | | -## Installation |
| 103 | +| Operation | dp_accounting | dp_accelerator | Speedup | |
| 104 | +|---|---|---|---| |
| 105 | +| Single epsilon (1k steps) | 0.6 s | 0.2 ms | 3000x | |
| 106 | +| Batch epsilon (100 configs) | 60 s | 0.02 s | 3000x | |
| 107 | +| RDP composition | 12 ms | 0.004 ms | 3000x | |
58 | 108 |
|
59 | | -```bash |
60 | | -pip install dp-accelerator |
| 109 | +Results are numerically identical to within relative tolerance of 1e-6. |
| 110 | + |
| 111 | +## API Reference |
| 112 | + |
| 113 | +### Core Classes |
| 114 | + |
| 115 | +| Class | Description | |
| 116 | +|---|---| |
| 117 | +| `DPSGDAccountant` | High-level accountant for DP-SGD training loops | |
| 118 | +| `RdpAccountant` | General-purpose RDP accountant supporting all DpEvent types | |
| 119 | +| `PLDAccountant` | Privacy Loss Distribution accountant via FFT composition | |
| 120 | + |
| 121 | +### Mechanism Functions |
| 122 | + |
| 123 | +| Function | Description | |
| 124 | +|---|---| |
| 125 | +| `get_epsilon_gaussian(sigma, delta)` | Compute epsilon for a Gaussian mechanism | |
| 126 | +| `get_sigma_gaussian(epsilon, delta)` | Calibrate sigma for a target epsilon | |
| 127 | +| `compute_rdp_poisson_subsampled_gaussian(q, sigma, orders)` | RDP for Poisson-subsampled Gaussian | |
| 128 | +| `compute_rdp_sample_wor_gaussian(q, sigma, orders)` | RDP for sampling without replacement | |
| 129 | +| `compute_rdp_laplace(epsilon, orders)` | RDP for pure-epsilon Laplace mechanism | |
| 130 | +| `compute_rdp_randomized_response(noise, num_buckets, orders)` | RDP for randomized response | |
| 131 | +| `rdp_to_epsilon(orders, rdp_values, delta)` | Convert RDP curve to (epsilon, delta)-DP | |
| 132 | +| `rdp_to_delta(orders, rdp_values, epsilon)` | Convert RDP curve to delta for given epsilon | |
| 133 | + |
| 134 | +### DpEvent Types |
| 135 | + |
| 136 | +`GaussianDpEvent`, `LaplaceDpEvent`, `PoissonSampledDpEvent`, |
| 137 | +`SampledWithoutReplacementDpEvent`, `SelfComposedDpEvent`, |
| 138 | +`ComposedDpEvent`, `RandomizedResponseDpEvent`, `ZCDpEvent`, |
| 139 | +`SingleEpochTreeAggregationDpEvent`, `RepeatAndSelectDpEvent` |
| 140 | + |
| 141 | +## Architecture |
| 142 | + |
| 143 | +The library is structured as a Rust core with a Python interface layer: |
| 144 | + |
| 145 | +``` |
| 146 | +src/ |
| 147 | + accounting.rs RDP computation (Poisson, WOR, Laplace, conversions) |
| 148 | + gaussian.rs Analytical Gaussian calibration (Balle and Wang) |
| 149 | + pld.rs Privacy Loss Distribution with FFT convolution |
| 150 | + math.rs Numerical primitives (log-sum-exp, gamma, erfc) |
| 151 | + lib.rs PyO3 module bindings |
| 152 | +
|
| 153 | +python/dp_accelerator/ |
| 154 | + rdp.py RdpAccountant and RDP primitive wrappers |
| 155 | + dp_event.py DpEvent class hierarchy |
| 156 | + pld/ PLD accountant and PMF classes |
| 157 | + mechanism_calibration.py |
| 158 | + gaussian_mechanism.py |
| 159 | + jax_privacy.py Drop-in adapter for JAX Privacy |
61 | 160 | ``` |
62 | 161 |
|
63 | 162 | ## Development |
64 | 163 |
|
65 | 164 | ```bash |
66 | | -git clone https://github.com/yourusername/dp-accelerator |
67 | | -cd dp-accelerator |
68 | | -maturin develop |
69 | | -``` |
| 165 | +# Build and install in development mode |
| 166 | +maturin develop --release |
70 | 167 |
|
71 | | -## Contributing |
| 168 | +# Run Rust tests |
| 169 | +cargo test --no-default-features |
72 | 170 |
|
73 | | -Contributions welcome! Please see our [contributing guide](CONTRIBUTING.md). |
| 171 | +# Run Python tests |
| 172 | +pytest tests/ -v |
| 173 | +``` |
74 | 174 |
|
75 | 175 | ## License |
76 | 176 |
|
77 | | -Apache License 2.0 |
| 177 | +Apache License 2.0. See [LICENSE](LICENSE) for details. |
0 commit comments