Example #1
0
def federated_train(model, learning_rate, data):
    """
    The simplest way to implement federated training is to train locally, and then average the models.

    Note that in the full-featured implementation of Federated Averaging provided by tff.learning,
    rather than averaging the models, we prefer to average model deltas, for a number of reasons,
    e.g., the ability to clip the update norms, for compression, etc.
    """
    return tff.federated_mean(
        tff.federated_map(local_train, [
            tff.federated_broadcast(model),
            tff.federated_broadcast(learning_rate), data
        ]))
Example #2
0
def aggregate_mnist_metrics_across_clients(metrics):
    return {
        'num_examples': tff.federated_sum(metrics.num_examples),
        'loss': tff.federated_mean(metrics.loss, metrics.num_examples),
        'accuracy': tff.federated_mean(metrics.accuracy, metrics.num_examples)
    }
Example #3
0
def get_global_temperature_average(sensor_readings):
  return tff.federated_mean(
      tff.federated_map(get_local_temperature_average, sensor_readings))
Example #4
0
def get_average_temperature(sensor_readings):
  return tff.federated_mean(sensor_readings)
Example #5
0
def federated_eval(model, data):
    return tff.federated_mean(
        tff.federated_map(local_eval, [tff.federated_broadcast(model), data]))
Example #6
0
def federated_train(model, learning_rate, data):
    return tff.federated_mean(
        tff.federated_map(local_train, [
            tff.federated_broadcast(model),
            tff.federated_broadcast(learning_rate), data
        ]))