Compute DP-SGD Privacy¶
Command-line script for computing privacy of a model trained with DP-SGD. The script applies the RDP accountant to estimate privacy budget of an iterated Sampled Gaussian Mechanism.
The code is mainly based on Google’s TF Privacy: https://github.com/tensorflow/privacy/blob/master/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy.py
Example
To call this script from command line, you can enter:
$ python -m opacus.scripts.compute_dp_sgd_privacy –epochs=3 –delta=1e-5 –sample-rate 0.01 –noise-multiplier 1.0 –alphas 2 5 10 20 100
DP-SGD with - sampling rate = 1%, - noise_multiplier = 1.0, - iterated over 300 steps
satisfies differential privacy with - epsilon = 2.39, - delta = 1e-05.
The optimal alpha is 5.0.
- opacus.scripts.compute_dp_sgd_privacy.compute_dp_sgd_privacy(*, sample_rate, noise_multiplier, epochs, delta, alphas, verbose=True)[source]¶
Performs the DP-SGD privacy analysis.
Finds sample rate and number of steps based on the input parameters, and calls DP-SGD privacy analysis to find the privacy loss epsilon and optimal order alpha.
- Parameters:
sample_rate (
float
) – probability of each sample from the dataset to be selected for a next batchnoise_multiplier (
float
) – The ratio of the standard deviation of the Gaussian noise to the L2-sensitivity of the function to which the noise is addedepochs (
int
) – Number of epochsdelta (
float
) – Target deltaverbose (
bool
) – If enabled, will print the results of DP-SGD analysis
- Return type:
- Returns:
Pair of privacy loss epsilon and optimal order alpha
- Raises:
ValueError – When batch size is greater than sample size