diff --git a/WORKSPACE b/WORKSPACE index 92f6997..e883651 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -13,3 +13,23 @@ git_repository( remote = "https://github.com/bazelbuild/rules_python.git", tag = "0.5.0", ) + +git_repository( + name = "com_google_differential_py", + remote = "https://github.com/google/differential-privacy.git", + commit = "8536a3af6b147b1cce6f884826bfd5f2009ae50f", +) + +# This is a workaround until the @com_google_differential_py WORKSPACE declares +# the nested differential-privacy/python/WORKSPACE as a local_repository, or +# https://github.com/bazelbuild/bazel/issues/1943 is fixed to support recursive +# WORKSPACE loading via git_repository. +load("@com_google_differential_py//python:accounting_py_deps.bzl", "accounting_py_deps") +accounting_py_deps() +# We can't directly use accounting_py_deps_init.bzl because it hard-codes a path +# to the requirements file that is relative to the workspace root. +load("@rules_python//python:pip.bzl", "pip_install") +pip_install( + name = "accounting_py_pip_deps", + requirements = "@com_google_differential_py//python:requirements.txt", +) diff --git a/tensorflow_privacy/privacy/dp_query/BUILD b/tensorflow_privacy/privacy/dp_query/BUILD index b742f0c..0bbafd8 100644 --- a/tensorflow_privacy/privacy/dp_query/BUILD +++ b/tensorflow_privacy/privacy/dp_query/BUILD @@ -36,7 +36,7 @@ py_library( deps = [ ":discrete_gaussian_utils", ":dp_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -59,7 +59,7 @@ py_library( deps = [ ":discrete_gaussian_utils", ":dp_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -82,7 +82,7 @@ py_library( deps = [ ":dp_query", ":normalized_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -103,7 +103,7 @@ py_library( srcs_version = "PY3", deps = [ ":dp_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -125,7 +125,7 @@ py_library( srcs_version = "PY3", deps = [ ":dp_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -167,7 +167,7 @@ py_library( srcs_version = "PY3", deps = [ ":dp_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -194,7 +194,7 @@ py_library( ":dp_query", ":gaussian_query", ":quantile_estimator_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -274,7 +274,7 @@ py_library( deps = [ ":dp_query", ":tree_aggregation", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) @@ -286,7 +286,7 @@ py_library( ":distributed_discrete_gaussian_query", ":dp_query", ":gaussian_query", - "//tensorflow_privacy/privacy/analysis:dp_event", + "@com_google_differential_py//python/dp_accounting:dp_event", ], ) diff --git a/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py b/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py index 6797b6a..b151b68 100644 --- a/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py @@ -16,10 +16,11 @@ import collections import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils from tensorflow_privacy.privacy.dp_query import dp_query +from com_google_differential_py.python.dp_accounting import dp_event + class DiscreteGaussianSumQuery(dp_query.SumAggregationDPQuery): """Implements DPQuery for discrete Gaussian sum queries. diff --git a/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py b/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py index 30031f6..514f297 100644 --- a/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py @@ -16,10 +16,11 @@ import collections import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils from tensorflow_privacy.privacy.dp_query import dp_query +from com_google_differential_py.python.dp_accounting import dp_event + class DistributedDiscreteGaussianSumQuery(dp_query.SumAggregationDPQuery): """Implements DPQuery for discrete distributed Gaussian sum queries. diff --git a/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py b/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py index 4a4266a..e721e82 100644 --- a/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py +++ b/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py @@ -16,10 +16,11 @@ import collections import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import normalized_query +from com_google_differential_py.python.dp_accounting import dp_event + class DistributedSkellamSumQuery(dp_query.SumAggregationDPQuery): """Implements DPQuery interface for discrete distributed sum queries. diff --git a/tensorflow_privacy/privacy/dp_query/gaussian_query.py b/tensorflow_privacy/privacy/dp_query/gaussian_query.py index bdc09b7..bc5c4ef 100644 --- a/tensorflow_privacy/privacy/dp_query/gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/gaussian_query.py @@ -17,9 +17,10 @@ import collections import distutils import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import dp_query +from com_google_differential_py.python.dp_accounting import dp_event + class GaussianSumQuery(dp_query.SumAggregationDPQuery): """Implements DPQuery interface for Gaussian sum queries. diff --git a/tensorflow_privacy/privacy/dp_query/nested_query.py b/tensorflow_privacy/privacy/dp_query/nested_query.py index 07e9393..da1b808 100644 --- a/tensorflow_privacy/privacy/dp_query/nested_query.py +++ b/tensorflow_privacy/privacy/dp_query/nested_query.py @@ -16,10 +16,11 @@ import collections import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import dp_query import tree +from com_google_differential_py.python.dp_accounting import dp_event + class NestedQuery(dp_query.DPQuery): """Implements DPQuery interface for structured queries. diff --git a/tensorflow_privacy/privacy/dp_query/no_privacy_query.py b/tensorflow_privacy/privacy/dp_query/no_privacy_query.py index 9e640f1..5ca70bc 100644 --- a/tensorflow_privacy/privacy/dp_query/no_privacy_query.py +++ b/tensorflow_privacy/privacy/dp_query/no_privacy_query.py @@ -14,9 +14,10 @@ """Implements DPQuery interface for no privacy average queries.""" import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import dp_query +from com_google_differential_py.python.dp_accounting import dp_event + class NoPrivacySumQuery(dp_query.SumAggregationDPQuery): """Implements DPQuery interface for a sum query with no privacy. diff --git a/tensorflow_privacy/privacy/dp_query/quantile_adaptive_clip_sum_query.py b/tensorflow_privacy/privacy/dp_query/quantile_adaptive_clip_sum_query.py index 9ab43b8..6fd9a18 100644 --- a/tensorflow_privacy/privacy/dp_query/quantile_adaptive_clip_sum_query.py +++ b/tensorflow_privacy/privacy/dp_query/quantile_adaptive_clip_sum_query.py @@ -16,11 +16,12 @@ import collections import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import gaussian_query from tensorflow_privacy.privacy.dp_query import quantile_estimator_query +from com_google_differential_py.python.dp_accounting import dp_event + class QuantileAdaptiveClipSumQuery(dp_query.SumAggregationDPQuery): """`DPQuery` for Gaussian sum queries with adaptive clipping. diff --git a/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py b/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py index eef67dc..e71bc06 100644 --- a/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py +++ b/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py @@ -35,10 +35,11 @@ corresponding epsilon for a `target_delta` and `noise_multiplier` to achieve import attr import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import tree_aggregation +from com_google_differential_py.python.dp_accounting import dp_event + # TODO(b/193679963): define `RestartQuery` and move `RestartIndicator` to be # in the same module. diff --git a/tensorflow_privacy/privacy/dp_query/tree_range_query.py b/tensorflow_privacy/privacy/dp_query/tree_range_query.py index 4d31e98..b3a603b 100644 --- a/tensorflow_privacy/privacy/dp_query/tree_range_query.py +++ b/tensorflow_privacy/privacy/dp_query/tree_range_query.py @@ -22,11 +22,12 @@ from typing import Optional import attr import tensorflow as tf -from tensorflow_privacy.privacy.analysis import dp_event from tensorflow_privacy.privacy.dp_query import distributed_discrete_gaussian_query from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import gaussian_query +from com_google_differential_py.python.dp_accounting import dp_event + def _build_tree_from_leaf(leaf_nodes: tf.Tensor, arity: int) -> tf.RaggedTensor: """A function constructs a complete tree given all the leaf nodes. diff --git a/tensorflow_privacy/privacy/logistic_regression/BUILD b/tensorflow_privacy/privacy/logistic_regression/BUILD index 7025111..a90b871 100644 --- a/tensorflow_privacy/privacy/logistic_regression/BUILD +++ b/tensorflow_privacy/privacy/logistic_regression/BUILD @@ -13,6 +13,7 @@ py_library( ":single_layer_softmax", "//tensorflow_privacy/privacy/analysis:compute_dp_sgd_privacy_lib", "//tensorflow_privacy/privacy/optimizers:dp_optimizer_keras", + "@com_google_differential_py//python/dp_accounting:common", ], ) diff --git a/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py b/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py index 3cc056a..36fd7b0 100644 --- a/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py +++ b/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py @@ -35,7 +35,7 @@ from tensorflow_privacy.privacy.logistic_regression import datasets from tensorflow_privacy.privacy.logistic_regression import single_layer_softmax from tensorflow_privacy.privacy.optimizers import dp_optimizer_keras -from differential_privacy.python.accounting import common +from com_google_differential_py.python.dp_accounting import common @tf.keras.utils.register_keras_serializable(package='Custom', name='Kifer')