Exemple #1
0
    def __call__(self, state, value, weight=None):
        """Performs an aggregate of value@CLIENTS, with optional weight@CLIENTS.

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

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

    Args:
      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`.

    Returns:
       A tuple of `tff.Value`s (state@SERVER, aggregate@SERVER) where
         * state: The updated state.
         * aggregate: The result of the aggregation of `value` weighted by
             `weight.
    """
        return self._next_fn(tff.to_value(state), tff.to_value(value),
                             tff.to_value(weight))
Exemple #2
0
    def __call__(self, state, value):
        """Performs a broadcast of value@SERVER, producing value@CLIENTS.

    This is a function intended to (only) be invoked in the context
    of a `tff.federated_computation`. It shold be compatible with the
    TFF type signature
    `(state@SERVER, value@SERVER) -> (state@SERVER, value@CLIENTS)`.

    Args:
      state: A `tff.Value` placed on the `tff.SERVER`.
      value: A `tff.Value` to be broadcast to the `tff.CLIENTS`.

    Returns:
       A tuple of `tff.Value`s (state@SERVER, value@CLIENTS) where
         * state: The updated state.
         * aggregate: The `value` now placed (communicated) to the
           `tff.CLIENTS`.
    """
        return self._next_fn(tff.to_value(state), tff.to_value(value))
Exemple #3
0
    def __call__(self, state, *args, **kwargs):
        """Performs the stateful function call.

    Args:
      state: A `tff.Value` placed on the `tff.SERVER`.
      *args: Arguments to the function.
      **kwargs: Arguments to the function.

    Returns:
       A tuple of `tff.Value`s (state@SERVER, ...) where
         * state: The updated state, to be passed to the next invocation
           of call.
         * ...: The result of the aggregation.
    """
        return self._next_fn(tff.to_value(state), *args, **kwargs)
 def one_arg_initialize(one_arg):
     del one_arg  # unused
     return tff.to_value(0)