A simple container for a stateful aggregation function.

A typical (though trivial) example would be:

stateless_federated_mean = tff.utils.StatefulAggregateFn(
    initialize_fn=lambda: (),  # The state is an empty tuple.
    next_fn=lambda state, value, weight=None: (
        state, tff.federated_mean(value, weight=weight)))

initialize_fn A no-arg function that returns a Python container which can be converted to a tff.Value, placed on the tff.SERVER, and passed as the first argument of __call__. This may be called in vanilla TensorFlow code, typically wrapped as a tff.tf_computation, as part of the initialization of a larger state object.
next_fn A function matching the signature of __call__, see below.



View source

Returns the initial state.


View source

Performs an aggregate of value@CLIENTS, producing value@SERVER.

The aggregation is optionally parameterized by weight@CLIENTS.

This is a function intended to (only) be invoked in the context of a tff.federated_computation. It should be compatible with the TFF type signature.

(state@SERVER, value@CLIENTS, weight@CLIENTS) ->
     (state@SERVER, aggregate@SERVER).

state A tff.Value placed on the tff.SERVER.
value A tff.Value to be aggregated, placed on the tff.CLIENTS.
weight An optional tff.Value for weighting values, placed on the tff.CLIENTS.

A tuple of tff.Values (state@SERVER, aggregate@SERVER), where

  • state: The updated state.
  • aggregate: The result of the aggregation of value weighted by weight.