-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5458d2c
commit fd1213a
Showing
8 changed files
with
118 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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 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,5 @@ | ||
# MNIST data | ||
data/MNIST/ | ||
|
||
# FHE training deployment files | ||
fhe_training/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,52 @@ | ||
"""Utility functions for deployment.""" | ||
|
||
from typing import Optional, Tuple, Union | ||
|
||
from concrete import fhe | ||
|
||
|
||
def serialize_encrypted_values( | ||
*values_enc: Optional[fhe.Value], | ||
) -> Union[Optional[bytes], Optional[Tuple[bytes]]]: | ||
"""Serialize encrypted values. | ||
If a value is None, None is returned. | ||
Args: | ||
values_enc (Optional[fhe.Value]): The values to serialize. | ||
Returns: | ||
Union[Optional[bytes], Optional[Tuple[bytes]]]: The serialized values. | ||
""" | ||
values_enc_serialized = tuple( | ||
value_enc.serialize() if value_enc is not None else None for value_enc in values_enc | ||
) | ||
|
||
if len(values_enc_serialized) == 1: | ||
return values_enc_serialized[0] | ||
|
||
return values_enc_serialized | ||
|
||
|
||
def deserialize_encrypted_values( | ||
*values_serialized: Optional[bytes], | ||
) -> Union[Optional[fhe.Value], Optional[Tuple[fhe.Value]]]: | ||
"""Deserialize encrypted values. | ||
If a value is None, None is returned. | ||
Args: | ||
values_serialized (Optional[bytes]): The values to deserialize. | ||
Returns: | ||
Union[Optional[fhe.Value], Optional[Tuple[fhe.Value]]]: The deserialized values. | ||
""" | ||
values_enc = tuple( | ||
fhe.Value.deserialize(value_serialized) if value_serialized is not None else None | ||
for value_serialized in values_serialized | ||
) | ||
|
||
if len(values_enc) == 1: | ||
return values_enc[0] | ||
|
||
return values_enc |
This file contains 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 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 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