Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tff.learning.build_federated_sgd_process

View source on GitHub

Builds the TFF computations for optimization using federated SGD.

tff.learning.build_federated_sgd_process(
    model_fn, server_optimizer_fn=(lambda :
    tf.keras.optimizers.SGD(learning_rate=0.1)), client_weight_fn=None,
    stateful_delta_aggregate_fn=None, stateful_model_broadcast_fn=None
)

This function creates a tff.utils.IterativeProcess that performs federated averaging on client models. The iterative process has the following methods:

Each time the next method is called, the server model is broadcast to each client using a broadcast function. Each client sums the gradients at each batch in the client's local dataset. These gradient sums are then aggregated at the server using an aggregation function. The aggregate gradients are applied at the server by using the tf.keras.optimizers.Optimizer.apply_gradients method of the server optimizer.

Args:

  • model_fn: A no-arg function that returns a tff.learning.Model.
  • server_optimizer_fn: A no-arg function that returns a tf.Optimizer. The apply_gradients method of this optimizer is used to apply client updates to the server model.
  • client_weight_fn: Optional function that takes the output of model.report_local_outputs and returns a tensor that provides the weight in the federated average of the aggregated gradients. If not provided, the default is the total number of examples processed on device.
  • stateful_delta_aggregate_fn: A tff.utils.StatefulAggregateFn where the next_fn performs a federated aggregation and upates state. It must have TFF type (<state@SERVER, value@CLIENTS, weights@CLIENTS> -> <state@SERVER, aggregate@SERVER>), where the value type is tff.learning.framework.ModelWeights.trainable corresponding to the object returned by model_fn. By default performs arithmetic mean aggregation, weighted by client_weight_fn.
  • stateful_model_broadcast_fn: A tff.utils.StatefulBroadcastFn where the next_fn performs a federated broadcast and upates state. It must have TFF type (<state@SERVER, value@SERVER> -> <state@SERVER, value@CLIENTS>), where the value type is tff.learning.framework.ModelWeights corresponding to the object returned by model_fn. The default is the identity broadcast.

Returns:

A tff.utils.IterativeProcess.