address schien comments

This commit is contained in:
Matthew Jagielski 2021-01-19 13:16:55 -05:00
parent 3bf78f46fe
commit e468af41dd
3 changed files with 15 additions and 11 deletions

View file

@ -18,12 +18,13 @@ The script applies the RDP accountant to estimate privacy budget of an iterated
Sampled Gaussian Mechanism. The mechanism's parameters are controlled by flags.
Example:
compute_dp_sgd_privacy
compute_noise_from_budget
--N=60000 \
--batch_size=256 \
--epsilon=2.92 \
--epochs=60 \
--delta=1e-5
--delta=1e-5 \
--min_noise=1e-6
The output states that DP-SGD with these parameters should
use a noise multiplier of 1.12.
@ -50,6 +51,7 @@ flags.DEFINE_integer('batch_size', None, 'Batch size')
flags.DEFINE_float('epsilon', None, 'Target epsilon for DP-SGD')
flags.DEFINE_float('epochs', None, 'Number of epochs (may be fractional)')
flags.DEFINE_float('delta', 1e-6, 'Target delta')
flags.DEFINE_float('min_noise', 1e-5, 'Minimum noise level for search.')
def main(argv):
@ -60,7 +62,7 @@ def main(argv):
assert FLAGS.epsilon is not None, 'Flag epsilon is missing.'
assert FLAGS.epochs is not None, 'Flag epochs is missing.'
compute_noise(FLAGS.N, FLAGS.batch_size, FLAGS.epsilon,
FLAGS.epochs, FLAGS.delta)
FLAGS.epochs, FLAGS.delta, FLAGS.min_noise)
if __name__ == '__main__':

View file

@ -45,7 +45,7 @@ def apply_dp_sgd_analysis(q, sigma, steps, orders, delta):
return eps, opt_order
def compute_noise(n, batch_size, target_epsilon, epochs, delta):
def compute_noise(n, batch_size, target_epsilon, epochs, delta, noise_lbd):
"""Compute noise based on the given hyperparameters."""
q = batch_size / n # q - the sampling ratio.
if q > 1:
@ -54,10 +54,11 @@ def compute_noise(n, batch_size, target_epsilon, epochs, delta):
list(range(5, 64)) + [128, 256, 512])
steps = int(math.ceil(epochs * n / batch_size))
init_noise = 1e-5 # minimum possible noise
init_noise = noise_lbd # minimum possible noise
init_epsilon, _ = apply_dp_sgd_analysis(q, init_noise, steps, orders, delta)
if init_epsilon < target_epsilon: # 1e-5 was an overestimate
if init_epsilon < target_epsilon: # noise_lbd was an overestimate
print("min_noise too large for target epsilon.")
return 0
cur_epsilon = init_epsilon

View file

@ -26,14 +26,15 @@ from tensorflow_privacy.privacy.analysis import compute_noise_from_budget_lib
class ComputeNoiseFromBudgetTest(parameterized.TestCase):
@parameterized.named_parameters(
('Test0', 60000, 150, 0.941870567, 15, 1e-5, 1.3),
('Test1', 100000, 100, 1.70928734, 30, 1e-7, 1.0),
('Test2', 100000000, 1024, 5907984.81339406, 10, 1e-7, 0.1),
('Test0', 60000, 150, 0.941870567, 15, 1e-5, 1e-5, 1.3),
('Test1', 100000, 100, 1.70928734, 30, 1e-7, 1e-6, 1.0),
('Test2', 100000000, 1024, 5907984.81339406, 10, 1e-7, 1e-5, 0.1),
('Test3', 100000000, 1024, 5907984.81339406, 10, 1e-7, 1, 0),
)
def test_compute_noise(self, n, batch_size, target_epsilon, epochs,
delta, expected_noise):
delta, min_noise, expected_noise):
target_noise = compute_noise_from_budget_lib.compute_noise(
n, batch_size, target_epsilon, epochs, delta)
n, batch_size, target_epsilon, epochs, delta, min_noise)
self.assertAlmostEqual(target_noise, expected_noise)
if __name__ == '__main__':