Krzysztof Ostrowski is a Research Scientist at Google, where he leads the TensorFlow Federated development team. This blog post is inspired by his talk at the OpenMined Privacy Conference.
TensorFlow Federated(TFF) is a new development framework for Federated Computations, that typically involve computations on data that is born decentralized and stays decentralized. TFF provides a common framework for federated computations in both research and production and is an open source project within the TensorFlow ecosystem.
The TFF library has been designed so as to facilitate an easy path from research to production. In TFF, the code is serialized into a portable, language-independent and platform-independent representation.
The design is, therefore, motivated by the dictum:
Write code once, and deploy it anywhere;
Your code shouldn’t have to change!
In this section, we shall seek to understand some of the characteristics of federated computations.
Let us consider the following example. Let us assume that temperature sensor readings of client devices are sensitive; The server wishes to get the percentage of client devices whose temperature sensor readings exceed a certain threshold. There’s federated broadcast of the threshold to all client devices. The client devices run a simple threshold check and send out a 1/0 depending on whether temperature > threshold is True/False respectively. The server then does federated averaging on the values from the clients, which gives the fraction of devices whose temperature exceeds the threshold.
federated float32@clients
Involves communication and orchestration — collective operations, known as federated ops, rather than dealing with individual client’s data.The program flow is expressed in a Pythonic way for better interpretability; As stated in an earlier section, all code is traced and serialized at definition time to a platform-independent representation. Here’s the code snippet showing the collective operations and on-device processing for the temperature sensor example discussed above.
@tf.function
def exceeds_threshold_fn(reading,threshold):#on-device processing
return tf.to_float(reading > threshold)
@tff.federated_computation
def get_fraction_over_threshold(readings, threshold):
return tff.federated_mean( #collective operations
tff.federated_map( #collective communication
tff.tf_computation(exceeds_threshold_fn),
[readings, tff.federated_broadcast(threshold)]))
We shall enumerate some of the features of TFF’s Canned and Simulation APIs.
# Just plug in your Keras model
train = tff.learning.build_federated_averaging_process(...)
state = train.initilaize()
for _ in range(5):
train_data = _ #pick random clients
state, metrics = train.next(state, train_data)
print(metrics.loss)
Canned TFF Executors provide support for the most common scenarios. A single-machine, multi-threaded execution is spawned by default in the background, and the Canned TFF Executors facilitate remote and distributed execution. TFF executor building blocks are reusable, stackable modules that add to individual capabilities and are specifically designed for extensibility and customizability.
There are opportunities to contribute to the federated algorithms suite, simulation infrastructure and more flexible runtime integrations.