Skip to content

Commit ac0829f

Browse files
author
Xin Pan
committed
Consolidate privacy/ and differential_privacy/.
1 parent 8cca18b commit ac0829f

File tree

26 files changed

+2586
-110
lines changed

26 files changed

+2586
-110
lines changed
File renamed without changes.

differential_privacy/README.md

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<font size=4><b>Deep Learning with Differential Privacy</b></font>
22

3-
Authors:
4-
Martín Abadi, Andy Chu, Ian Goodfellow, H. Brendan McMahan, Ilya Mironov, Kunal Talwar, Li Zhang
5-
63
Open Sourced By: Xin Pan ([email protected], github: panyx0718)
74

85

9-
<Introduction>
6+
###Introduction for dp_sgd/README.md
107

118
Machine learning techniques based on neural networks are achieving remarkable
129
results in a wide variety of domains. Often, the training of models requires
@@ -21,73 +18,14 @@ manageable cost in software complexity, training efficiency, and model quality.
2118
paper: https://arxiv.org/abs/1607.00133
2219

2320

24-
<b>Requirements:</b>
25-
26-
1. Tensorflow 0.10.0 (master branch)
27-
28-
Note: r0.11 might experience some problems
29-
30-
2. Bazel 0.3.1
31-
32-
3. Download MNIST data
33-
34-
TODO(xpan): Complete the link:
35-
[train](http://download.tensorflow.org/models/)
36-
[test](http://download.tensorflow.org/models/)
37-
38-
Alternatively, download the tfrecord format MNIST from:
39-
https://github.com/panyx0718/models/tree/master/slim
40-
41-
<b>How to run:</b>
42-
43-
```shell
44-
# Clone the codes under differential_privacy.
45-
# Create an empty WORKSPACE file.
46-
# Download the data to the data/ directory.
47-
ls -R
48-
.:
49-
data differential_privacy WORKSPACE
50-
51-
./data:
52-
mnist_test.tfrecord mnist_train.tfrecord
53-
54-
./differential_privacy:
55-
dp_mnist dp_optimizer __init__.py per_example_gradients README.md
56-
57-
./differential_privacy/dp_mnist:
58-
BUILD dp_mnist.py
59-
60-
./differential_privacy/dp_optimizer:
61-
accountant.py BUILD dp_optimizer.py dp_pca.py sanitizer.py utils.py
62-
63-
./differential_privacy/per_example_gradients:
64-
BUILD __init__.py per_example_gradients.py
65-
66-
# Build the codes.
67-
bazel build -c opt differential_privacy/...
21+
###Introduction for multiple_teachers/README.md
6822

69-
# Run the mnist differntial privacy training codes.
70-
bazel-bin/differential_privacy/dp_mnist/dp_mnist \
71-
--training_data_path=data/mnist_train.tfrecord \
72-
--eval_data_path=data/mnist_test.tfrecord \
73-
--save_path=/tmp/mnist_dir
23+
This repository contains code to create a setup for learning privacy-preserving
24+
student models by transferring knowledge from an ensemble of teachers trained
25+
on disjoint subsets of the data for which privacy guarantees are to be provided.
7426

75-
...
76-
step: 1
77-
step: 2
78-
...
79-
step: 9
80-
spent privacy: eps 0.1250 delta 0.72709
81-
spent privacy: eps 0.2500 delta 0.24708
82-
spent privacy: eps 0.5000 delta 0.0029139
83-
spent privacy: eps 1.0000 delta 6.494e-10
84-
spent privacy: eps 2.0000 delta 8.2242e-24
85-
spent privacy: eps 4.0000 delta 1.319e-51
86-
spent privacy: eps 8.0000 delta 3.3927e-107
87-
train_accuracy: 0.53
88-
eval_accuracy: 0.53
89-
...
27+
Knowledge acquired by teachers is transferred to the student in a differentially
28+
private manner by noisily aggregating the teacher decisions before feeding them
29+
to the student during training.
9030

91-
ls /tmp/mnist_dir/
92-
checkpoint ckpt ckpt.meta results-0.json
93-
```
31+
paper: https://arxiv.org/abs/1610.05755

differential_privacy/dp_sgd/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<font size=4><b>Deep Learning with Differential Privacy</b></font>
2+
3+
Authors:
4+
Martín Abadi, Andy Chu, Ian Goodfellow, H. Brendan McMahan, Ilya Mironov, Kunal Talwar, Li Zhang
5+
6+
Open Sourced By: Xin Pan ([email protected], github: panyx0718)
7+
8+
9+
<Introduction>
10+
11+
Machine learning techniques based on neural networks are achieving remarkable
12+
results in a wide variety of domains. Often, the training of models requires
13+
large, representative datasets, which may be crowdsourced and contain sensitive
14+
information. The models should not expose private information in these datasets.
15+
Addressing this goal, we develop new algorithmic techniques for learning and a
16+
refined analysis of privacy costs within the framework of differential privacy.
17+
Our implementation and experiments demonstrate that we can train deep neural
18+
networks with non-convex objectives, under a modest privacy budget, and at a
19+
manageable cost in software complexity, training efficiency, and model quality.
20+
21+
paper: https://arxiv.org/abs/1607.00133
22+
23+
24+
<b>Requirements:</b>
25+
26+
1. Tensorflow 0.10.0 (master branch)
27+
28+
Note: r0.11 might experience some problems
29+
30+
2. Bazel 0.3.1
31+
32+
3. Download MNIST data
33+
34+
TODO(xpan): Complete the link:
35+
[train](http://download.tensorflow.org/models/)
36+
[test](http://download.tensorflow.org/models/)
37+
38+
Alternatively, download the tfrecord format MNIST from:
39+
https://github.com/panyx0718/models/tree/master/slim
40+
41+
<b>How to run:</b>
42+
43+
```shell
44+
# Clone the codes under differential_privacy.
45+
# Create an empty WORKSPACE file.
46+
# Download the data to the data/ directory.
47+
48+
# List the codes.
49+
ls -R differential_privacy/
50+
differential_privacy/:
51+
dp_sgd __init__.py privacy_accountant README.md
52+
53+
differential_privacy/dp_sgd:
54+
dp_mnist dp_optimizer per_example_gradients README.md
55+
56+
differential_privacy/dp_sgd/dp_mnist:
57+
BUILD dp_mnist.py
58+
59+
differential_privacy/dp_sgd/dp_optimizer:
60+
BUILD dp_optimizer.py dp_pca.py sanitizer.py utils.py
61+
62+
differential_privacy/dp_sgd/per_example_gradients:
63+
BUILD per_example_gradients.py
64+
65+
differential_privacy/privacy_accountant:
66+
python tf
67+
68+
differential_privacy/privacy_accountant/python:
69+
BUILD gaussian_moments.py
70+
71+
differential_privacy/privacy_accountant/tf:
72+
accountant.py accountant_test.py BUILD
73+
74+
# List the data.
75+
ls -R data/
76+
77+
./data:
78+
mnist_test.tfrecord mnist_train.tfrecord
79+
80+
# Build the codes.
81+
bazel build -c opt differential_privacy/...
82+
83+
# Run the mnist differntial privacy training codes.
84+
bazel-bin/differential_privacy/dp_sgd/dp_mnist/dp_mnist \
85+
--training_data_path=data/mnist_train.tfrecord \
86+
--eval_data_path=data/mnist_test.tfrecord \
87+
--save_path=/tmp/mnist_dir
88+
89+
...
90+
step: 1
91+
step: 2
92+
...
93+
step: 9
94+
spent privacy: eps 0.1250 delta 0.72709
95+
spent privacy: eps 0.2500 delta 0.24708
96+
spent privacy: eps 0.5000 delta 0.0029139
97+
spent privacy: eps 1.0000 delta 6.494e-10
98+
spent privacy: eps 2.0000 delta 8.2242e-24
99+
spent privacy: eps 4.0000 delta 1.319e-51
100+
spent privacy: eps 8.0000 delta 3.3927e-107
101+
train_accuracy: 0.53
102+
eval_accuracy: 0.53
103+
...
104+
105+
ls /tmp/mnist_dir/
106+
checkpoint ckpt ckpt.meta results-0.json
107+
```

differential_privacy/dp_mnist/BUILD renamed to differential_privacy/dp_sgd/dp_mnist/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ py_binary(
1717
"dp_mnist.py",
1818
],
1919
deps = [
20-
"//differential_privacy/dp_optimizer",
21-
"//differential_privacy/dp_optimizer:dp_pca",
22-
"//differential_privacy/dp_optimizer:utils",
20+
"//differential_privacy/dp_sgd/dp_optimizer",
21+
"//differential_privacy/dp_sgd/dp_optimizer:dp_pca",
22+
"//differential_privacy/dp_sgd/dp_optimizer:utils",
2323
],
2424
)

differential_privacy/dp_mnist/dp_mnist.py renamed to differential_privacy/dp_sgd/dp_mnist/dp_mnist.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import numpy as np
2525
import tensorflow as tf
2626

27-
from differential_privacy.dp_optimizer import accountant
28-
from differential_privacy.dp_optimizer import dp_optimizer
29-
from differential_privacy.dp_optimizer import dp_pca
30-
from differential_privacy.dp_optimizer import sanitizer
31-
from differential_privacy.dp_optimizer import utils
27+
from differential_privacy.dp_sgd.dp_optimizer import dp_optimizer
28+
from differential_privacy.dp_sgd.dp_optimizer import dp_pca
29+
from differential_privacy.dp_sgd.dp_optimizer import sanitizer
30+
from differential_privacy.dp_sgd.dp_optimizer import utils
31+
from differential_privacy.privacy_accountant.tf import accountant
3232

3333
# parameters for the training
3434
tf.flags.DEFINE_integer("batch_size", 600,

differential_privacy/dp_optimizer/BUILD renamed to differential_privacy/dp_sgd/dp_optimizer/BUILD

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,16 @@ py_library(
2929
],
3030
)
3131

32-
py_library(
33-
name = "accountant",
34-
srcs = [
35-
"accountant.py",
36-
],
37-
deps = [
38-
":utils",
39-
],
40-
)
41-
4232
py_library(
4333
name = "dp_optimizer",
4434
srcs = [
4535
"dp_optimizer.py",
4636
"sanitizer.py",
4737
],
4838
deps = [
49-
":accountant",
5039
":utils",
51-
"//differential_privacy/per_example_gradients",
40+
"//differential_privacy/dp_sgd/per_example_gradients",
41+
"//differential_privacy/privacy_accountant/tf:accountant",
5242
],
5343
)
5444

differential_privacy/dp_optimizer/dp_optimizer.py renamed to differential_privacy/dp_sgd/dp_optimizer/dp_optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import tensorflow as tf
2121

22-
from differential_privacy.dp_optimizer import utils
23-
from differential_privacy.per_example_gradients import per_example_gradients
22+
from differential_privacy.dp_sgd.dp_optimizer import utils
23+
from differential_privacy.dp_sgd.per_example_gradients import per_example_gradients
2424

2525

2626
class DPGradientDescentOptimizer(tf.train.GradientDescentOptimizer):

differential_privacy/dp_optimizer/dp_pca.py renamed to differential_privacy/dp_sgd/dp_optimizer/dp_pca.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515

1616
"""Differentially private optimizers.
1717
"""
18-
1918
import tensorflow as tf
2019

21-
from differential_privacy.dp_optimizer import sanitizer as san
20+
from differential_privacy.dp_sgd.dp_optimizer import sanitizer as san
2221

2322

2423
def ComputeDPPrincipalProjection(data, projection_dims,

differential_privacy/dp_optimizer/sanitizer.py renamed to differential_privacy/dp_sgd/dp_optimizer/sanitizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import tensorflow as tf
2828

29-
from differential_privacy.dp_optimizer import utils
29+
from differential_privacy.dp_sgd.dp_optimizer import utils
3030

3131

3232
ClipOption = collections.namedtuple("ClipOption",

differential_privacy/per_example_gradients/per_example_gradients.py renamed to differential_privacy/dp_sgd/per_example_gradients/per_example_gradients.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def _ListUnion(list_1, list_2):
5858

5959

6060
def Interface(ys, xs):
61-
"""
62-
Returns a dict mapping each element of xs to any of its consumers that are
63-
indirectly consumed by ys.
61+
"""Maps xs to consumers.
62+
63+
Returns a dict mapping each element of xs to any of its consumers that are
64+
indirectly consumed by ys.
6465
6566
Args:
6667
ys: The outputs
@@ -181,10 +182,10 @@ def __call__(self, x, z_grads):
181182
idx = list(self.op.inputs).index(x)
182183
assert idx != -1
183184
assert len(z_grads) == len(self.op.outputs)
184-
assert idx == 1 # We expect weights to be arg 1
185+
assert idx == 1 # We expect weights to be arg 1
185186
# We don't expect anyone to per-example differentiate with repsect
186187
# to anything other than the weights.
187-
x, w = self.op.inputs
188+
x, _ = self.op.inputs
188189
z_grads, = z_grads
189190
x_expanded = tf.expand_dims(x, 2)
190191
z_grads_expanded = tf.expand_dims(z_grads, 1)
@@ -305,7 +306,7 @@ def __call__(self, x, z_grads):
305306
assert idx == 1 # We expect biases to be arg 1
306307
# We don't expect anyone to per-example differentiate with respect
307308
# to anything other than the biases.
308-
x, b = self.op.inputs
309+
x, _ = self.op.inputs
309310
z_grads, = z_grads
310311
return z_grads
311312

@@ -336,10 +337,10 @@ def PerExampleGradients(ys, xs, grad_ys=None, name="gradients",
336337
merged_interface = _ListUnion(merged_interface, interface[x])
337338
# Differentiate with respect to the interface
338339
interface_gradients = tf.gradients(ys, merged_interface, grad_ys=grad_ys,
339-
name=name,
340-
colocate_gradients_with_ops=
341-
colocate_gradients_with_ops,
342-
gate_gradients=gate_gradients)
340+
name=name,
341+
colocate_gradients_with_ops=
342+
colocate_gradients_with_ops,
343+
gate_gradients=gate_gradients)
343344
grad_dict = OrderedDict(zip(merged_interface, interface_gradients))
344345
# Build the per-example gradients with respect to the xs
345346
if colocate_gradients_with_ops:

0 commit comments

Comments
 (0)