Tensorflow federated : How to map the remote-worker with remote datasets in iterative_process.next?

Viewed 181

I would like to point the federated_train_data to remote client data as shown in the code below.Is this possible? How ?

If not what further implementation is required for me to try this out. Kindly point me to the relevant code.

factory = tff.framework.create_executor_factory(make_remote_executor)
context = tff.framework.ExecutionContext(factory)
tff.framework.set_default_context(context)

state = iterative_process.initialize()

state, metrics = iterative_process.next(state, federated_train_data)
def make_remote_executor(inferred_cardinalities):
  """Make remote executor."""

  def create_worker_stack(ex):
    ex = tff.framework.ThreadDelegatingExecutor(ex)
    return tff.framework.ReferenceResolvingExecutor(ex)

  client_ex = []
  num_clients = inferred_cardinalities.get(tff.CLIENTS, None)
  if num_clients:
    print('Inferred that there are {} clients'.format(num_clients))
  else:
    print('No CLIENTS placement provided')

  for _ in range(num_clients or 0):
    channel = grpc.insecure_channel('{}:{}'.format(FLAGS.host, FLAGS.port))
    remote_ex = tff.framework.RemoteExecutor(channel, rpc_mode='STREAMING')
    worker_stack = create_worker_stack(remote_ex)
    client_ex.append(worker_stack)

  federating_strategy_factory = tff.framework.FederatedResolvingStrategy.factory(
      {
          tff.SERVER: create_worker_stack(tff.framework.EagerTFExecutor()),
          tff.CLIENTS: client_ex,
      })
  unplaced_ex = create_worker_stack(tff.framework.EagerTFExecutor())
  federating_ex = tff.framework.FederatingExecutor(federating_strategy_factory,
                                                   unplaced_ex)
  return tff.framework.ReferenceResolvingExecutor(federating_ex)

This is from https://github.com/tensorflow/federated/blob/master/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py

1 Answers

In the linked example, you can see that the client data is coming from a tf.data.Dataset per-client generated by the make_federated data function.

Client data can be supplied in the form of a serializable tf.data.Dataset or, depending on how you're defining your iterative process, you can tff.federated_map some input data (such as client IDs) to datasets using TensorFlow.

Note that RemoteExecutors are not designed to run against data "on clients", that is, on the remote executor itself. They could perhaps be used this way using TensorFlow code to read data from the remote executor's filesystem into a dataset, but in general this is not a supported use-case. The recommended way to handle client data is to have a TensorFlow computation that can generate a tf.data.Dataset representing the client data based on a client ID or other input to the client's TensorFlow computation.

Related