Path: blob/master/site/en-snapshot/federated/design/context.md
25118 views
Context
[TOC]
Context
A context_base.SyncContext or context_base.AsyncContext is an environment that can construct, compile, or execute an AST.
This API defines a low-level abstraction that should be used when an Executor is not used for execution; the Reference backend integrate at this level.
ExecutionContext
An execution_context.ExecutionContext is context_base.SyncContext or context_base.AsyncContext that compiles computations using a compilation function and executes computations using an Executor.
This API defines a high-level abstraction that should be used when an Executor is used for execution; the native integrates at this level.
FederatedComputationContext
A federated_computation_context.FederatedComputationContext is a context that constructs federated computations. This context is used trace Python functions decorated with the federated_computation.federated_computation decorator.
TensorFlowComputationContext
A tensorflow_computation_context.TensorFlowComputationContext is a context that constructs TensorFlow computations. This context is used to serialize Python functions decorated with the tensorflow_computation.tf_computation decorator.
ContextStack
A context_stack_base.ContextStack is a data structure for interacting with a stack of Contexts.
You can set the context TFF will use to construct, compile, or execute an AST by:
Invoking set_default_context.set_default_context to set the default context. This API is often used to install a context that will compile or execute a computation.
Invoking get_context_stack.get_context_stack to get the current context stack and then invoking context_stack_base.ContextStack.install to temporarily install a context onto the top of the stack. For example, the federated_computation.federated_computation and tensorflow_computation.tf_computation decorators push the corresponding contexts onto the current context stack while the decorated function is being traced.
ContextStackImpl
A context_stack_impl.ContextStackImpl is a context_stack_base.ContextStack that is implemented as a common thread-local stack.