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
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)¶
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.
float) – probability of each sample from the dataset to be selected for a next batch
float) – The ratio of the standard deviation of the Gaussian noise to the L2-sensitivity of the function to which the noise is added
int) – Number of epochs
float) – Target delta
bool) – If enabled, will print the results of DP-SGD analysis
- Return type:
Pair of privacy loss epsilon and optimal order alpha
ValueError – When batch size is greater than sample size