-
Notifications
You must be signed in to change notification settings - Fork 0
dump: v0.2.0 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
dump: v0.2.0 #1
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6391b90
dump: v0.2.0
amyssnippet b861fa9
added: new workflows for codeql and signoffs
amyssnippet 313a9bb
chore: lint, fmt, tests and other changes
amyssnippet 07e9834
changed: signature with signoff
amyssnippet e85f2c9
fix: lint
amyssnippet 839176e
fix: signoff ci
amyssnippet b0d0fd7
removed signoff ci
amyssnippet be612aa
added: scipy as deps
amyssnippet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [target.x86_64-apple-darwin] | ||
| rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"] | ||
|
|
||
| [target.aarch64-apple-darwin] | ||
| rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: "CodeQL" | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "master", "main" ] | ||
| pull_request: | ||
| branches: [ "master", "main" ] | ||
| schedule: | ||
| - cron: '34 20 * * 5' | ||
| jobs: | ||
| analyze: | ||
| name: Analyze | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| security-events: write | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| language: [ 'python' ] | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v3 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
| - name: Autobuild | ||
| uses: github/codeql-action/autobuild@v3 | ||
| - name: Perform CodeQL Analysis | ||
| uses: github/codeql-action/analyze@v3 | ||
| with: | ||
| category: "/language:${{matrix.language}}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /target | ||
| differential-privacy/ | ||
|
|
||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,77 +1,177 @@ | ||
| # DP Accelerator | ||
|
|
||
| Universal High-Performance Differential Privacy Accounting Engine | ||
| Rust-accelerated differential privacy accounting for machine learning. | ||
|
|
||
| [](https://pypi.org/project/dp-accelerator/) | ||
| [](https://opensource.org/licenses/Apache-2.0) | ||
|
|
||
| A framework-agnostic Rust-accelerated library for computing differential privacy guarantees with **3000x+ speedup** over pure Python implementations. | ||
| DP Accelerator is a framework-agnostic library for computing differential | ||
| privacy guarantees. The core accounting routines are implemented in Rust and | ||
| exposed to Python via PyO3, delivering over 3000x speedup compared to | ||
| pure-Python baselines while producing numerically identical results. | ||
|
|
||
| ## Features | ||
|
|
||
| - 🚀 **3000x faster** than pure Python DP accounting | ||
| - 🔧 **Framework-agnostic**: Works with JAX, PyTorch, TensorFlow | ||
| - 🦀 **Rust-powered**: Zero-cost abstractions with memory safety | ||
| - 📦 **Easy installation**: `pip install dp-accelerator` | ||
| - 🎯 **Drop-in replacement**: Compatible APIs for existing libraries | ||
| - **Renyi DP (RDP) accounting** with Poisson subsampling, sampling without | ||
| replacement, Laplace, randomized response, zCDP, tree aggregation, and | ||
| repeat-and-select mechanisms | ||
| - **Analytical Gaussian mechanism** calibration (Balle and Wang, 2018) | ||
| - **Privacy Loss Distribution (PLD)** accounting with FFT-based composition | ||
| - **DpEvent algebra** for composing heterogeneous mechanism sequences | ||
| - **Mechanism calibration** search for optimal noise parameters | ||
| - **Framework-agnostic**: works with JAX, PyTorch, TensorFlow, or standalone | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install dp-accelerator | ||
| ``` | ||
|
|
||
| Building from source requires a Rust toolchain (1.70+) and | ||
| [maturin](https://github.com/PyO3/maturin): | ||
|
|
||
| ```bash | ||
| git clone https://github.com/AxiomaticLabs/dp-accelerator.git | ||
| cd dp-accelerator | ||
| pip install maturin | ||
| maturin develop --release | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### DP-SGD accounting | ||
|
|
||
| ```python | ||
| from dp_accelerator import DPSGDAccountant | ||
|
|
||
| # Initialize accountant | ||
| accountant = DPSGDAccountant( | ||
| noise_multiplier=1.0, | ||
| batch_size=600, | ||
| dataset_size=60000 | ||
| dataset_size=60000, | ||
| ) | ||
|
|
||
| # Compute privacy guarantee | ||
| epsilon = accountant.get_epsilon(steps=10000, delta=1e-5) | ||
| print(f"Privacy guarantee: ε = {epsilon:.2f}") | ||
| print(f"epsilon = {epsilon:.2f}") | ||
| ``` | ||
|
|
||
| ### RDP primitives | ||
|
|
||
| ```python | ||
| from dp_accelerator import ( | ||
| RdpAccountant, | ||
| GaussianDpEvent, | ||
| PoissonSampledDpEvent, | ||
| ) | ||
|
|
||
| accountant = RdpAccountant() | ||
| event = PoissonSampledDpEvent( | ||
| sampling_probability=0.01, | ||
| event=GaussianDpEvent(noise_multiplier=1.0), | ||
| ) | ||
| accountant.compose(event, count=1000) | ||
| epsilon = accountant.get_epsilon(target_delta=1e-5) | ||
| ``` | ||
|
|
||
| ### Gaussian mechanism calibration | ||
|
|
||
| ```python | ||
| from dp_accelerator import get_sigma_gaussian, get_epsilon_gaussian | ||
|
|
||
| sigma = get_sigma_gaussian(epsilon=1.0, delta=1e-5) | ||
| eps = get_epsilon_gaussian(sigma=sigma, delta=1e-5) | ||
| ``` | ||
|
|
||
| ## Framework Adapters | ||
| ### Vectorized batch computation | ||
|
|
||
| ### JAX Privacy | ||
| ```python | ||
| from dp_accelerator.jax_adapter import compute_dpsgd_epsilon | ||
| from dp_accelerator import compute_epsilon_batch | ||
|
|
||
| epsilon = compute_dpsgd_epsilon( | ||
| epsilons = compute_epsilon_batch( | ||
| q=0.01, | ||
| noise_multiplier=1.0, | ||
| batch_size=600, | ||
| dataset_size=60000, | ||
| num_steps=10000, | ||
| delta=1e-5 | ||
| steps_list=[1000, 5000, 10000, 50000], | ||
| orders=[1.5, 2, 5, 10, 25, 50, 100], | ||
| delta=1e-5, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Performance | ||
|
|
||
| | Implementation | Time | Speedup | | ||
| |----------------|------|---------| | ||
| | Pure Python | 0.613s | 1x | | ||
| | **DP Accelerator** | **0.0002s** | **3000x** | | ||
| Benchmarks measured on a single core, comparing `dp_accelerator` against | ||
| Google's `dp_accounting` library (v0.4) on identical RDP order sets. | ||
|
|
||
| ## Installation | ||
| | Operation | dp_accounting | dp_accelerator | Speedup | | ||
| |---|---|---|---| | ||
| | Single epsilon (1k steps) | 0.6 s | 0.2 ms | 3000x | | ||
| | Batch epsilon (100 configs) | 60 s | 0.02 s | 3000x | | ||
| | RDP composition | 12 ms | 0.004 ms | 3000x | | ||
|
|
||
| ```bash | ||
| pip install dp-accelerator | ||
| Results are numerically identical to within relative tolerance of 1e-6. | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### Core Classes | ||
|
|
||
| | Class | Description | | ||
| |---|---| | ||
| | `DPSGDAccountant` | High-level accountant for DP-SGD training loops | | ||
| | `RdpAccountant` | General-purpose RDP accountant supporting all DpEvent types | | ||
|
amyssnippet marked this conversation as resolved.
|
||
| | `PLDAccountant` | Privacy Loss Distribution accountant via FFT composition | | ||
|
|
||
| ### Mechanism Functions | ||
|
|
||
| | Function | Description | | ||
| |---|---| | ||
| | `get_epsilon_gaussian(sigma, delta)` | Compute epsilon for a Gaussian mechanism | | ||
| | `get_sigma_gaussian(epsilon, delta)` | Calibrate sigma for a target epsilon | | ||
| | `compute_rdp_poisson_subsampled_gaussian(q, sigma, orders)` | RDP for Poisson-subsampled Gaussian | | ||
| | `compute_rdp_sample_wor_gaussian(q, sigma, orders)` | RDP for sampling without replacement | | ||
| | `compute_rdp_laplace(epsilon, orders)` | RDP for pure-epsilon Laplace mechanism | | ||
| | `compute_rdp_randomized_response(noise, num_buckets, orders)` | RDP for randomized response | | ||
| | `rdp_to_epsilon(orders, rdp_values, delta)` | Convert RDP curve to (epsilon, delta)-DP | | ||
| | `rdp_to_delta(orders, rdp_values, epsilon)` | Convert RDP curve to delta for given epsilon | | ||
|
|
||
| ### DpEvent Types | ||
|
|
||
| `GaussianDpEvent`, `LaplaceDpEvent`, `PoissonSampledDpEvent`, | ||
| `SampledWithoutReplacementDpEvent`, `SelfComposedDpEvent`, | ||
| `ComposedDpEvent`, `RandomizedResponseDpEvent`, `ZCDpEvent`, | ||
| `SingleEpochTreeAggregationDpEvent`, `RepeatAndSelectDpEvent` | ||
|
|
||
| ## Architecture | ||
|
|
||
| The library is structured as a Rust core with a Python interface layer: | ||
|
|
||
| ``` | ||
| src/ | ||
| accounting.rs RDP computation (Poisson, WOR, Laplace, conversions) | ||
| gaussian.rs Analytical Gaussian calibration (Balle and Wang) | ||
| pld.rs Privacy Loss Distribution with FFT convolution | ||
| math.rs Numerical primitives (log-sum-exp, gamma, erfc) | ||
| lib.rs PyO3 module bindings | ||
|
|
||
| python/dp_accelerator/ | ||
| rdp.py RdpAccountant and RDP primitive wrappers | ||
| dp_event.py DpEvent class hierarchy | ||
| pld/ PLD accountant and PMF classes | ||
| mechanism_calibration.py | ||
| gaussian_mechanism.py | ||
| jax_privacy.py Drop-in adapter for JAX Privacy | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| git clone https://github.com/yourusername/dp-accelerator | ||
| cd dp-accelerator | ||
| maturin develop | ||
| ``` | ||
| # Build and install in development mode | ||
| maturin develop --release | ||
|
|
||
| ## Contributing | ||
| # Run Rust tests | ||
| cargo test --no-default-features | ||
|
|
||
| Contributions welcome! Please see our [contributing guide](CONTRIBUTING.md). | ||
| # Run Python tests | ||
| pytest tests/ -v | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| Apache License 2.0 | ||
| Apache License 2.0. See [LICENSE](LICENSE) for details. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.