-
Notifications
You must be signed in to change notification settings - Fork 283
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
Allow sharing of tensors whose size is unknown to some parties #184
Conversation
Summary: When a party wants to secret-share a tensor, the CrypTen API currently assumes that the other parties know what the size of that tensor will be. This may be problematic, for example, if a party wants to share a data tensor whose size is unknown a priori. To make matters worse, if a party makes an incorrect assumption about the size of the tensor they will receive, the PRZS initialization does not work correctly and the parties may end up with secret shares of a tensor that do not match in size (which, somewhat surprisingly, does not always appear to be caught by Gloo during computations). The diff adds an `broadcast_size` option in the construction of secret-shared tensors. If set to `True`, the `src` party will broadcast the size of the tensor to all other parties so that they can execute the PRZS initialization correctly. We could also add an additional check on the size of the secret shares for all initializations, but I did not do that because it would add a communication round (somewhat defeating the purpose of doing PRZS initialization). This means that the failure case described above still exists; I added documentation describing it. Differential Revision: D24381193 fbshipit-source-id: 3baf2373d40fc880f7d5741178e182c0661b46b2
This pull request was exported from Phabricator. Differential Revision: D24381193 |
@@ -264,7 +264,7 @@ def send_obj(self, obj, dst, group=None): | |||
|
|||
buf = pickle.dumps(obj) | |||
size = torch.tensor(len(buf), dtype=torch.int32) | |||
arr = torch.from_numpy(numpy.frombuffer(buf, dtype=numpy.int8)) | |||
arr = torch.from_numpy(numpy.copy(numpy.frombuffer(buf, dtype=numpy.int8))) |
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.
From what I have read from here[1], the arr
should share the same memory with the numpy array in case numpy.copy
is not used.
Q: It is needed to create a copy of the data? (by using this I think we are playing it safe, but if buf
becomes bigger it might introduce an overhead because of the copy)
[1] https://pytorch.org/docs/stable/generated/torch.from_numpy.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.
Without this copy, I am seeing this warning. I tried altering the writeable flag of the numpy array directly but that does not appear to be allowed here. The copy makes the warning go away.
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.
Yep, you are right!
I have read here that pytorch does not support for the moment read-only tensors!
Summary: Pull Request resolved: #184 When a party wants to secret-share a tensor, the CrypTen API currently assumes that the other parties know what the size of that tensor will be. This may be problematic, for example, if a party wants to share a data tensor whose size is unknown a priori. To make matters worse, if a party makes an incorrect assumption about the size of the tensor they will receive, the PRZS initialization does not work correctly and the parties may end up with secret shares of a tensor that do not match in size (which, somewhat surprisingly, does not always appear to be caught by Gloo during computations). The diff adds an `broadcast_size` option in the construction of secret-shared tensors. If set to `True`, the `src` party will broadcast the size of the tensor to all other parties so that they can execute the PRZS initialization correctly. We could also add an additional check on the size of the secret shares for all initializations, but I did not do that because it would add a communication round (somewhat defeating the purpose of doing PRZS initialization). This means that the failure case described above still exists; I added documentation describing it. Reviewed By: knottb Differential Revision: D24381193 fbshipit-source-id: 0b2ae19df973dc777f546944adc1e7676d3ef621
…h#184) Summary: Pull Request resolved: fairinternal/CrypTen#184 This is a first working version of the Tensorflow model conversion to CrypTen. This currently works on simple three layer fully connected network. Future diffs will ensure that additional modules are supported. Reviewed By: lvdmaaten Differential Revision: D20661986 fbshipit-source-id: 60bffed2ecd4363a7afe0658453f8856460e60ca
Summary:
When a party wants to secret-share a tensor, the CrypTen API currently assumes that the other parties know what the size of that tensor will be. This may be problematic, for example, if a party wants to share a data tensor whose size is unknown a priori. To make matters worse, if a party makes an incorrect assumption about the size of the tensor they will receive, the PRZS initialization does not work correctly and the parties may end up with secret shares of a tensor that do not match in size (which, somewhat surprisingly, does not always appear to be caught by Gloo during computations).
The diff adds an
broadcast_size
option in the construction of secret-shared tensors. If set toTrue
, thesrc
party will broadcast the size of the tensor to all other parties so that they can execute the PRZS initialization correctly.We could also add an additional check on the size of the secret shares for all initializations, but I did not do that because it would add a communication round (somewhat defeating the purpose of doing PRZS initialization). This means that the failure case described above still exists; I added documentation describing it.
Differential Revision: D24381193