-
-
Notifications
You must be signed in to change notification settings - Fork 2k
(WIP) Add Protobuf serialization #2826
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
26a788e
Add round-trip tests for Protobuf serialization
karlhigley 6ab805b
Add `bufferize` and `unbufferize` methods to `AdditiveSharingTensor`
karlhigley e1eaa4a
Add `bufferize` and `unbufferize` methods to `ObjectMessage`
karlhigley 7a42943
Add a mapping between Python and Protobuf classes
karlhigley bdfd142
Add Protobuf serde
karlhigley e92432f
Add Protobuf Torch serde
karlhigley dfd20e2
Temporarily swap serialization over to Protobuf serializer
karlhigley 56fe53f
Handle the possibility of empty messages being sent
karlhigley eb612b2
(WIP) Add `bufferize` and `unbufferize` for Operation
karlhigley b0e11eb
Adjust Protobuf round-trip serde tests to avoid `all` serialization
karlhigley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """ | ||
| This file exists to provide a common place for all Protobuf | ||
| serialisation for native Python objects. If you're adding | ||
| something here that isn't for `None`, think twice and either | ||
| use an existing sub-class of Message or add a new one. | ||
| """ | ||
|
|
||
| from collections import OrderedDict | ||
| from google.protobuf.empty_pb2 import Empty | ||
| from syft.workers.abstract import AbstractWorker | ||
|
|
||
|
|
||
| def _bufferize_none(worker: AbstractWorker, obj: "type(None)") -> "Empty": | ||
| """ | ||
| This function converts None into an empty Protobuf message. | ||
|
|
||
| Args: | ||
| obj (None): makes signature match other bufferize methods | ||
|
|
||
| Returns: | ||
| protobuf_obj: Empty Protobuf message | ||
| """ | ||
| return Empty() | ||
|
|
||
|
|
||
| def _unbufferize_none(worker: AbstractWorker, obj: "Empty") -> "type(None)": | ||
| """ | ||
| This function converts an empty Protobuf message back into None. | ||
|
|
||
| Args: | ||
| obj (Empty): Empty Protobuf message | ||
|
|
||
| Returns: | ||
| obj: None | ||
| """ | ||
| return None | ||
|
|
||
|
|
||
| # Maps a type to its bufferizer and unbufferizer functions | ||
| MAP_NATIVE_PROTOBUF_TRANSLATORS = OrderedDict({type(None): (_bufferize_none, _unbufferize_none)}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """ | ||
| This file exists to translate python classes to and from Protobuf messages. | ||
| The reason for this is to have stable serialization protocol that can be used | ||
| not only by PySyft but also in other languages. | ||
|
|
||
| https://github.com/OpenMined/syft-proto (`syft_proto` module) is included as | ||
| a dependency in setup.py. | ||
| """ | ||
| import torch | ||
|
|
||
| from google.protobuf.empty_pb2 import Empty | ||
|
|
||
| from syft.messaging.message import ObjectMessage | ||
| from syft.messaging.message import Operation | ||
| from syft.frameworks.torch.tensors.interpreters.additive_shared import AdditiveSharingTensor | ||
|
|
||
| from syft_proto.frameworks.torch.tensors.interpreters.v1.additive_shared_pb2 import ( | ||
| AdditiveSharingTensor as AdditiveSharingTensorPB, | ||
| ) | ||
| from syft_proto.messaging.v1.message_pb2 import ObjectMessage as ObjectMessagePB | ||
| from syft_proto.messaging.v1.message_pb2 import OperationMessage as OperationMessagePB | ||
| from syft_proto.generic.v1.tensor_pb2 import Tensor as TensorPB | ||
|
|
||
|
|
||
| MAP_PYTHON_TO_PROTOBUF_CLASSES = { | ||
| ObjectMessage: ObjectMessagePB, | ||
| Operation: OperationMessagePB, | ||
| torch.Tensor: TensorPB, | ||
| AdditiveSharingTensor: AdditiveSharingTensorPB, | ||
| type(None): Empty, | ||
| } | ||
|
|
||
| MAP_PROTOBUF_TO_PYTHON_CLASSES = {} | ||
|
|
||
| for key, value in MAP_PYTHON_TO_PROTOBUF_CLASSES.items(): | ||
| MAP_PROTOBUF_TO_PYTHON_CLASSES[value] = key |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.