Skip to content

Conversation

@zicofish
Copy link
Collaborator

@zicofish zicofish commented Dec 10, 2019

I have added a new protocol "ABY3" to the library, and made minimal necessary changes in tf_encrypted/tensor/native.py to 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:

  1. compact usage: for example, 64 boolean shares are packed into a native int64 type, and boolean operations are implemented in a SIMD manner;
  2. single: for example, after comparison, the result is a boolean value, which is shared and stored using tf's bool type. We have created a new factory tf_encrypted/tensor/boolfactory.py to 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.

@mortendahl mortendahl self-requested a review December 10, 2019 10:24
Copy link
Member

@jvmncs jvmncs left a 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):
Copy link
Member

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)

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked via #737

Copy link
Member

@mortendahl mortendahl left a 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):
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

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.

Copy link
Member

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):
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #736

Copy link
Member

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):
Copy link
Member

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.

Copy link
Collaborator Author

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 :(

Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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).

Copy link
Collaborator Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked via #737

@mortendahl
Copy link
Member

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.

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
Copy link
Member

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

Copy link
Collaborator Author

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__":
Copy link
Member

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):
Copy link
Member

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
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked via #737

Copy link
Member

@mortendahl mortendahl left a 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.

@mortendahl mortendahl merged commit e01c421 into tf-encrypted:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants