tff.program.FederatedContext

An abstract interface representing a federated context.

Inherits From: SyncContext

A federated context supports invoking a limited set of tff.Computations, making guarantees about what a tff.Computation can accept as an argument and what it returns when invoked.

Restrictions on the TensorFlow Federated Type

Arguments can be nested structures of values corresponding to the TensorFlow Federated type signature of the tff.Computation:

Return values can be structures of tff.program.MaterializableValueReferences or a single tff.program.MaterializableValueReference, where a reference corresponds to the tensor-type of the TensorFlow Federated type signature in the return value of the invoked tff.Computation.

TensorFlow Federated Type to Python Representation

In order to interact with the value returned by a tff.Computation, it is helpful to be able to reason about the Python type of this value. In some way this Python type must depend on the TensorFlow Federated type signature of the associated value. To provide uniformity of experience and ease of reasoning, we specify the Python representation of values in a manner that can be stated entirely in the TensorFlow Federated typesystem.

We have chosen to limit the TensorFlow Federated type signatures of invoked tff.Computations to disallow the returning of client-placed values, tff.SequenceTypes, and tff.FunctionTypes, in order to reduced the area which needs to be supported by federated programs. Below we describe the mapping between TensorFlow Federated type signatures and Python representations of values that can be passed as arguments to or returned as results from tff.Computations.

Python representations of values that can be accepted as an arguments to or returned as a value from a tff.Computation:

TensorFlow Federated Type Python Representation
tff.TensorType tff.program.MaterializableValueReference
tff.SequenceType tff.program.MaterializableValueReference
tff.FederatedType (server-placed) Python representation of the member of the tff.FederatedType
tff.StructWithPythonType Python container of the tff.StructWithPythonType
tff.StructType (with no Python type, all fields named) collections.OrderedDict
tff.StructType (with no Python type, no fields named) tuple

Python representations of values that can be only be accepted as an arguments to a tff.Computation:

TFF Type Python Representation
tff.FederatedType (client-placed) Opaque object returned by tff.program.DataSourceIterator.select
tff.FunctionType tff.Computation

Methods

invoke

View source

Invokes the comp with the argument arg.

Args
comp The tff.Computation being invoked.
arg The optional argument of comp; server-placed values must be represented by tff.program.MaterializableStructure, and client-placed values must be represented by structures of values returned by a tff.program.FederatedDataSourceIterator.

Returns
The result of invocation; a structure of tff.program.MaterializableValueReference.

Raises
ValueError If the result type of comp does not contain only structures, server-placed values, or tensors.