diff --git a/WORKSPACE b/WORKSPACE index 3156501..fd5a6c6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,6 +1,7 @@ workspace(name = "org_tensorflow_privacy") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") git_repository( name = "bazel_skylib", @@ -14,22 +15,21 @@ git_repository( tag = "0.5.0", ) -git_repository( - name = "com_google_differential_py", - remote = "https://github.com/google/differential-privacy.git", - commit = "3485dec02794bda52d7b0ea248fa2a2caf11d55b", +dp_lib_commit = "3485dec02794bda52d7b0ea248fa2a2caf11d55b" +dp_lib_tar_sha256 = "e2dfa8a42b7f6a4b701a9a0ea0904e0b716e2ace691dcd789af2e9185f21f4b8" +dp_lib_url = "https://github.com/google/differential-privacy/archive/" + dp_lib_commit + ".tar.gz" + +http_archive( + name = "com_google_differential_py", + sha256 = dp_lib_tar_sha256, + urls = [ + dp_lib_url, + ], + strip_prefix = "differential-privacy-" + dp_lib_commit + "/python", ) -# 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") +# Load transitive dependencies of the DP accounting library. +load("@com_google_differential_py//: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", -) +load("@com_google_differential_py//:accounting_py_deps_init.bzl", "accounting_py_deps_init") +accounting_py_deps_init("com_google_differential_py") diff --git a/tensorflow_privacy/privacy/analysis/BUILD b/tensorflow_privacy/privacy/analysis/BUILD index a322fe7..fa01f94 100644 --- a/tensorflow_privacy/privacy/analysis/BUILD +++ b/tensorflow_privacy/privacy/analysis/BUILD @@ -13,7 +13,7 @@ py_library( name = "compute_dp_sgd_privacy_lib", srcs = ["compute_dp_sgd_privacy_lib.py"], srcs_version = "PY3", - deps = ["@com_google_differential_py//python/dp_accounting:accounting"], + deps = ["@com_google_differential_py//dp_accounting:accounting"], ) py_binary( @@ -42,7 +42,7 @@ py_binary( py_library( name = "compute_noise_from_budget_lib", srcs = ["compute_noise_from_budget_lib.py"], - deps = ["@com_google_differential_py//python/dp_accounting:accounting"], + deps = ["@com_google_differential_py//dp_accounting:accounting"], ) py_test( @@ -61,7 +61,7 @@ py_library( srcs = ["rdp_accountant.py"], srcs_version = "PY3", visibility = ["//visibility:public"], - deps = ["@com_google_differential_py//python/dp_accounting:accounting"], + deps = ["@com_google_differential_py//dp_accounting:accounting"], ) py_test( @@ -110,6 +110,6 @@ py_test( srcs_version = "PY3", deps = [ ":tree_aggregation_accountant", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) diff --git a/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py b/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py index 04866c0..5c8cc1b 100644 --- a/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py +++ b/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py @@ -17,7 +17,7 @@ import math from absl import app -import com_google_differential_py.python.dp_accounting +import dp_accounting def apply_dp_sgd_analysis(q, sigma, steps, orders, delta): diff --git a/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py b/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py index afb7f52..40fd172 100644 --- a/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py +++ b/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py @@ -17,7 +17,7 @@ import math from absl import app -import com_google_differential_py.python.dp_accounting +import dp_accounting from scipy import optimize diff --git a/tensorflow_privacy/privacy/analysis/rdp_accountant.py b/tensorflow_privacy/privacy/analysis/rdp_accountant.py index 3f4b3c0..893c68d 100644 --- a/tensorflow_privacy/privacy/analysis/rdp_accountant.py +++ b/tensorflow_privacy/privacy/analysis/rdp_accountant.py @@ -41,7 +41,7 @@ The example code would be: eps, _, opt_order = rdp_accountant.get_privacy_spent(rdp, target_delta=delta) """ -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np diff --git a/tensorflow_privacy/privacy/analysis/tree_aggregation_accountant_test.py b/tensorflow_privacy/privacy/analysis/tree_aggregation_accountant_test.py index aca0a20..5dd7039 100644 --- a/tensorflow_privacy/privacy/analysis/tree_aggregation_accountant_test.py +++ b/tensorflow_privacy/privacy/analysis/tree_aggregation_accountant_test.py @@ -14,7 +14,7 @@ # ============================================================================== from absl.testing import parameterized -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.analysis import tree_aggregation_accountant diff --git a/tensorflow_privacy/privacy/dp_query/BUILD b/tensorflow_privacy/privacy/dp_query/BUILD index 0370fd2..787de79 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", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -59,7 +59,7 @@ py_library( deps = [ ":discrete_gaussian_utils", ":dp_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -82,7 +82,7 @@ py_library( deps = [ ":dp_query", ":normalized_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -103,7 +103,7 @@ py_library( srcs_version = "PY3", deps = [ ":dp_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -125,7 +125,7 @@ py_library( srcs_version = "PY3", deps = [ ":dp_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -167,7 +167,7 @@ py_library( srcs_version = "PY3", deps = [ ":dp_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -194,7 +194,7 @@ py_library( ":dp_query", ":gaussian_query", ":quantile_estimator_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -274,7 +274,7 @@ py_library( deps = [ ":dp_query", ":tree_aggregation", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -286,7 +286,7 @@ py_library( ":distributed_discrete_gaussian_query", ":dp_query", ":gaussian_query", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) diff --git a/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py b/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py index 65551c4..6bf2422 100644 --- a/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py @@ -15,7 +15,7 @@ import collections -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils from tensorflow_privacy.privacy.dp_query import dp_query 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 960ff5d..bfa62e5 100644 --- a/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query.py @@ -15,7 +15,7 @@ import collections -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils from tensorflow_privacy.privacy.dp_query import dp_query diff --git a/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py b/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py index cdc3a49..d50bc53 100644 --- a/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py +++ b/tensorflow_privacy/privacy/dp_query/distributed_skellam_query.py @@ -15,7 +15,7 @@ import collections -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import normalized_query diff --git a/tensorflow_privacy/privacy/dp_query/gaussian_query.py b/tensorflow_privacy/privacy/dp_query/gaussian_query.py index 4e81c0e..a4aeeca 100644 --- a/tensorflow_privacy/privacy/dp_query/gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/gaussian_query.py @@ -16,7 +16,7 @@ import collections import distutils -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import dp_query diff --git a/tensorflow_privacy/privacy/dp_query/nested_query.py b/tensorflow_privacy/privacy/dp_query/nested_query.py index 8595292..235cf99 100644 --- a/tensorflow_privacy/privacy/dp_query/nested_query.py +++ b/tensorflow_privacy/privacy/dp_query/nested_query.py @@ -15,7 +15,7 @@ import collections -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import dp_query import tree diff --git a/tensorflow_privacy/privacy/dp_query/no_privacy_query.py b/tensorflow_privacy/privacy/dp_query/no_privacy_query.py index ccf0cf3..955ee9f 100644 --- a/tensorflow_privacy/privacy/dp_query/no_privacy_query.py +++ b/tensorflow_privacy/privacy/dp_query/no_privacy_query.py @@ -13,7 +13,7 @@ # limitations under the License. """Implements DPQuery interface for no privacy average queries.""" -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import dp_query 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 5657c1b..96500ad 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 @@ -15,7 +15,7 @@ import collections -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import gaussian_query diff --git a/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py b/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py index 85ebf93..b73adc7 100644 --- a/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py +++ b/tensorflow_privacy/privacy/dp_query/tree_aggregation_query.py @@ -34,7 +34,7 @@ corresponding epsilon for a `target_delta` and `noise_multiplier` to achieve """ import attr -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import dp_query from tensorflow_privacy.privacy.dp_query import tree_aggregation diff --git a/tensorflow_privacy/privacy/dp_query/tree_range_query.py b/tensorflow_privacy/privacy/dp_query/tree_range_query.py index 1d92471..7cdc0b0 100644 --- a/tensorflow_privacy/privacy/dp_query/tree_range_query.py +++ b/tensorflow_privacy/privacy/dp_query/tree_range_query.py @@ -21,7 +21,7 @@ import math from typing import Optional import attr -import com_google_differential_py.python.dp_accounting +import dp_accounting import tensorflow as tf from tensorflow_privacy.privacy.dp_query import distributed_discrete_gaussian_query from tensorflow_privacy.privacy.dp_query import dp_query diff --git a/tensorflow_privacy/privacy/logistic_regression/BUILD b/tensorflow_privacy/privacy/logistic_regression/BUILD index b9c2dd8..ef2bca0 100644 --- a/tensorflow_privacy/privacy/logistic_regression/BUILD +++ b/tensorflow_privacy/privacy/logistic_regression/BUILD @@ -12,7 +12,7 @@ py_library( ":datasets", ":single_layer_softmax", "//tensorflow_privacy/privacy/optimizers:dp_optimizer_keras", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) diff --git a/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py b/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py index bc4d9e0..522c9a2 100644 --- a/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py +++ b/tensorflow_privacy/privacy/logistic_regression/multinomial_logistic.py @@ -28,7 +28,7 @@ the algorithm of Abadi et al.: https://arxiv.org/pdf/1607.00133.pdf%20. import math from typing import List, Optional, Tuple -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow_privacy.privacy.logistic_regression import datasets diff --git a/tutorials/BUILD b/tutorials/BUILD index 592ff2f..ad2b5d0 100644 --- a/tutorials/BUILD +++ b/tutorials/BUILD @@ -27,7 +27,7 @@ py_binary( srcs_version = "PY3", deps = [ "//tensorflow_privacy/privacy/optimizers:dp_optimizer", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -38,7 +38,7 @@ py_binary( srcs_version = "PY3", deps = [ "//tensorflow_privacy/privacy/optimizers:dp_optimizer_keras", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -49,7 +49,7 @@ py_binary( srcs_version = "PY3", deps = [ "//tensorflow_privacy/privacy/keras_models:dp_keras_model", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -60,7 +60,7 @@ py_binary( srcs_version = "PY3", deps = [ "//tensorflow_privacy/privacy/optimizers:dp_optimizer_vectorized", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -83,7 +83,7 @@ py_binary( srcs_version = "PY3", deps = [ "//tensorflow_privacy/privacy/optimizers:dp_optimizer", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) @@ -94,7 +94,7 @@ py_binary( srcs_version = "PY3", deps = [ "//tensorflow_privacy/privacy/optimizers:dp_optimizer", - "@com_google_differential_py//python/dp_accounting:accounting", + "@com_google_differential_py//dp_accounting:accounting", ], ) diff --git a/tutorials/lm_dpsgd_tutorial.py b/tutorials/lm_dpsgd_tutorial.py index 15c99d0..a512171 100644 --- a/tutorials/lm_dpsgd_tutorial.py +++ b/tutorials/lm_dpsgd_tutorial.py @@ -35,7 +35,7 @@ import os from absl import app from absl import flags from absl import logging -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow import estimator as tf_estimator diff --git a/tutorials/mnist_dpsgd_tutorial_eager.py b/tutorials/mnist_dpsgd_tutorial_eager.py index 7a89ad3..6948f88 100644 --- a/tutorials/mnist_dpsgd_tutorial_eager.py +++ b/tutorials/mnist_dpsgd_tutorial_eager.py @@ -15,7 +15,7 @@ from absl import app from absl import flags -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentGaussianOptimizer diff --git a/tutorials/mnist_dpsgd_tutorial_keras.py b/tutorials/mnist_dpsgd_tutorial_keras.py index 248baa2..304dfdb 100644 --- a/tutorials/mnist_dpsgd_tutorial_keras.py +++ b/tutorials/mnist_dpsgd_tutorial_keras.py @@ -16,7 +16,7 @@ from absl import app from absl import flags from absl import logging -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasSGDOptimizer diff --git a/tutorials/mnist_dpsgd_tutorial_keras_model.py b/tutorials/mnist_dpsgd_tutorial_keras_model.py index 180c8d3..abd3683 100644 --- a/tutorials/mnist_dpsgd_tutorial_keras_model.py +++ b/tutorials/mnist_dpsgd_tutorial_keras_model.py @@ -16,7 +16,7 @@ from absl import app from absl import flags from absl import logging -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow_privacy.privacy.keras_models.dp_keras_model import DPSequential diff --git a/tutorials/mnist_dpsgd_tutorial_vectorized.py b/tutorials/mnist_dpsgd_tutorial_vectorized.py index 4412e94..393e239 100644 --- a/tutorials/mnist_dpsgd_tutorial_vectorized.py +++ b/tutorials/mnist_dpsgd_tutorial_vectorized.py @@ -16,7 +16,7 @@ from absl import app from absl import flags from absl import logging -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow import estimator as tf_estimator diff --git a/tutorials/mnist_lr_tutorial.py b/tutorials/mnist_lr_tutorial.py index c1bd6bc..2268bf4 100644 --- a/tutorials/mnist_lr_tutorial.py +++ b/tutorials/mnist_lr_tutorial.py @@ -26,7 +26,7 @@ import math from absl import app from absl import flags from absl import logging -import com_google_differential_py.python.dp_accounting +import dp_accounting import numpy as np import tensorflow as tf from tensorflow import estimator as tf_estimator