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:


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.

  • sample_rate (float) – probability of each sample from the dataset to be selected for a next batch

  • noise_multiplier (float) – The ratio of the standard deviation of the Gaussian noise to the L2-sensitivity of the function to which the noise is added

  • epochs (int) – Number of epochs

  • delta (float) – Target delta

  • alphas (List[float]) – A list of RDP orders

  • verbose (bool) – If enabled, will print the results of DP-SGD analysis

Return type

Tuple[float, float]


Pair of privacy loss epsilon and optimal order alpha


ValueError – When batch size is greater than sample size