Last active
August 18, 2020 22:01
-
-
Save jvmncs/5e7be5666f7ba1aa824fbc76cccb6129 to your computer and use it in GitHub Desktop.
Paillier Aggregation in TensorFlow Federated
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
import tensorflow as tf | |
import tensorflow_federated as tff | |
from federated_aggregations import paillier | |
paillier_factory = paillier.local_paillier_executor_factory() | |
paillier_context = tff.framework.ExecutionContext(paillier_factory) | |
tff.framework.set_default_context(paillier_context) | |
# data from 5 clients | |
x = [np.array([i, i + 1], dtype=np.int32) for i in range(5)] | |
x_type = tff.TensorType(tf.int32, [2]) | |
@tff.federated_computation(tff.FederatedType(x_type, tff.CLIENTS)) | |
def secure_paillier_addition(x): | |
return tff.federated_secure_sum(x, bitwidth=32) | |
result = secure_paillier_addition(x) | |
print(result) | |
>>> [10 15] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment