Privacy Analysis

Based on Google’s TF Privacy: Here, we update this code to Python 3, and optimize dependencies.

Functionality for computing Renyi Differential Privacy (RDP) of an additive Sampled Gaussian Mechanism (SGM).


Suppose that we have run an SGM applied to a function with L2-sensitivity of 1.

Its parameters are given as a list of tuples [(q_1, sigma_1, steps_1), ..., (q_k, sigma_k, steps_k)], and we wish to compute epsilon for a given target delta.

The example code would be:

>>> max_order = 32
>>> orders = range(2, max_order + 1)
>>> rdp = np.zeros_like(orders, dtype=float)
>>> for q, sigma, steps in parameters:
>>>     rdp += privacy_analysis.compute_rdp(q, sigma, steps, orders)
>>> epsilon, opt_order = privacy_analysis.get_privacy_spent(orders, rdp, delta)
opacus.privacy_analysis.compute_rdp(q, noise_multiplier, steps, orders)[source]

Computes Renyi Differential Privacy (RDP) guarantees of the Sampled Gaussian Mechanism (SGM) iterated steps times.

  • q (float) – Sampling rate of SGM.

  • noise_multiplier (float) – The ratio of the standard deviation of the additive Gaussian noise to the L2-sensitivity of the function to which it is added. Note that this is same as the standard deviation of the additive Gaussian noise when the L2-sensitivity of the function is 1.

  • steps (int) – The number of iterations of the mechanism.

  • orders (Union[List[float], float]) – An array (or a scalar) of RDP orders.

Return type

Union[List[float], float]


The RDP guarantees at all orders; can be np.inf.

opacus.privacy_analysis.get_privacy_spent(orders, rdp, delta)[source]

Computes epsilon given a list of Renyi Differential Privacy (RDP) values at multiple RDP orders and target delta. The computation of epslion, i.e. conversion from RDP to (eps, delta)-DP, is based on the theorem presented in the following work: Borja Balle et al. “Hypothesis testing interpretations and Renyi differential privacy.” International Conference on Artificial Intelligence and Statistics. PMLR, 2020. Particullary, Theorem 21 in the arXiv version :type orders: Union[List[float], float] :param orders: An array (or a scalar) of orders (alphas). :type rdp: Union[List[float], float] :param rdp: A list (or a scalar) of RDP guarantees. :type delta: float :param delta: The target delta.

Return type

Tuple[float, float]


Pair of epsilon and optimal order alpha.


ValueError – If the lengths of orders and rdp are not equal.