-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
New tensor type for FV scheme #4061
Conversation
Check out this pull request on Review Jupyter notebook visual diffs & provide feedback on notebooks. Powered by ReviewNB |
1593910
to
32a2581
Compare
32a2581
to
35163a9
Compare
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'm actually lost in how a new tensor should be setup, which operations should we add and so on. I will check on slack to see if someone can give it a look, especially for the failing tests.
def __add__(self, *args, **kwargs): | ||
self.prepareEvaluator() | ||
|
||
if not args[0].shape == self.child.shape: | ||
raise ValueError( | ||
f"Cannot add tensors with different shape {args[0].shape} , {self.child.shape}" | ||
) | ||
|
||
args = args[0].flatten().tolist() | ||
|
||
# if integer values; transform it to plaintext | ||
if isinstance(args[0], int): | ||
args = [self.encoder.encode(x) for x in args] | ||
|
||
child = self.child.flatten().tolist() | ||
|
||
data = [self.evaluator.add(x, y) for x, y in zip(child, args)] | ||
data = np.array(data).reshape(self.child.shape) |
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.
Have you tried to implement the __radd__
, __rsub__
methods so that it also can operate when it's the right operand. However, I'm not sure this is how we should do it in PySyft.
# Homomorphic Encryption using private key; if private key available prefer it. | ||
x_encrypted.child.encrypt(private_key, context) |
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.
Why is that?
Tensors, so compared to the @overloaded.method, you see | ||
that the @overloaded.module does not hook the arguments. | ||
""" | ||
pass |
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.
Shouldn't this be implemented with the other operations?
Currently, the tests are failling here:
You need to also add serialization/deserialize tests. |
@overloaded.method | ||
def add(self, _self, *args, **kwargs): | ||
""" | ||
Here is an example of how to use the @overloaded.method decorator. To see |
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.
MAYBE: Need to update the commnets :D
obj.child = data | ||
return obj | ||
|
||
def mm(self, *args, **kwargs): |
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.
Q: Can't we use also overload this?
self.evaluator = None | ||
|
||
def encrypt(self, key, context): | ||
self.context = context |
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.
Q: Shouldn't we populate self
and return self
?
inputs = self.child.flatten().tolist() | ||
new_child = [self.encryptor.encrypt(self.encoder.encode(x)) for x in inputs] | ||
|
||
data = np.array(new_child).reshape(self.child.shape) |
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.
Q: It is necessary to be np.array
can't it be tensor?
@IamRavikantSingh I changed this to point to syft_0.2.x |
62beac7
to
403d9a0
Compare
403d9a0
to
fdb0188
Compare
1. Add inplace decryption 2. Fix operations on ciphertext: working: th.add(), a.add(b), a + b (same for sub, mul). matrix multiplication only working with a.mm(b) yet.
686e59d
to
9bfa9db
Compare
Hi! 0.2.x hit EOL, closing this as we no longer support it. |
Description
closes #3710
Creating a new tensor type for supporting the FV homomorphic encryption scheme written internally in PySyft.
might remain as a draft for some time because it still needs several changes to make it fully functional.
Affected Dependencies
will update it.
How has this been tested?
will update it
Checklist