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 --dataset-size=60000 --batch-size=256 --noise_multiplier=1.12 --epochs=60 --delta=1e-5 --a 10 20 100

The training process with these parameters satisfies (epsilon,delta)-DP of (2.95, 1e-5).

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