tff.framework.Context

Context objects evaluate invocations of computations.

Invocations of TensorFlow Federated computations need to be treated differently depending on the Context in which they are invoked. For example:

  • During top-level Python simulations, computation invocations result in the computation being serialized and evaluated by the TensorFlow native runtime.
  • In tf_computation-annotated functions, computation invocations must import the body of the invoked function into the current TensorFlow graph.

Code can customize the way in which each of these calls are evaluated by setting a specific Context using a global or thread-local context stack.

Methods

invoke

View source

Invokes computation comp with argument arg.

Args
comp The computation being invoked. The Python type of comp expected here (e.g., pb.Computation. ConcreteComputation, or other) may depend on the context. It is the responsibility of the concrete implementation of this interface to verify that the type of comp matches what the context is expecting.
arg The argument passed to the computation. If no argument is passed, this will be None. Structural argument types will be normalized into structure.Structs.

Returns
The result of invocation, which is context-dependent.