-
Notifications
You must be signed in to change notification settings - Fork 214
add ABY3 protocol #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ABY3 protocol #721
Conversation
jvmncs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some brief preliminary notes from my end
| sess.run(fit_batch_op, tag="fit-batch") | ||
|
|
||
| def loss(self, sess, x, y, player_name): | ||
| def print_loss(y_hat, y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these outputs in cleartext break privacy? (cc @mortendahl)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these outputs in cleartext break privacy? (cc @mortendahl)
Yes, I leave it here only for debugging. Normal runs should not reveal loss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment to that effect would be much appreciated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked via #737
mortendahl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review but looks amazing so far -- lots of great stuff in here, very excited!
A few general notes:
- we should update formatting to match with rest of the code base
- we should stick with TF naming when possible; this will make it easier for a user to get the semantics
| fit_batch_op = self.backward(x, dy, self.init_learning_rate) | ||
| return fit_batch_op | ||
|
|
||
| def fit(self, sess, x, y, num_batches): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be num_epochs instead of num_batches, since each iteration is using the entire training set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also follow sklearn's lead and use something like num_iters https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num_iters might be a better choice. Each iteration is using only a batch of data, not the entire training set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked via #737
| import numpy as np | ||
|
|
||
|
|
||
| def close(x, y, threshold = 0.01): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the same as eg np.testing.assert_allclose(x, x, rtol=0.0, atol=threshold); if so we should just use that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #736
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """ | ||
| return self.prot.reduce_max(self, axis) | ||
|
|
||
| def consistency_check(self, shares, inst_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a leftover? Doesn't seem to be used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a leftover? Doesn't seem to be used anywhere.
Indeed, should have deleted it :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| def _sub_public_private(prot, x, y): | ||
| assert isinstance(x, ABY3PublicTensor), type(x) | ||
| assert isinstance(y, ABY3PrivateTens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the with contexts won't do anything here since z is a Python array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked via #737
|
|
||
| def _sub_public_private(prot, x, y): | ||
| assert isinstance(x, ABY3PublicTensor), type(x) | ||
| assert isinstance(y, ABY3PrivateTens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we either leave these out (in which case dispatch will raise an error) or add a # TODO + exception, instead of just a pass (which will silently fail by returning None).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with raising an error in the current version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked via #737
I think we should update this to match with the rest of the code base; I'd be happy to take this on. |
|
|
||
| def _sub_public_private(prot, x, y): | ||
| assert isinstance(x, ABY3PublicTensor), type(x) | ||
| assert isinstance(y, ABY3PrivateTens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function seems to be missing, cc @zicofish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, might be legacy code. Will solve it in the next commit
| print(sess.run(z.reveal())) | ||
|
|
||
|
|
||
| if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest seems to pick up these tests on its own so perhaps this listing of tests could be avoided altogether (or eg replaced by unittest.main() as in pond_test.py)? see #736
| import numpy as np | ||
|
|
||
|
|
||
| def close(x, y, threshold = 0.01): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #736
| @@ -0,0 +1,1043 @@ | |||
| import tensorflow as tf | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File should be renamed to aby3_test.py to match rest of codebase; see #736
| sess.run(fit_batch_op, tag="fit-batch") | ||
|
|
||
| def loss(self, sess, x, y, player_name): | ||
| def print_loss(y_hat, y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked via #737
mortendahl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this one up! Amazing work! 🥇
There are a few unresolved comments left that we can address in another PR; I have opened issues for all of them.
I have added a new protocol "ABY3" to the library, and made minimal necessary changes in
tf_encrypted/tensor/native.pyto support the protocol.The current ABY3 implementation contains computation for replicate arithmetic sharing and replicate boolean sharing. For Yao sharing, it is not supported yet.
NOTE. Boolean sharing is used in two ways:
tf_encrypted/tensor/boolfactory.pyto support this.The tests are included in the file
tf_encrypted/protocol/aby3/test_aby3.py.BTW, I use 4-space indent for my new files, which is different from yours. Although this does not affect the correctness, if 2-space indent is absolutely necessary, please let me know and I can update to your standard.