Skip to content

Commit e32766c

Browse files
Automated rollback of commit b16a0ab
PiperOrigin-RevId: 458478847
1 parent b16a0ab commit e32766c

24 files changed

+158
-109
lines changed

tensorflow_privacy/privacy/analysis/BUILD

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ py_library(
1313
name = "compute_dp_sgd_privacy_lib",
1414
srcs = ["compute_dp_sgd_privacy_lib.py"],
1515
srcs_version = "PY3",
16-
deps = ["@com_google_differential_py//python/dp_accounting"],
16+
deps = [
17+
"@com_google_differential_py//python/dp_accounting:dp_event",
18+
"@com_google_differential_py//python/dp_accounting/rdp:rdp_privacy_accountant",
19+
],
1720
)
1821

1922
py_binary(
@@ -42,7 +45,10 @@ py_binary(
4245
py_library(
4346
name = "compute_noise_from_budget_lib",
4447
srcs = ["compute_noise_from_budget_lib.py"],
45-
deps = ["@com_google_differential_py//python/dp_accounting"],
48+
deps = [
49+
"@com_google_differential_py//python/dp_accounting:dp_event",
50+
"@com_google_differential_py//python/dp_accounting/rdp:rdp_privacy_accountant",
51+
],
4652
)
4753

4854
py_test(
@@ -61,7 +67,11 @@ py_library(
6167
srcs = ["rdp_accountant.py"],
6268
srcs_version = "PY3",
6369
visibility = ["//visibility:public"],
64-
deps = ["@com_google_differential_py//python/dp_accounting"],
70+
deps = [
71+
"@com_google_differential_py//python/dp_accounting:dp_event",
72+
"@com_google_differential_py//python/dp_accounting:privacy_accountant",
73+
"@com_google_differential_py//python/dp_accounting/rdp:rdp_privacy_accountant",
74+
],
6575
)
6676

6777
py_test(
@@ -109,7 +119,9 @@ py_test(
109119
python_version = "PY3",
110120
srcs_version = "PY3",
111121
deps = [
122+
":rdp_accountant",
112123
":tree_aggregation_accountant",
113-
"@com_google_differential_py//python/dp_accounting",
124+
"@com_google_differential_py//python/dp_accounting:dp_event",
125+
"@com_google_differential_py//python/dp_accounting/rdp:rdp_privacy_accountant",
114126
],
115127
)

tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
import math
1818

1919
from absl import app
20-
from com_google_differential_py.python.dp_accounting
20+
21+
from com_google_differential_py.python.dp_accounting import dp_event
22+
from com_google_differential_py.python.dp_accounting.rdp import rdp_privacy_accountant
2123

2224

2325
def apply_dp_sgd_analysis(q, sigma, steps, orders, delta):
2426
"""Compute and print results of DP-SGD analysis."""
2527

26-
accountant = dp_accounting.rdp.RdpAccountant(orders)
28+
accountant = rdp_privacy_accountant.RdpAccountant(orders)
2729

28-
event = dp_accounting.SelfComposedDpEvent(
29-
dp_accounting.PoissonSampledDpEvent(q,
30-
dp_accounting.GaussianDpEvent(sigma)),
31-
steps)
30+
event = dp_event.SelfComposedDpEvent(
31+
dp_event.PoissonSampledDpEvent(q, dp_event.GaussianDpEvent(sigma)), steps)
3232

3333
accountant.compose(event)
3434

tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
import math
1818

1919
from absl import app
20-
from com_google_differential_py.python.dp_accounting
2120
from scipy import optimize
2221

22+
from com_google_differential_py.python.dp_accounting import dp_event
23+
from com_google_differential_py.python.dp_accounting.rdp import rdp_privacy_accountant
24+
2325

2426
def apply_dp_sgd_analysis(q, sigma, steps, orders, delta):
2527
"""Compute and print results of DP-SGD analysis."""
2628

27-
accountant = dp_accounting.rdp.RdpAccountant(orders)
28-
event = dp_accounting.SelfComposedDpEvent(
29-
dp_accounting.PoissonSampledDpEvent(q,
30-
dp_accounting.GaussianDpEvent(sigma)),
31-
steps)
29+
accountant = rdp_privacy_accountant.RdpAccountant(orders)
30+
event = dp_event.SelfComposedDpEvent(
31+
dp_event.PoissonSampledDpEvent(q, dp_event.GaussianDpEvent(sigma)), steps)
3232
accountant.compose(event)
3333
return accountant.get_epsilon_and_optimal_order(delta)
3434

tensorflow_privacy/privacy/analysis/rdp_accountant.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
eps, _, opt_order = rdp_accountant.get_privacy_spent(rdp, target_delta=delta)
4242
"""
4343

44-
from com_google_differential_py.python.dp_accounting
4544
import numpy as np
4645

46+
from com_google_differential_py.python.dp_accounting import dp_event
47+
from com_google_differential_py.python.dp_accounting import privacy_accountant
48+
from com_google_differential_py.python.dp_accounting.rdp import rdp_privacy_accountant
49+
4750

4851
def _compute_rdp_from_event(orders, event, count):
4952
"""Computes RDP from a DpEvent using RdpAccountant.
@@ -58,14 +61,15 @@ def _compute_rdp_from_event(orders, event, count):
5861
"""
5962
orders_vec = np.atleast_1d(orders)
6063

61-
if isinstance(event, dp_accounting.SampledWithoutReplacementDpEvent):
62-
neighboring_relation = dp_accounting.NeighboringRelation.REPLACE_ONE
63-
elif isinstance(event, dp_accounting.SingleEpochTreeAggregationDpEvent):
64-
neighboring_relation = dp_accounting.NeighboringRelation.REPLACE_SPECIAL
64+
if isinstance(event, dp_event.SampledWithoutReplacementDpEvent):
65+
neighboring_relation = privacy_accountant.NeighboringRelation.REPLACE_ONE
66+
elif isinstance(event, dp_event.SingleEpochTreeAggregationDpEvent):
67+
neighboring_relation = privacy_accountant.NeighboringRelation.REPLACE_SPECIAL
6568
else:
66-
neighboring_relation = dp_accounting.NeighboringRelation.ADD_OR_REMOVE_ONE
69+
neighboring_relation = privacy_accountant.NeighboringRelation.ADD_OR_REMOVE_ONE
6770

68-
accountant = dp_accounting.rdp.RdpAccountant(orders_vec, neighboring_relation)
71+
accountant = rdp_privacy_accountant.RdpAccountant(orders_vec,
72+
neighboring_relation)
6973
accountant.compose(event, count)
7074
rdp = accountant._rdp # pylint: disable=protected-access
7175

@@ -92,8 +96,8 @@ def compute_rdp(q, noise_multiplier, steps, orders):
9296
Returns:
9397
The RDPs at all orders. Can be `np.inf`.
9498
"""
95-
event = dp_accounting.PoissonSampledDpEvent(
96-
q, dp_accounting.GaussianDpEvent(noise_multiplier))
99+
event = dp_event.PoissonSampledDpEvent(
100+
q, dp_event.GaussianDpEvent(noise_multiplier))
97101

98102
return _compute_rdp_from_event(orders, event, steps)
99103

@@ -125,8 +129,8 @@ def compute_rdp_sample_without_replacement(q, noise_multiplier, steps, orders):
125129
Returns:
126130
The RDPs at all orders, can be np.inf.
127131
"""
128-
event = dp_accounting.SampledWithoutReplacementDpEvent(
129-
1, q, dp_accounting.GaussianDpEvent(noise_multiplier))
132+
event = dp_event.SampledWithoutReplacementDpEvent(
133+
1, q, dp_event.GaussianDpEvent(noise_multiplier))
130134

131135
return _compute_rdp_from_event(orders, event, steps)
132136

@@ -191,7 +195,7 @@ def get_privacy_spent(orders, rdp, target_eps=None, target_delta=None):
191195
raise ValueError(
192196
"Exactly one out of eps and delta must be None. (None is).")
193197

194-
accountant = dp_accounting.rdp.RdpAccountant(orders)
198+
accountant = rdp_privacy_accountant.RdpAccountant(orders)
195199
accountant._rdp = rdp # pylint: disable=protected-access
196200

197201
if target_eps is not None:

tensorflow_privacy/privacy/analysis/tree_aggregation_accountant_test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
# ==============================================================================
1515

1616
from absl.testing import parameterized
17-
from com_google_differential_py.python.dp_accounting
1817
import tensorflow as tf
18+
1919
from tensorflow_privacy.privacy.analysis import tree_aggregation_accountant
2020

21+
from com_google_differential_py.python.dp_accounting import dp_event
22+
from com_google_differential_py.python.dp_accounting.rdp import rdp_privacy_accountant
23+
2124

2225
class TreeAggregationTest(tf.test.TestCase, parameterized.TestCase):
2326

@@ -30,7 +33,8 @@ def test_compute_eps_tree(self, noise_multiplier, eps):
3033
steps_list, target_delta = 1600, 1e-6
3134
rdp = tree_aggregation_accountant.compute_rdp_tree_restart(
3235
noise_multiplier, steps_list, orders)
33-
new_eps = dp_accounting.rdp.compute_epsilon(orders, rdp, target_delta)[0]
36+
new_eps = rdp_privacy_accountant.compute_epsilon(orders, rdp,
37+
target_delta)[0]
3438
self.assertLess(new_eps, eps)
3539

3640
@parameterized.named_parameters(
@@ -63,7 +67,7 @@ def test_compute_eps_tree_decreasing(self, steps_list):
6367
for noise_multiplier in [0.1 * x for x in range(1, 100, 5)]:
6468
rdp = tree_aggregation_accountant.compute_rdp_tree_restart(
6569
noise_multiplier, steps_list, orders)
66-
eps = dp_accounting.rdp.compute_epsilon(orders, rdp, target_delta)[0]
70+
eps = rdp_privacy_accountant.compute_epsilon(orders, rdp, target_delta)[0]
6771
self.assertLess(eps, prev_eps)
6872
prev_eps = eps
6973

@@ -86,9 +90,8 @@ def test_no_tree_no_sampling(self, total_steps, noise_multiplier):
8690
orders = [1 + x / 10. for x in range(1, 100)] + list(range(12, 64))
8791
tree_rdp = tree_aggregation_accountant.compute_rdp_tree_restart(
8892
noise_multiplier, [1] * total_steps, orders)
89-
accountant = dp_accounting.rdp.RdpAccountant(orders)
90-
accountant.compose(
91-
dp_accounting.GaussianDpEvent(noise_multiplier), total_steps)
93+
accountant = rdp_privacy_accountant.RdpAccountant(orders)
94+
accountant.compose(dp_event.GaussianDpEvent(noise_multiplier), total_steps)
9295
rdp = accountant._rdp # pylint: disable=protected-access
9396
self.assertAllClose(tree_rdp, rdp, rtol=1e-12)
9497

tensorflow_privacy/privacy/dp_query/BUILD

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ py_library(
3636
deps = [
3737
":discrete_gaussian_utils",
3838
":dp_query",
39-
"@com_google_differential_py//python/dp_accounting",
39+
"@com_google_differential_py//python/dp_accounting:dp_event",
4040
],
4141
)
4242

@@ -59,7 +59,7 @@ py_library(
5959
deps = [
6060
":discrete_gaussian_utils",
6161
":dp_query",
62-
"@com_google_differential_py//python/dp_accounting",
62+
"@com_google_differential_py//python/dp_accounting:dp_event",
6363
],
6464
)
6565

@@ -82,7 +82,7 @@ py_library(
8282
deps = [
8383
":dp_query",
8484
":normalized_query",
85-
"@com_google_differential_py//python/dp_accounting",
85+
"@com_google_differential_py//python/dp_accounting:dp_event",
8686
],
8787
)
8888

@@ -103,7 +103,7 @@ py_library(
103103
srcs_version = "PY3",
104104
deps = [
105105
":dp_query",
106-
"@com_google_differential_py//python/dp_accounting",
106+
"@com_google_differential_py//python/dp_accounting:dp_event",
107107
],
108108
)
109109

@@ -125,7 +125,7 @@ py_library(
125125
srcs_version = "PY3",
126126
deps = [
127127
":dp_query",
128-
"@com_google_differential_py//python/dp_accounting",
128+
"@com_google_differential_py//python/dp_accounting:dp_event",
129129
],
130130
)
131131

@@ -167,7 +167,7 @@ py_library(
167167
srcs_version = "PY3",
168168
deps = [
169169
":dp_query",
170-
"@com_google_differential_py//python/dp_accounting",
170+
"@com_google_differential_py//python/dp_accounting:dp_event",
171171
],
172172
)
173173

@@ -194,7 +194,7 @@ py_library(
194194
":dp_query",
195195
":gaussian_query",
196196
":quantile_estimator_query",
197-
"@com_google_differential_py//python/dp_accounting",
197+
"@com_google_differential_py//python/dp_accounting:dp_event",
198198
],
199199
)
200200

@@ -274,7 +274,7 @@ py_library(
274274
deps = [
275275
":dp_query",
276276
":tree_aggregation",
277-
"@com_google_differential_py//python/dp_accounting",
277+
"@com_google_differential_py//python/dp_accounting:dp_event",
278278
],
279279
)
280280

@@ -286,7 +286,7 @@ py_library(
286286
":distributed_discrete_gaussian_query",
287287
":dp_query",
288288
":gaussian_query",
289-
"@com_google_differential_py//python/dp_accounting",
289+
"@com_google_differential_py//python/dp_accounting:dp_event",
290290
],
291291
)
292292

tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
import collections
1717

18-
from com_google_differential_py.python.dp_accounting
1918
import tensorflow as tf
2019
from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils
2120
from tensorflow_privacy.privacy.dp_query import dp_query
2221

22+
from com_google_differential_py.python.dp_accounting import dp_event
23+
2324

2425
class DiscreteGaussianSumQuery(dp_query.SumAggregationDPQuery):
2526
"""Implements DPQuery for discrete Gaussian sum queries.
@@ -83,5 +84,5 @@ def add_noise(v):
8384
return tf.ensure_shape(noised_v, v.shape)
8485

8586
result = tf.nest.map_structure(add_noise, sample_state)
86-
event = dp_accounting.UnsupportedDpEvent()
87+
event = dp_event.UnsupportedDpEvent()
8788
return result, global_state, event

tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
import collections
1717

18-
from com_google_differential_py.python.dp_accounting
1918
import tensorflow as tf
2019
from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils
2120
from tensorflow_privacy.privacy.dp_query import dp_query
2221

22+
from com_google_differential_py.python.dp_accounting import dp_event
23+
2324

2425
class DistributedDiscreteGaussianSumQuery(dp_query.SumAggregationDPQuery):
2526
"""Implements DPQuery for discrete distributed Gaussian sum queries.
@@ -107,5 +108,5 @@ def preprocess_record(self, params, record):
107108
def get_noised_result(self, sample_state, global_state):
108109
# Note that by directly returning the aggregate, this assumes that there
109110
# will not be missing local noise shares during execution.
110-
event = dp_accounting.UnsupportedDpEvent()
111+
event = dp_event.UnsupportedDpEvent()
111112
return sample_state, global_state, event

tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
import collections
1717

18-
from com_google_differential_py.python.dp_accounting
1918
import tensorflow as tf
2019
from tensorflow_privacy.privacy.dp_query import dp_query
2120
from tensorflow_privacy.privacy.dp_query import normalized_query
2221

22+
from com_google_differential_py.python.dp_accounting import dp_event
23+
2324

2425
class DistributedSkellamSumQuery(dp_query.SumAggregationDPQuery):
2526
"""Implements DPQuery interface for discrete distributed sum queries.
@@ -126,7 +127,7 @@ def preprocess_record(self, params, record):
126127

127128
def get_noised_result(self, sample_state, global_state):
128129
"""The noise was already added locally, therefore just continue."""
129-
event = dp_accounting.UnsupportedDpEvent()
130+
event = dp_event.UnsupportedDpEvent()
130131
return sample_state, global_state, event
131132

132133

tensorflow_privacy/privacy/dp_query/gaussian_query.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
import collections
1717
import distutils
1818

19-
from com_google_differential_py.python.dp_accounting
2019
import tensorflow as tf
2120
from tensorflow_privacy.privacy.dp_query import dp_query
2221

22+
from com_google_differential_py.python.dp_accounting import dp_event
23+
2324

2425
class GaussianSumQuery(dp_query.SumAggregationDPQuery):
2526
"""Implements DPQuery interface for Gaussian sum queries.
@@ -93,6 +94,6 @@ def add_noise(v):
9394

9495
result = tf.nest.map_structure(add_noise, sample_state)
9596
noise_multiplier = global_state.stddev / global_state.l2_norm_clip
96-
event = dp_accounting.GaussianDpEvent(noise_multiplier)
97+
event = dp_event.GaussianDpEvent(noise_multiplier)
9798

9899
return result, global_state, event

0 commit comments

Comments
 (0)