Switch from a git_repository rule to http_archive for the DP accounting Bazel dependency. This is preferred, per https://docs.bazel.build/versions/main/external.html#repository-rules, to avoid depending on the system git (the HTTP downloader is build into Bazel).

Also use the strip_prefix option to only pull in the accounting WORKSPACE, not the top-level Google DP project WORKSPACE. This allows us to align the import statements to work both when pulling in the `dp_acounting` dependency via Bazel and pip.

PiperOrigin-RevId: 459807060
This commit is contained in:
A. Unique TensorFlower 2022-07-08 12:06:47 -07:00
parent 8b698a7fea
commit e826ec717a
25 changed files with 56 additions and 56 deletions

View file

@ -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(
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",
remote = "https://github.com/google/differential-privacy.git",
commit = "3485dec02794bda52d7b0ea248fa2a2caf11d55b",
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")

View file

@ -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",
],
)

View file

@ -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):

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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",
],
)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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",
],
)

View file

@ -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

View file

@ -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",
],
)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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