Path: blob/master/site/en-snapshot/federated/tutorials/federated_select.ipynb
25118 views
Copyright 2021 The TensorFlow Authors.
Sending Different Data To Particular Clients With tff.federated_select
This tutorial demonstrates how to implement custom federated algorithms in TFF that require sending different data to different clients. You may already be familiar with tff.federated_broadcast
which sends a single server-placed value to all clients. This tutorial focuses on cases where different parts of a server-based value are sent to different clients. This may be useful for dividing up parts of a model across different clients in order to avoid sending the whole model to any single client.
Let's get started by importing both tensorflow
and tensorflow_federated
.
Sending Different Values Based On Client Data
Consider the case where we have some server-placed list from which we want to send a few elements to each client based on some client-placed data. For example, a list of strings on the server, and on the clients, a comma-separated list of indices to download. We can implement that as follows:
Then we can simulate our computation by providing the server-placed list of strings as well as string data for each client:
Sending A Randomized Element To Each Client
Alternatively, it may be useful to send a random portion of the server data to each client. We can implement that by first generating a random key on each client and then following a similar selection process to the one used above:
Since our broadcast_random_element
function doesn't take in any client-placed data, we have to configure the TFF Simulation Runtime with a default number of clients to use:
Then we can simulate the selection. We can change default_num_clients
above and the list of strings below to generate different results, or simply re-run the computation to generate different random outputs.