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 compute_dp_sgd_privacy.py --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_size, batch_size, 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_size (int) – The size of the sample (dataset)

  • batch_size (int) – Batch size

  • 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]

Returns

Pair of privacy loss epsilon and optimal order alpha

Raises

ValueError – When batch size is greater than sample size