Skip to content

Instantly share code, notes, and snippets.

@jvmncs
Last active August 18, 2020 22:01
Show Gist options
  • Save jvmncs/5e7be5666f7ba1aa824fbc76cccb6129 to your computer and use it in GitHub Desktop.
Save jvmncs/5e7be5666f7ba1aa824fbc76cccb6129 to your computer and use it in GitHub Desktop.
Paillier Aggregation in TensorFlow Federated
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